Hello Ansible Experts,
How would I get a fact/variable from a host that is not the target of my playbook?
I know that hostvars exist for this reason but since the hosts that I want to get variables from are not the target of my playbook, the hostvars for that host is not populated.
For this scenario, I am generating a configuration file for a Munin master node which needs to get the ansible_processor_count from the other nodes. This playbook is executed for the master node only so therefore only the facts for that master node are gathered.
Here’s the Jinja template that I am trying to render:
{% for host in groups[‘all’] %}
[{{ host }}]
address {{ host }}
use_node_name yes
cpu.user.warning {{ hostvars[host][‘ansible_processor_count’] * 100 * 0.8 }}
cpu.user.critical {{ hostvars[host][‘ansible_processor_count’] * 100 * 0.9 }}
{% endfor %}
I get a:
fatal: [munin-master] => {‘msg’: “‘dict object’ has no attribute ‘ansible_processor_count’”, ‘failed’: True}
Thank you!
Paulo