# Refresh inventory on playbook run

**URL:** <https://forum.ansible.com/t/refresh-inventory-on-playbook-run/30467>\
**Category:** AWX Project\
**Tags:** vmware, awx\
**Created:** [June 1, 2019, 10:23am UTC](https://forum.ansible.com/t/refresh-inventory-on-playbook-run/30467 "2019-06-01T10:23:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![daemenseth](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/daemenseth/32/677_2.png) [@daemenseth](https://forum.ansible.com/u/daemenseth)\
**Post date:** [June 1, 2019, 10:23am UTC](https://forum.ansible.com/t/refresh-inventory-on-playbook-run/30467/1 "2019-06-01T10:23:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Foley\_John](https://avatars.discourse-cdn.com/v4/letter/f/e495f1/32.png) [@Foley\_John](https://forum.ansible.com/u/Foley_John)\
**Post date:** [June 1, 2019, 4:41pm UTC](https://forum.ansible.com/t/refresh-inventory-on-playbook-run/30467/2 "2019-06-01T16:41:49Z")

</div>

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](https://us1.discourse-cdn.com/ansible/original/2X/7/760622c1f5b048c15d45e97c76556e73baba2a14.jpeg)

---

<div class="post-metadata">

**Author:** ![Toby](https://avatars.discourse-cdn.com/v4/letter/t/7993a0/32.png) [@Toby](https://forum.ansible.com/u/Toby)\
**Post date:** [June 1, 2019, 4:57pm UTC](https://forum.ansible.com/t/refresh-inventory-on-playbook-run/30467/3 "2019-06-01T16:57:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![daemenseth](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/daemenseth/32/677_2.png) [@daemenseth](https://forum.ansible.com/u/daemenseth)\
**Post date:** [June 3, 2019, 2:11pm UTC](https://forum.ansible.com/t/refresh-inventory-on-playbook-run/30467/4 "2019-06-03T14:11:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kosala\_Atapattu1](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@Kosala\_Atapattu1](https://forum.ansible.com/u/Kosala_Atapattu1)\
**Post date:** [June 4, 2019, 10:50pm UTC](https://forum.ansible.com/t/refresh-inventory-on-playbook-run/30467/5 "2019-06-04T22:50:57Z")

</div>

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](https://github.com/kosalaat/create_vm_from_template)

---

<div class="post-metadata">

**Author:** ![daemenseth](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/daemenseth/32/677_2.png) [@daemenseth](https://forum.ansible.com/u/daemenseth)\
**Post date:** [June 5, 2019, 7:41am UTC](https://forum.ansible.com/t/refresh-inventory-on-playbook-run/30467/6 "2019-06-05T07:41:38Z")

</div>

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
