From 30376f1ba560d9fcb35e53fb64a5f4eef84e9956 Mon Sep 17 00:00:00 2001 From: Erik Berg Date: Thu, 15 Sep 2022 10:30:14 +0200 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. Also removing redundant vars line Change-Id: I33b8b555d7feab93ece13eef8df27a1717da7ea0 --- tasks/main.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 51d4266..eb93ab7 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -16,14 +16,17 @@ # limitations under the License. - name: Gather variables for each operating system - include_vars: "{{ item }}" - with_first_found: - - "{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml" - - "{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml" - - "{{ ansible_os_family | lower }}-{{ ansible_distribution_major_version | lower }}.yml" - - "{{ ansible_distribution | lower }}.yml" - - "{{ ansible_os_family | lower }}-{{ ansible_distribution_version.split('.')[0] }}.yml" - - "{{ ansible_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 }}.yml" + paths: + - "{{ role_path }}/vars" tags: - always