AWX-Manage command execution using ansible playbook

Hello All,

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

  •  docker exec -it awx_task bash
    
  •  cd /var/lib/awx/projects/ansible
    
  • 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.

``

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.

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