Skip to content

Commit

Permalink
fix: replace omit with dynamic j2 list
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelmamula committed Dec 9, 2024
1 parent 4916c2a commit 8680796
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 28 deletions.
19 changes: 12 additions & 7 deletions roles/sap_general_preconfigure/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,25 @@
# 5. SLES_SAP_15.6.yml - Specific to distribution SLES_SAP and minor release.
- name: Include OS specific vars, specific
ansible.builtin.include_vars: "{{ __vars_file }}"
loop:
- "{{ ansible_os_family }}.yml"
- "{{ ansible_distribution ~ '.yml' if ansible_distribution != ansible_os_family else omit }}"
- "{{ __distribution_major_split ~ '.yml' if __distribution_major_split != __distribution_major else omit }}"
- "{{ __distribution_minor_split ~ '.yml' if __distribution_minor_split != __distribution_minor else omit }}"
- "{{ __distribution_major }}.yml"
- "{{ __distribution_minor }}.yml"
loop: "{{ __var_files }}"
vars:
__vars_file: "{{ role_path }}/vars/{{ item }}"
__distribution_major: "{{ ansible_distribution ~ '_' ~ ansible_distribution_major_version }}"
__distribution_minor: "{{ ansible_distribution ~ '_' ~ ansible_distribution_version }}"
# Enables loading of shared vars between SLES and SLES_SAP
__distribution_major_split: "{{ ansible_distribution.split('_')[0] ~ '_' ~ ansible_distribution_major_version }}"
__distribution_minor_split: "{{ ansible_distribution.split('_')[0] ~ '_' ~ ansible_distribution_version }}"
__var_files: >-
{{
[
ansible_os_family ~ '.yml',
(ansible_distribution ~ '.yml') if ansible_distribution != ansible_os_family else None,
(__distribution_major_split ~ '.yml') if __distribution_major_split != __distribution_major else None,
(__distribution_minor_split ~ '.yml') if __distribution_minor_split != __distribution_minor else None,
__distribution_major ~ '.yml',
__distribution_minor ~ '.yml'
] | select('defined') | select('string') | list
}}
when: __vars_file is file
tags:
- always
Expand Down
19 changes: 12 additions & 7 deletions roles/sap_ha_pacemaker_cluster/tasks/include_vars_common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,23 @@
# 5. SLES_SAP_15.6.yml - Specific to distribution SLES_SAP and minor release.
- name: "SAP HA Prepare Pacemaker - Include environment specific variables"
ansible.builtin.include_vars: "{{ __vars_file }}"
loop:
- "{{ ansible_os_family }}.yml"
- "{{ ansible_distribution ~ '.yml' if ansible_distribution != ansible_os_family else omit }}"
- "{{ __distribution_major_split ~ '.yml' if __distribution_major_split != __distribution_major else omit }}"
- "{{ __distribution_minor_split ~ '.yml' if __distribution_minor_split != __distribution_minor else omit }}"
- "{{ __distribution_major }}.yml"
- "{{ __distribution_minor }}.yml"
loop: "{{ __var_files }}"
vars:
__vars_file: "{{ role_path }}/vars/{{ item }}"
__distribution_major: "{{ ansible_distribution ~ '_' ~ ansible_distribution_major_version }}"
__distribution_minor: "{{ ansible_distribution ~ '_' ~ ansible_distribution_version }}"
# Enables loading of shared vars between SLES and SLES_SAP
__distribution_major_split: "{{ ansible_distribution.split('_')[0] ~ '_' ~ ansible_distribution_major_version }}"
__distribution_minor_split: "{{ ansible_distribution.split('_')[0] ~ '_' ~ ansible_distribution_version }}"
__var_files: >-
{{
[
ansible_os_family ~ '.yml',
(ansible_distribution ~ '.yml') if ansible_distribution != ansible_os_family else None,
(__distribution_major_split ~ '.yml') if __distribution_major_split != __distribution_major else None,
(__distribution_minor_split ~ '.yml') if __distribution_minor_split != __distribution_minor else None,
__distribution_major ~ '.yml',
__distribution_minor ~ '.yml'
] | select('defined') | select('string') | list
}}
when: __vars_file is file
19 changes: 12 additions & 7 deletions roles/sap_hana_preconfigure/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,25 @@
# 5. SLES_SAP_15.6.yml - Specific to distribution SLES_SAP and minor release.
- name: Include OS specific vars, specific
ansible.builtin.include_vars: "{{ __vars_file }}"
loop:
- "{{ ansible_os_family }}.yml"
- "{{ ansible_distribution ~ '.yml' if ansible_distribution != ansible_os_family else omit }}"
- "{{ __distribution_major_split ~ '.yml' if __distribution_major_split != __distribution_major else omit }}"
- "{{ __distribution_minor_split ~ '.yml' if __distribution_minor_split != __distribution_minor else omit }}"
- "{{ __distribution_major }}.yml"
- "{{ __distribution_minor }}.yml"
loop: "{{ __var_files }}"
vars:
__vars_file: "{{ role_path }}/vars/{{ item }}"
__distribution_major: "{{ ansible_distribution ~ '_' ~ ansible_distribution_major_version }}"
__distribution_minor: "{{ ansible_distribution ~ '_' ~ ansible_distribution_version }}"
# Enables loading of shared vars between SLES and SLES_SAP
__distribution_major_split: "{{ ansible_distribution.split('_')[0] ~ '_' ~ ansible_distribution_major_version }}"
__distribution_minor_split: "{{ ansible_distribution.split('_')[0] ~ '_' ~ ansible_distribution_version }}"
__var_files: >-
{{
[
ansible_os_family ~ '.yml',
(ansible_distribution ~ '.yml') if ansible_distribution != ansible_os_family else None,
(__distribution_major_split ~ '.yml') if __distribution_major_split != __distribution_major else None,
(__distribution_minor_split ~ '.yml') if __distribution_minor_split != __distribution_minor else None,
__distribution_major ~ '.yml',
__distribution_minor ~ '.yml'
] | select('defined') | select('string') | list
}}
when: __vars_file is file


