Fastest way to gather facts to fact cache

Sepehr Nazari picture Sepehr Nazari · Sep 21, 2015 · Viewed 18.6k times · Source

I am trying to make Ansible work with --limit and to do that I need facts about other hosts, which I am caching with fact_caching. What command should I run so that it simply gathers all the facts on all the hosts and caches them, without running any tasks? Something like the setup module would be perfect if it cached the facts it gathered, but it seems like it does not.

Answer

alfredocambera picture alfredocambera · Sep 22, 2015

Here is how I'd solve the problem:

1.- Enable facts gathering on your playbook (site.yml):

gather_facts: yes

2.- Enable facts caching on ansible.cfg:

2.1.- Option 1 - Use this if you have the time to install redis:

[defaults]
gathering = smart
fact_caching = redis

# two hours timeout
fact_caching_timeout = 7200

2.2.- Option 2 - Use this to test right now is simple but slower than redis:

[defaults]
gathering = smart
fact_caching = jsonfile
fact_caching_connection = /tmp/facts_cache

# two hours timeout
fact_caching_timeout = 7200

3.- Update or create the facts cache. To do this create a new role (cache-update) with just one task: execute ping. We use ping because is the simplest and fastest ansible task so it will help us update the cache really fast:

- name: Pinging server to update facts cache
  ping:             

Greetings,