Gathering facts in roles: Is it done multiple times?

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

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

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

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
see http://docs.ansible.com/ansible/setup_module.html

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.