Expand Down
19 changes: 12 additions & 7 deletions roles/sap_netweaver_preconfigure/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,25 @@
# 5. SLES_SAP_15.6.yml - Specific to distribution SLES_SAP and minor release.
- name: Include OS specific vars, specific
ansible.builtin.include_vars: "{{ __vars_file }}"
loop:
- "{{ ansible_os_family }}.yml"
- "{{ ansible_distribution ~ '.yml' if ansible_distribution != ansible_os_family else omit }}"
- "{{ __distribution_major_split ~ '.yml' if __distribution_major_split != __distribution_major else omit }}"
- "{{ __distribution_minor_split ~ '.yml' if __distribution_minor_split != __distribution_minor else omit }}"
- "{{ __distribution_major }}.yml"
- "{{ __distribution_minor }}.yml"
loop: "{{ __var_files }}"
vars:
__vars_file: "{{ role_path }}/vars/{{ item }}"
__distribution_major: "{{ ansible_distribution ~ '_' ~ ansible_distribution_major_version }}"
__distribution_minor: "{{ ansible_distribution ~ '_' ~ ansible_distribution_version }}"
# Enables loading of shared vars between SLES and SLES_SAP
__distribution_major_split: "{{ ansible_distribution.split('_')[0] ~ '_' ~ ansible_distribution_major_version }}"
__distribution_minor_split: "{{ ansible_distribution.split('_')[0] ~ '_' ~ ansible_distribution_version }}"
__var_files: >-
{{
[
ansible_os_family ~ '.yml',
(ansible_distribution ~ '.yml') if ansible_distribution != ansible_os_family else None,
(__distribution_major_split ~ '.yml') if __distribution_major_split != __distribution_major else None,
(__distribution_minor_split ~ '.yml') if __distribution_minor_split != __distribution_minor else None,
__distribution_major ~ '.yml',
__distribution_minor ~ '.yml'
] | select('defined') | select('string') | list
}}
when: __vars_file is file
tags:
- always
Expand Down

0 comments on commit 8680796

Please sign in to comment.