Skip to content

Commit

Permalink
allow role to work with gather_facts: false
Browse files Browse the repository at this point in the history
Allow the role to work if the playbook has set `gather_facts: false`.
The `gather_subset: min` includes all of the facts used by this
role.  Other roles may need to gather more facts.
The role gathers the facts where they are needed.  Other roles may
need to gather facts in a different place.
  • Loading branch information
richm committed Apr 11, 2022
1 parent 47088ce commit 7ad6cb2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions tasks/set_vars.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
---
- name: Ensure ansible_facts used by role
setup:
gather_subset: min
when: not ansible_facts.keys() | list |
intersect(__storage_required_facts) == __storage_required_facts

- name: Set platform/version specific variables
include_vars: "{{ __vars_file }}"
loop:
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_default.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- name: Ensure that the role runs with default parameters
hosts: all

gather_facts: false
roles:
- linux-system-roles.storage
6 changes: 6 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# ansible_facts required by the role
__storage_required_facts:
- distribution
- distribution_major_version
- distribution_version
- os_family

0 comments on commit 7ad6cb2

Please sign in to comment.