Ansible Variable Persistence

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.

Knowledge Base

See the Ansible section of my Knowledge Base for more information.

As always, if you have any questions or have a topic that you would like me to discuss, please feel free to post a comment at the bottom of this blog entry, e-mail at will@oznetnerd.com, or drop me a message on Twitter (@OzNetNerd).

Note: This website is my personal blog. The opinions expressed in this blog are my own and not those of my employer.