# Gathering facts in roles: Is it done multiple times?

**URL:** <https://forum.ansible.com/t/gathering-facts-in-roles-is-it-done-multiple-times/24782>\
**Category:** Ansible Project\
**Created:** [June 21, 2017, 8:28am UTC](https://forum.ansible.com/t/gathering-facts-in-roles-is-it-done-multiple-times/24782 "2017-06-21T08:28:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frank\_Thommen](https://avatars.discourse-cdn.com/v4/letter/f/7feea3/32.png) [@Frank\_Thommen](https://forum.ansible.com/u/Frank_Thommen)\
**Post date:** [June 21, 2017, 8:28am UTC](https://forum.ansible.com/t/gathering-facts-in-roles-is-it-done-multiple-times/24782/1 "2017-06-21T08:28:22Z")

</div>

Hi,

from ansible's documentation I don't understand how ansible handles fact gathering when using roles: Are a host's facts gathered at each single playbook run? Or at each "role" run? Or only once?

In most cases one would want to gather facts only once in the beginning, but is this the case and/or how can I check this?

frank

---

<div class="post-metadata">

**Author:** ![jean-yves](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jean-yves](https://forum.ansible.com/u/jean-yves)\
**Post date:** [June 21, 2017, 9:01am UTC](https://forum.ansible.com/t/gathering-facts-in-roles-is-it-done-multiple-times/24782/2 "2017-06-21T09:01:36Z")

</div>

Hi Frank,

21 juin 2017 10:29 "Frank Thommen" \<lists.ansible@drosera.ch\> a écrit:

> Hi,
> 
> from ansible's documentation I don't understand how ansible handles fact gathering when using  
> roles: Are a host's facts gathered at each single playbook run? Or at each "role" run? Or only  
> once?
> 
> In most cases one would want to gather facts only once in the beginning, but is this the case  
> and/or how can I check this?

This is at playbook level, not at role level  
For me the gathering fact happens each time a new block of hosts/tasks in the playbook  
You can control it by using gather\_facts: no to skip it.

Regards,

JYL

---

<div class="post-metadata">

**Author:** ![Frank\_Thommen](https://avatars.discourse-cdn.com/v4/letter/f/7feea3/32.png) [@Frank\_Thommen](https://forum.ansible.com/u/Frank_Thommen)\
**Post date:** [June 21, 2017, 11:06am UTC](https://forum.ansible.com/t/gathering-facts-in-roles-is-it-done-multiple-times/24782/3 "2017-06-21T11:06:29Z")

</div>

I.e. for a playbook roles/common/tasks/main.yml which is

---

<div class="post-metadata">

**Author:** ![PhilEv](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@PhilEv](https://forum.ansible.com/u/PhilEv)\
**Post date:** [June 21, 2017, 1:32pm UTC](https://forum.ansible.com/t/gathering-facts-in-roles-is-it-done-multiple-times/24782/4 "2017-06-21T13:32:44Z")

</div>

fact gathering is a play level directive

(see [http://docs.ansible.com/ansible/playbooks\_keywords.html#play](http://docs.ansible.com/ansible/playbooks_keywords.html#play))

from the doc:

**gather\_facts:** A boolean that controls if the play will automatically run the ‘setup’ task to gather facts for the hosts

and one can run the setup module at anytime during the course of tasks execution to do it  
see [http://docs.ansible.com/ansible/setup\_module.html](http://docs.ansible.com/ansible/setup_module.html)

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 21, 2017, 1:42pm UTC](https://forum.ansible.com/t/gathering-facts-in-roles-is-it-done-multiple-times/24782/5 "2017-06-21T13:42:43Z")

</div>

As Phillippe states, this is a PLAY level keyword (true by default),  
also the 'gathering' setting in ansible.cfg can change the behaviour.  
[http://docs.ansible.com/ansible/intro\_configuration.html#gathering](http://docs.ansible.com/ansible/intro_configuration.html#gathering)

So it does not matter how many files nor roles are included, just the  
number of Plays and the hosts targeted by those plays.
