Are facts carried forward?

90 views
Skip to first unread message

Michael Dur

unread,
Aug 29, 2014, 11:22:49 AM8/29/14
to ansible...@googlegroups.com
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

Michael DeHaan

unread,
Aug 29, 2014, 11:29:26 AM8/29/14
to ansible...@googlegroups.com
Answered this exact same question here yesterday:

Facts are available throughout the playbook run, or longer, if fact caching is enabled.





--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/afc0834b-5e2b-41db-a3f7-a38abc7d0063%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

kesten broughton

unread,
Aug 29, 2014, 1:44:28 PM8/29/14
to ansible...@googlegroups.com
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. 

 - hosts: all
   gather_facts: yes

 - hosts: group1           
   gather_facts: no      # faster not to gather_facts if we got them above
   roles: 
     - role-that-uses-facts
     
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.

Henry Finucane

unread,
Aug 30, 2014, 3:11:48 PM8/30/14
to ansible...@googlegroups.com
Are you aware of 'smart' fact gathering? I think this might ameliorate
your problems:

http://docs.ansible.com/intro_configuration.html#gathering
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/9e76926e-40d3-4fe8-8e93-e05e83e7df2e%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
-----------------------
| Henry Finucane
| "I hear aphorisms are popular"
-----------------------

Michael DeHaan

unread,
Sep 2, 2014, 12:33:05 PM9/2/14
to ansible...@googlegroups.com
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.




Reply all
Reply to author
Forward
0 new messages