ansible custom facts on windows
I found that accessing the IP addresses on Windows machines was not very easy with Ansible. The data seems to be there in the discovered facts, but there didn’t seem to be any way to link an interface alias to an IP address on that interface. This is what I needed though and was able to solve this workflow using Ansible custom facts for windows.
I thought the documentation was a little sparse on how this actually works so here’s the TLDR:
Deploy a powershell script to your target Windows machine that will return a hash table with your custom facts, for example:
Specify the path to your powershell script in your playbook and access the custom facts in your ansible variable space like so:
It appears that Ansible automatically names your custom fact vars using the file name of the powershell script and then prepending “ansible_”.