# AWX-Manage command execution using ansible playbook

**URL:** <https://forum.ansible.com/t/awx-manage-command-execution-using-ansible-playbook/33707>\
**Category:** AWX Project\
**Tags:** awx\
**Created:** [September 1, 2020, 5:20am UTC](https://forum.ansible.com/t/awx-manage-command-execution-using-ansible-playbook/33707 "2020-09-01T05:20:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![harsh\_chawda](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@harsh\_chawda](https://forum.ansible.com/u/harsh_chawda)\
**Post date:** [September 1, 2020, 5:20am UTC](https://forum.ansible.com/t/awx-manage-command-execution-using-ansible-playbook/33707/1 "2020-09-01T05:20:37Z")

</div>

Hello All,

I am importing all the hosts inside my hosts file into AWX using awx-manage commands like

- 

```auto
 docker exec -it awx_task bash

```

- 

```auto
 cd /var/lib/awx/projects/ansible

```

- 

```auto
awx-manage inventory_import --source=./hosts --inventory-name="Manual Project Inventory" --overwrite --overwrite-vars

```

`And its working fine as expected it is importing all the hosts inside AWX inventory`

`But instead of manually running it, I want it to do through ansible playbook. I have written one. But when i am running it. It shows status as changed and completes successfully.`

`But the inventory is not getting updated in the AWX. Below is my playbook, can anyone please tell me what i am doing wrong or what to be done or some other script will also be fine for me.`

` **First Playbook** `

`---`  
`- hosts: localhost`  
`tasks:`  
`- name: Execute commands in docker container`  
`command: docker exec -it awx_task bash -c awx-manage inventory_import --source=/var/lib/awx/projects/ansible/hosts --inventory-name="Manual Project Inventory" --overwrite --overwrite-vars`

` **Second Playbook** `

` **---** `  
`- hosts: localhost`  
`tasks:`  
`- name: This command will change the working directory to somedir/`  
`shell:`  
`cmd: awx-manage inventory_import --source=/var/lib/awx/projects/ansible/hosts --inventory-name="Manual Project Inventory" --overwrite --overwrite-vars`  
`args:`  
`executable: docker exec -it awx_task bash`

`Please help me if someone has any idea.`

`Thanks in advance.`

``

---

<div class="post-metadata">

**Author:** ![Ankit2](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@Ankit2](https://forum.ansible.com/u/Ankit2)\
**Post date:** [September 1, 2020, 7:16am UTC](https://forum.ansible.com/t/awx-manage-command-execution-using-ansible-playbook/33707/2 "2020-09-01T07:16:36Z")

</div>

can you paste the result of the **command** module. It should show how many hosts/groups were imported. Also, since you have been trying to do this manually as well, try checking the source, it must be showing 2 sources for inventory. Try removing and re-running it.

---

<div class="post-metadata">

**Author:** ![harsh\_chawda](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@harsh\_chawda](https://forum.ansible.com/u/harsh_chawda)\
**Post date:** [September 3, 2020, 5:31am UTC](https://forum.ansible.com/t/awx-manage-command-execution-using-ansible-playbook/33707/3 "2020-09-03T05:31:59Z")

</div>

Hello Ankit,

Thanks for your reply. I was able to fix the issue by using another ansible module **raw**.

And its working as expected and updating the inventory inside AWX.

Thanks again for your time.

**Regards**  
**Harsh**
