Skip to content

Commit b1f70ce

Browse files
committed
Refactor the use of include_vars
Move remaining os-default files to vars directory, where the include_vars expects them to be. Use a first_found lookup instead of a with_first_found loop so that the 'paths' parameter can be used. This ensures that only vars from the role are included, and not vars from a parent calling role. This can happen when a parent role has a higher priority vars file available for inclusion than the role it calls. Change-Id: I49c041b2217c51048fa182106009d334b6b38f6f
1 parent e0a5a72 commit b1f70ce

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

playbooks/roles/bifrost-create-vm-nodes/defaults/dummy-defaults.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.

playbooks/roles/bifrost-create-vm-nodes/tasks/main.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@
2323
- ansible_distribution == "CentOS"
2424
- ansible_distribution_version|int >= 9
2525

26-
- name: "Load distribution defaults"
27-
include_vars: "{{ item }}"
28-
with_first_found:
29-
- "../defaults/required_defaults_{{ ansible_distribution }}.yml"
30-
- "../defaults/required_defaults_{{ ansible_os_family }}.yml"
31-
32-
- name: "Include OS version-specific defaults"
33-
include_vars: "{{ item }}"
34-
with_first_found:
35-
- "../defaults/required_defaults_{{ ansible_distribution }}_{{ ansible_distribution_release }}.yml"
36-
- "../defaults/required_defaults_{{ ansible_distribution }}_{{ ansible_distribution_version }}.yml"
37-
- "../defaults/dummy-defaults.yml"
26+
- name: Gather variables for each operating system
27+
include_vars: "{{ lookup('first_found', params) }}"
28+
vars:
29+
params:
30+
files:
31+
- "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_version'] | lower }}.yml"
32+
- "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml"
33+
- "{{ ansible_facts['os_family'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml"
34+
- "{{ ansible_facts['distribution'] | lower }}.yml"
35+
- "{{ ansible_facts['os_family'] | lower }}.yml"
36+
paths:
37+
- "{{ role_path }}/vars"
3838

3939
- name: "Install required packages"
4040
package:
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)