# Collect Azure VM facts

**URL:** <https://forum.ansible.com/t/collect-azure-vm-facts/28270>\
**Category:** Ansible Project\
**Tags:** azure, windows\
**Created:** [August 6, 2018, 5:28pm UTC](https://forum.ansible.com/t/collect-azure-vm-facts/28270 "2018-08-06T17:28:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matin\_Nayob](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@Matin\_Nayob](https://forum.ansible.com/u/Matin_Nayob)\
**Post date:** [August 6, 2018, 5:28pm UTC](https://forum.ansible.com/t/collect-azure-vm-facts/28270/1 "2018-08-06T17:28:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [August 6, 2018, 7:40pm UTC](https://forum.ansible.com/t/collect-azure-vm-facts/28270/2 "2018-08-06T19:40:17Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![Matin\_Nayob](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@Matin\_Nayob](https://forum.ansible.com/u/Matin_Nayob)\
**Post date:** [August 7, 2018, 1:44pm UTC](https://forum.ansible.com/t/collect-azure-vm-facts/28270/3 "2018-08-07T13:44:29Z")

</div>

Hi Jordan,

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

Cheers,  
Matin
