I want to define a playbook which establishes facts about my hosts that can be used in other plays. The set_fact module claims to be able to do this ... http://docs.ansible.com/set_fact_module.html -- however it's not working ... The facts I define are available after the call to set_fact within a run of the play-book -- I would then expect to be able to use ansible all -m setup and see the fact defined somewhere within the facts gathered for each host ...
I tried looking into the code for the set_fact module -- but all I find is documentation string ... https://github.com/ansible/ansible-modules-core/blob/19b328c4df2157b6c0191e9144236643ce2be890/utilities/logic/set_fact.py
Firstly, the set_fact module only sets facts available during a run. For persistent facts, you'll need to either:
--Static--
- define them in one of the following:
- vars/
- group_vars/
- host_vars/
--Dynamic--
Assign them to hosts using your language of choice via Ansible's Dynamic Inventory:
- http://docs.ansible.com/ansible/intro_dynamic_inventory.html
- http://docs.ansible.com/ansible/developing_inventory.html
The latter is what I usually choose to do, as it is quite simple to set up, and the facts are always available on all hosts, even if you are doing something like:
- getting all the facts for all the hosts while connected to a nagios host in order to generate its configuration files.
If a remotely managed system has an /etc/ansible/facts.d directory, any files in this directory ending in .fact, can be JSON, INI, or executable files returning JSON, and these can supply local facts in Ansible, since 1.3. An alternate directory can be specified using the fact_path play directive.
http://docs.ansible.com/ansible/playbooks_variables.html#local-facts-facts-d
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With