--- # All rights reserved (c) 2020-2024, Vladimir Botka # Simplified BSD License, https://opensource.org/licenses/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/blob/master/tasks/al_include_os_vars_path.yml # Debug and Test input variable al_os_vars_path - - - - - - - - - - - - - - - - - - - - - - - name: "Al_include_os_vars_path: Debug" vars: msg: |- al_os_vars_path: {{ al_os_vars_path | d('UNDEFINED') }} ansible.builtin.debug: msg: "{{ '{}'.format(msg) }}" when: al_debug | bool - name: "Al_include_os_vars_path: Test al_os_vars_path defined" ansible.builtin.fail: msg: Variable al_os_vars_path not defined. End of play. when: al_os_vars_path is not defined # Default variables - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - name: "Al_include_os_vars_path: Vars from {{ al_os_vars_path ~ '/vars/defaults' }}" ansible.builtin.include_vars: "{{ _file }}" vars: _file: "{{ lookup('ansible.builtin.first_found', params) }}" params: files: - "{{ ansible_distribution }}-{{ ansible_distribution_release }}.yml" - "{{ ansible_distribution }}.yml" - "{{ ansible_os_family }}.yml" - default.yml - defaults.yml paths: "{{ al_os_vars_path }}/vars/defaults" skip: true register: result when: _file | length > 0 - name: "Al_include_os_vars_path: Debug result" ansible.builtin.debug: var: result when: al_debug | bool # Custom variables - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - name: "Al_include_os_vars_path: vars from {{ al_os_vars_path ~ '/vars' }}" ansible.builtin.include_vars: "{{ _file }}" vars: _file: "{{ lookup('ansible.builtin.first_found', params) }}" params: files: - "{{ ansible_distribution }}-{{ ansible_distribution_release }}.yml" - "{{ ansible_distribution }}.yml" - "{{ ansible_os_family }}.yml" - default.yml - defaults.yml paths: "{{ al_os_vars_path }}/vars" skip: true # register: result when: _file | length > 0 # - name: "al_include_os_vars_path: Debug result" # ansible.builtin.debug: # var: result # when: al_debug | bool # EOF ...