We have many playbooks, and groups.
I notice when I do a full site run that at the beginning of the ‘top level’ playbooks, that is those referenced by site.yml, that facts are gathered each time.
I realize I can disable gathering facts for a given playbook.
Are facts that are previously gathered carried forward, allowing us to gather just once for a run?
Thanks!
-Michael
Answered this exact same question here yesterday:
Facts are available throughout the playbook run, or longer, if fact caching is enabled.
http://docs.ansible.com/playbooks_variables.html#fact-caching
Fact-caching will eliminate the need for the following workaround, but if you are stuck in pre 1.8 ansible…
If you have a bunch of plays in a site.yml and are a big fan of --start-at-task like i am, then there is a problem if downstream plays also require gathered facts.Having gather_facts: yes for every play slows things down.
But then if you start-at-task on the group1 play you don’t have the facts you need.
My solution was to have the first role always gather facts for normal runs.
- hosts: zoo
gather_facts: “{{ zoo_facts | default(‘no’)}}”
Then when debugging/developing i run with
ansible-playbook -i hosts site.yml --start-at-task=“task in zoo role” -e “zoo_facts=yes”
So we can start mid run, and switch on gathering facts for that role, but normally only the first play will gather facts.
Are you aware of 'smart' fact gathering? I think this might ameliorate
your problems:
http://docs.ansible.com/intro_configuration.html#gathering
Smart fact gathering won’t rerun fact gathering on a host that has already gathered, but it will not gather hosts explicitly on hosts that have not been gathered.
So it’s basically a performance tweak.