Skip to content

Commit

Permalink
support gather_facts: false; support setup-snapshot.yml (#52)
Browse files Browse the repository at this point in the history
Some users use `gather_facts: false` in their playbooks.  This changes
the role to work in that case, by gathering only the facts it requires
to run.
CI testing can be sped up by creating a snapshot image pre-installed
with packages.  tests/setup-snapshot.yml can be used by a CI system
to do this.

Use tests/setup-snapshot.yml just to put the packages in the local
cache. These packages may be or may not be installed.
  • Loading branch information
nhosoi authored and richm committed Apr 14, 2022
1 parent aca5514 commit 77d0e0f
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 13 deletions.
14 changes: 1 addition & 13 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
---
- name: Set version specific variables
include_vars: "{{ lookup('first_found', ffparams) }}"
vars:
ffparams:
files:
- "{{ ansible_facts['distribution'] }}_\
{{ ansible_facts['distribution_version'] }}.yml"
- "{{ ansible_facts['distribution'] }}_\
{{ ansible_facts['distribution_major_version'] }}.yml"
- "{{ ansible_facts['distribution'] }}.yml"
- "{{ ansible_facts['os_family'] }}.yml"
- "default.yml"
paths:
- "{{ role_path }}/vars"
include_tasks: tasks/set_vars.yml

- name: Populate service facts
service_facts:
Expand Down
21 changes: 21 additions & 0 deletions tasks/set_vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: Ensure ansible_facts used by role
setup:
gather_subset: min
when: not ansible_facts.keys() | list |
intersect(__timesync_required_facts) == __timesync_required_facts

- name: Set platform/version specific variables
include_vars: "{{ lookup('first_found', ffparams) }}"
vars:
ffparams:
files:
- "{{ ansible_facts['distribution'] }}_\
{{ ansible_facts['distribution_version'] }}.yml"
- "{{ ansible_facts['distribution'] }}_\
{{ ansible_facts['distribution_major_version'] }}.yml"
- "{{ ansible_facts['distribution'] }}.yml"
- "{{ ansible_facts['os_family'] }}.yml"
- "default.yml"
paths:
- "{{ role_path }}/vars"
26 changes: 26 additions & 0 deletions tests/setup-snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
- hosts: all
tasks:
- name: Set platform/version specific variables
include_role:
name: linux-system-roles.timesync
tasks_from: set_vars.yml
public: true

- name: Install test packages to put them in the local cache
package:
name:
- chrony
- ntp
- linuxptp
state: present
no_log: true
ignore_errors: true

- name: Uninstall test packages
package:
name:
- chrony
- ntp
- linuxptp
state: absent
no_log: true
1 change: 1 addition & 0 deletions tests/tests_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

roles:
- linux-system-roles.timesync
gather_facts: false
7 changes: 7 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ __timesync_chrony_version: "{{
__timesync_ntp_version: "{{
ansible_facts.packages['ntp'][0].version|default('0')
if 'ntp' in ansible_facts.packages else '0' }}"

# ansible_facts required by the role
__timesync_required_facts:
- distribution
- distribution_major_version
- distribution_version
- os_family

0 comments on commit 77d0e0f

Please sign in to comment.