From ee909497f29724048b5f46f3b758d6880bd883e5 Mon Sep 17 00:00:00 2001 From: Jonathan Rosser Date: Wed, 12 Jan 2022 08:14:32 +0000 Subject: [PATCH] Refactor use of include_vars 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: If58b7e10f39affe2f34af9e9503bc1f90caa4b0e --- tasks/main.yml | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index b95d25a..bd96d28 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -14,14 +14,18 @@ # limitations under the License. - name: Gather variables for each operating system - include_vars: "{{ item }}" - with_first_found: - - "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_version'] | lower }}.yml" - - "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml" - - "{{ ansible_facts['os_family'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml" - - "{{ ansible_facts['distribution'] | lower }}.yml" - - "{{ ansible_facts['os_family'] | lower }}-{{ ansible_facts['distribution_version'].split('.')[0] }}.yml" - - "{{ ansible_facts['os_family'] | lower }}.yml" + include_vars: "{{ lookup('first_found', params) }}" + vars: + params: + files: + - "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_version'] | lower }}.yml" + - "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml" + - "{{ ansible_facts['os_family'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml" + - "{{ ansible_facts['distribution'] | lower }}.yml" + - "{{ ansible_facts['os_family'] | lower }}-{{ ansible_facts['distribution_version'].split('.')[0] }}.yml" + - "{{ ansible_facts['os_family'] | lower }}.yml" + paths: + - "{{ role_path }}/vars" tags: - always