Managing New virtual Machine inventory

Hi,

I need you for an advice.

I have some playbook to deploy virtuals machines on vsphere (the hosts option for these playbooks is ‘localhost’). And I have some playbook to configure these VM.
I don’t know manage the inventory for newly VM.
Can I add newly VM to AWX inventory with AWX API in the deploy playbook ? To do you think it’s better to create an entry in the inventory before executing any playbook and not automate inventory update ?
How do you manage inventory for new VM and deal with password generation…

Thanks you

What I ended up doing what creating a workflow. I have a survey setup that gathers info on the new VM, followed by the actual playbook that deploys the VM. At the end of the deploy playbook, there is actually a play that adds the hostname of the VM to a file on the server that AWX/Tower is running on. The next step of the workflow is actually an inventory script that reads that file and adds the server to my inventory. Configuration then happens in subsequent playbooks. At the very end, I remove the server from the file and rerun the inventory script, which removes it from inventory. It gets readded to inventory later on when AWX/Tower syncs to Satellite.

Hi,

I can only share my experience so it will need to be adapted to your needs…

Playbook will create VMs on VMware vSphere using an inventory file properly versioned using GIT, so that means that every time that file is updated playbook will run throughout that file and see what VMs should be deployed/running/stopped or even HW update (whenever is possible or needed).
A single source of truth for VM deployment…

You can rely on other tools like Terraform to have a state of your infrastructure, just saying. In the end is a matter to adapt/use technology that suits your needs.

Moving on…

After VM creation, now use Dynamic Inventory script to query VMware vSphere API. Going to be honest with you… it’s not the fastest thing that you gonna to use… be patient… from my experience a API to finish return facts/info for 1100 ish VMs will take around 15/20 mins…

Now you have two inventories…

Inventory number one: for “state” of infrastructure
Inventory number two: for config management

Cheers,
JS

Thanks you Johan and Joaos for you ideas. It’s very interesting.
The temporary file and the git inventory is a good idea. I have a gitlab for all playbooks/roles
I don’t use Redhat satellite (and I have Windows VM too).

Joas, for a better speed for your inventory, try govc (+ jq to parse json). It’s very fast. Some times, I prefer use govc rather ansible modules
I don’t use terraform, but i will use in the futur

Thanks you