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:

$result = @{ }

if(Get-NetAdapter -Name "management" -ErrorAction Ignore){
  $result['mgmt_ip_address'] = (Get-NetIPConfiguration -InterfaceAlias "management").IPv4Address.IPAddress
}

$result

Specify the path to your powershell script in your playbook and access the custom facts in your ansible variable space like so:

---
- name: test_playbook
  hosts: windows_webservers
  fact_path: 'C:\temp\ip_facts.ps1'

  tasks:

  - debug:
      msg: "{{ ansible_ip_facts | default() }}"

It appears that Ansible automatically names your custom fact vars using the file name of the powershell script and then prepending “ansible_”.