automation-good-practices
automation-good-practices copied to clipboard
Decision on how to handle fact gathering in a role
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.
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
.
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?
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 usingvars/
the facts are defined indefaults/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 executestasks/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
orgather_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
.