Dynamic Inventory Source Sync

108 views
Skip to first unread message

wme...@why-me.com

unread,
Jan 25, 2021, 6:59:15 PM1/25/21
to awx-p...@googlegroups.com
So this may sound like a bit of a dumb question, but i can't seem to find an answer anywhere.  I have a Dynamic inventory setup, have a playbook that will deploy a new machine, how can i trigger the inventory source to run a sync.  I know i can have it run every time a playbook runs against it, but that slows down the entire process.  What I am trying to accomplish is build a new Virtual machine(doesn't matter what the platform, vmware, azure, awx, etc.  I have an inventory set up for that platform(in this instance it is vmware) that  has a source of my vcenter server.  My playbook scans the inventory to ensure that a system with the requested name does not already exists, it then deploys the VM, and waits for deployment to complete.  Once complete I want to be able to run post deployment scripts against the new VM, but since it does not exist in inventory the playbooks fail.   I know i can pass the name using set_stats, but i would like to be able to use all of the facts associated with the new machine (ie OS major, minor versions, disk drives attached, etc).  What have others done to do this?

Ronan

unread,
Jan 27, 2021, 4:48:58 PM1/27/21
to AWX Project
I’m in the same situation.
Immediately after the successful vm deployment, my playbook adds the machine to the « dynamic » inventory in AWX (using the API) so the next job template in the workflow can pick it up. 
I have 6000+ vms in that inventory. It takes more than 10min to extract the inventory from the vCenter. So syncing on every launch is not an option.
I only sync the inventory once every night. During the refresh, the previously added vm is merged by the one discovered via the vCenter (I use the « overwrite » option in the inventory sync).
I use that approach for a while now. The only drawback is that, if you want to create a single workflow that create the vm and also does something on it (using the inventory to cache facts), you have to pass the vm name to both an extra vars and a limit. It’s not elegant but I didn’t find any other way.
Hope it helps.

phil.gr...@gmail.com

unread,
Feb 3, 2021, 9:07:06 AM2/3/21
to AWX Project
There are 2 ways to do this:

1. Create a workflow. First stage is your playbook JT, then just add an Inventory Sync as stage 2. Then you can call whatever you like to complete the setup.

If your inventory takes too long to scan, then

2. use add_host - https://docs.ansible.com/ansible/2.9/modules/add_host_module.html after your first playbook or part of it.

Phil.

Reply all
Reply to author
Forward
0 new messages