automation-good-practices icon indicating copy to clipboard operation
automation-good-practices copied to clipboard

Decision on how to handle fact gathering in a role

Open ericzolf opened this issue 2 years ago • 3 comments

the system roles team recently had a request to be able to run roles when the user has done gather_facts: false in the playbook - what would we recommend? Only document, gather if not yet done, let it fail...

See https://chat.google.com/room/AAAAarh_G-k/LvyYgMPd0-E for details.

ericzolf avatar Mar 24 '22 16:03 ericzolf

Section 3.1.9.1. Platform specific variables seems to cover this topic.

But I have some trouble following the example given there. I don't understand where and how to define a list of required facts for __rolename_required_facts. So my playbook fails with the error '__rolename_required_facts' is undefined.

Tronde avatar Aug 03 '22 12:08 Tronde

Section 3.1.9.1. Platform specific variables seems to cover this topic.

But I have some trouble following the example given there. I don't understand where and how to define a list of required facts for __rolename_required_facts. So my playbook fails with the error '__rolename_required_facts' is undefined.

These are typically defined in vars/main.yml - most of the system roles use this e.g. https://github.com/linux-system-roles/storage/blob/master/vars/main.yml - in some cases where the role was not using vars/ the facts are defined in defaults/main.yml - https://github.com/linux-system-roles/network/blob/main/defaults/main.yml#L125 - as long as they are defined by the time ansible executes tasks/main.yml of the role.

Do you have a use case where you need to use ANSIBLE_GATHERING=explicit or gather_facts: false in your playbooks?

richm avatar Aug 03 '22 13:08 richm

Am 3. August 2022 15:41:10 MESZ schrieb Richard Megginson @.***>:

Section 3.1.9.1. Platform specific variables seems to cover this topic.

But I have some trouble following the example given there. I don't understand where and how to define a list of required facts for __rolename_required_facts. So my playbook fails with the error '__rolename_required_facts' is undefined.

These are typically defined in vars/main.yml - most of the system roles use this e.g. https://github.com/linux-system-roles/storage/blob/master/vars/main.yml - in some cases where the role was not using vars/ the facts are defined in defaults/main.yml - https://github.com/linux-system-roles/network/blob/main/defaults/main.yml#L125 - as long as they are defined by the time ansible executes tasks/main.yml of the role.

I got some help on this and have put it into vars/main.yml.

Do you have a use case where you need to use ANSIBLE_GATHERING=explicit or gather_facts: false in your playbooks?

Speaking for myself: No. I see this as some sort of failsave, so the role would work when used by someone else, who might have set gather_facts: false.

Tronde avatar Aug 03 '22 14:08 Tronde