--- # All rights reserved (c) 2020-2025, Vladimir Botka # Simplified BSD License, https://opensource.org/licenses/BSD-2-Clause # SPDX-License-Identifier: BSD-2-Clause # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # ansible_lib: al_include_os_vars_path # # Description: Include OS specific variables from al_os_vars_path. # # Input: # # al_os_vars_path ................ directory to read variables from # # Output: none # # Example: # # vars: # al_os_vars_path: "{{ playbook_dir }}" # tasks: # - include_role: # name: vbotka.ansible_lib # tasks_from: al_include_os_vars_path.yml # # Notes: # # 1) Create files vars/defaults/default.yml and vars/default.yml (at # least empty). # 2) Variables in vars/defaults/* will be overwritten by the file from # "with_first_found" in vars. # 3) Variables in vars/main.yml will be overwritten by the file from # the list "with_first_found". # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # https://github.com/vbotka/ansible-lib/tasks/al_include_os_vars_path.yml # Debug and Test input variable al_os_vars_path - - - - - - - - - - - - - - - - - - - - - - - name: "Al_include_os_vars_path: Debug al_debug={{ al_debug }}" when: al_debug | bool vars: msg: |- al_os_vars_path: {{ al_os_vars_path | d('UNDEFINED') }} ansible_os_family: {{ ansible_os_family }} ansible_distribution: {{ ansible_distribution }} ansible_distribution_release: {{ ansible_distribution_release }} ansible.builtin.debug: msg: "{{ '{}'.format(msg) }}" - name: "Al_include_os_vars_path: Test al_os_vars_path defined." when: al_os_vars_path is not defined ansible.builtin.fail: msg: "[ERR] Variable al_os_vars_path not defined." # Default variables - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - name: "Al_include_os_vars_path: Vars from {{ al_os_vars_path ~ '/vars/defaults' }}" when: _file | length > 0 vars: _file: "{{ lookup('ansible.builtin.first_found', params) }}" _files: - "{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_release'] }}.yml" - "{{ ansible_facts['distribution'] }}.yml" - "{{ ansible_facts['os_family'] }}.yml" - default.yml - defaults.yml params: files: "{{ _files | unique }}" paths: "{{ al_os_vars_path }}/vars/defaults" skip: true register: result ansible.builtin.include_vars: "{{ _file }}" - name: "Al_include_os_vars_path: Debug result al_debug2={{ al_debug2 }}" when: al_debug2 | bool ansible.builtin.debug: var: result # Custom variables - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - name: "Al_include_os_vars_path: vars from {{ al_os_vars_path ~ '/vars' }}" when: _file | length > 0 vars: _file: "{{ lookup('ansible.builtin.first_found', params) }}" _files: - "{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_release'] }}.yml" - "{{ ansible_facts['distribution'] }}.yml" - "{{ ansible_facts['os_family'] }}.yml" - default.yml - defaults.yml params: files: "{{ _files | unique }}" paths: "{{ al_os_vars_path }}/vars" skip: true register: result ansible.builtin.include_vars: "{{ _file }}" - name: "Al_include_os_vars_path: Debug result al_debug2={{ al_debug2 }}" when: al_debug2 | bool ansible.builtin.debug: var: result # EOF ...