user15366089
user15366089

Reputation:

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?

Upvotes: 1

Views: 587

Answers (1)

Roman Zinger
Roman Zinger

Reputation: 152

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

Upvotes: 2

Related Questions