Collect Azure VM facts

Hi there,

Is there a way to gather facts about the state of an Azure VM?

There exist fact gathering modules for other Azure resources (such as a azure_rm_virtualmachineimage_facts) but there doesn’t seem to be any for VMs.
What I am trying to do is run sysprep on a Windows VM, then have ansible wait until its in a Stopped state, before trying to capture it.

An option is to just run the Azure cli, however I was hoping there may be a better way.

Any thoughts?

Thanks,
Matin

A VM facts module was just added to the codebase and will be available in the 2.7 release by default. What you can do is create a copy of the file as is and store it in the library folder of the role or next to the playbook and access it like normal (https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_facts.py). If you do want to go down that route, I recommend you call the module something like azure_rm_virtualmachine_facts_cust to make it explicitly clear you are using a version that is not built into Ansible. This means that when you do upgrade to 2.7 or future versions you don’t override the builtin one which by that time may contain bug fixes or newer features.

Thanks

Jordan

Hi Jordan,

Amazing timing, thanks a lot for that.
It works great!

Cheers,
Matin