Skip to content

Commit

Permalink
support gather_facts: false; support setup-snapshot.yml (#53)
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.
  • Loading branch information
richm authored Apr 19, 2022
1 parent 0a16a0e commit cc453ea
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 13 deletions.
13 changes: 1 addition & 12 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,7 @@

# yamllint disable rule:line-length
- 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" # yamllint disable-line rule:line-length
- "{{ ansible_facts['distribution'] }}.yml"
- "{{ ansible_facts['os_family'] }}.yml"
- "default.yml"
paths:
- "{{ role_path }}/vars"
# yamllint enable rule:line-length
include_tasks: set_vars.yml

- name: Include the appropriate provider tasks
include_tasks: "main-{{ nbde_server_provider }}.yml"
Expand Down
20 changes: 20 additions & 0 deletions tasks/set_vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
- name: Ensure ansible_facts used by role
setup:
gather_subset: min
when: not ansible_facts.keys() | list |
intersect(__nbde_server_required_facts) ==
__nbde_server_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" # yamllint disable-line rule:line-length
- "{{ ansible_facts['distribution'] }}_{{ ansible_facts['distribution_major_version'] }}.yml" # yamllint disable-line rule:line-length
- "{{ ansible_facts['distribution'] }}.yml"
- "{{ ansible_facts['os_family'] }}.yml"
- "default.yml"
paths:
- "{{ role_path }}/vars"
12 changes: 12 additions & 0 deletions tests/setup-snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- hosts: all
tasks:
- name: Set platform/version specific variables
include_role:
name: linux-system-roles.nbde_server
tasks_from: set_vars.yml
public: true

- name: Install test packages
package:
name: "{{ __nbde_server_packages }}"
state: present
2 changes: 1 addition & 1 deletion tests/tests_default.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Ensure that the role runs with default parameters
hosts: all

gather_facts: false
roles:
- linux-system-roles.nbde_server

Expand Down
7 changes: 7 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# SPDX-License-Identifier: MIT
---

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

# vim:set ts=2 sw=2 et:

0 comments on commit cc453ea

Please sign in to comment.