Search code examples
ansibleansible-factsansible-role

How to access ansible facts in roles?


I am currently working on some ansible automation tasks and wanted to use ansible facts in a role I created. However, I cannot access any facts.
Example: If I want to use the default IP-Address of a Windows machine, I was advised to use the following variable:

{{ ansible_default_ipv4.address }}

Ansible however tells me, that this variable is not defined.

Does anyone have an idea as to how I should use facts in a role?


Solution

  • try this one: {{ hostvars[host].ansible_default_ipv4.address }}