Gathering facts in roles: Is it done multiple times?

4,141 views
Skip to first unread message

Frank Thommen

unread,
Jun 21, 2017, 4:29:11 AM6/21/17
to ansible...@googlegroups.com
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


jean...@lenhof.eu.org

unread,
Jun 21, 2017, 5:01:59 AM6/21/17
to ansible...@googlegroups.com
Hi Frank,

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

Frank Thommen

unread,
Jun 21, 2017, 7:07:11 AM6/21/17
to ansible...@googlegroups.com
On 06/21/2017 11:01 AM, jean...@lenhof.eu.org wrote:
> Hi Frank,
>
> 21 juin 2017 10:29 "Frank Thommen" <lists....@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

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

---
- include: tasks_1.yml
- include: tasks_2.yml

fact gathering would only happen once or once per *.yml (I'm not
completely sure which is the playbook and which the task in this setup,
sorry)

> 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.

The concrete example is more complicated, since some include are only
done on special conditions. Therefore I cannot really know from the
beginning, which tasks are run and which not. Consequently I wouldn't
know where to gather and where not.

frank


Philippe Eveque

unread,
Jun 21, 2017, 9:32:59 AM6/21/17
to ansible...@googlegroups.com
fact gathering is a play level directive 

(see 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







--
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-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/805a8b57-beca-c669-f0df-7ab306e0ec72%40drosera.ch.

For more options, visit https://groups.google.com/d/optout.

Brian Coca

unread,
Jun 21, 2017, 9:43:00 AM6/21/17
to Ansible Project
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

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


----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages