Refactor the use of include_vars

The debian_family and ubuntu files have the same content, and they're
both in the debian family, so drop the ubuntu 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: I93b0d7f296bae859914477b4009e44a44e3bde1a
This commit is contained in:
Erik Berg 2023-02-20 23:55:08 +01:00
parent e8a4942ea4
commit 619dbe31e2
No known key found for this signature in database
GPG Key ID: 1182D19B0E5ED030
5 changed files with 12 additions and 32 deletions

View File

@ -1,3 +0,0 @@
---
# NOTE(cinerama) This file is intentionally left blank - do not
# add variables here.

View File

@ -1,8 +0,0 @@
---
required_packages:
- mariadb-server
- python3-dev
- libffi-dev
- libxslt1-dev
- libssl-dev
- libxml2-dev

View File

@ -11,27 +11,18 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
--- ---
# NOTE(cinerama) dummy-defaults.yml is an empty defaults file. We use it - name: Gather variables for each operating system
# here to ensure that with_first_found won't fail should we not have include_vars: "{{ lookup('first_found', params) }}"
# defaults for a particular distribution, version, etc. vars:
- name: Include OS family-specific defaults params:
include_vars: "{{ item }}" files:
with_first_found: - "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_version'] | lower }}.yml"
- "../defaults/required_defaults_{{ ansible_os_family }}_family.yml" - "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml"
- "../defaults/dummy-defaults.yml" - "{{ ansible_facts['os_family'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml"
- "{{ ansible_facts['distribution'] | lower }}.yml"
- name: Include OS distribution-specific defaults - "{{ ansible_facts['os_family'] | lower }}.yml"
include_vars: "{{ item }}" paths:
with_first_found: - "{{ role_path }}/vars"
- "../defaults/required_defaults_{{ ansible_distribution }}.yml"
- "../defaults/dummy-defaults.yml"
- name: Include OS version-specific defaults
include_vars: "{{ item }}"
with_first_found:
- "../defaults/required_defaults_{{ ansible_distribution }}_{{ ansible_distribution_release }}.yml"
- "../defaults/required_defaults_{{ ansible_distribution }}_{{ ansible_distribution_version }}.yml"
- "../defaults/dummy-defaults.yml"
- name: "Install Keystone" - name: "Install Keystone"
include_tasks: install.yml include_tasks: install.yml