Refresh inventory on playbook run

Hello

I have a playbook which create a vmware vm based on survey data.

With some trick I add the machine to the inventory:

  • name: Added host to inventory
    command: awx-manage inventory_import --inventory-name ‘Inventory’ --source /tmp/inventory.ini
    delegate_to: localhost

  • name: Refresh inventory to ensure new instances exist in inventory
    meta: refresh_inventory
    delegate_to: localhost

But in the sameplaybook I connect to the newly created vm but this fails because I don’t know the host.
I was hopen meta: refresh_inventory did a inventory refresh but this works not for awx

How Can I solve this issue

This is kind of a sore spot for AWX/Tower IMHO. I ran into the same issue (I deploy a VM but it has to be in inventory for me to do anything with it). I ended up writing a small inventory script, and working my VM deployment into a workflow.

It goes something like this: Deploy from template > inventory script (now it is in inventory) > Secondary configs.

You might try creating a workflow too, kind of what I did, and the actual VM creation is how you have it, followed by an inventory sync, followed by your follow on tasks. I cannot remember if I tried using that awx-manage command or not.

I also tried doing a vsphere inventory sync between my deploy and follow on tasks, but the vsphere inventory sync was taking too long (20+ minutes).

John M. Foley

IT Specialist

jfol@loc.gov

http://www.loc.gov/staff/emailsig/logos/lloc.jpg

How come you don’t just use the add_host module to add the host into the in-memory inventory?

I used add_host that was not working because I used it with a delegate_to
Now I use it directly on host localhost and it works perfectly

Problem solved

What was the problem with add_host and delegate to? I’ve used that combo without any problem.

https://github.com/kosalaat/create_vm_from_template

I used the add_host with a delegate_to localhost that was the issue
Now I run it directly on the ansible machine and no issues