feat(vars): load group vars dynamically if files exist
This commit is contained in:
parent
34bb4bd7ad
commit
f78ea02bdd
@ -9,6 +9,10 @@
|
|||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: "{{ hashi_vault_configuration.listener }}"
|
msg: "{{ hashi_vault_configuration.listener }}"
|
||||||
|
|
||||||
|
- name: "Import variables"
|
||||||
|
ansible.builtin.import_tasks:
|
||||||
|
file: load_vars.yml
|
||||||
|
|
||||||
- name: "Vault"
|
- name: "Vault"
|
||||||
when: enable_vault | bool
|
when: enable_vault | bool
|
||||||
when: "'vault_servers' in group_names"
|
when: "'vault_servers' in group_names"
|
||||||
|
@ -1,33 +1,49 @@
|
|||||||
---
|
---
|
||||||
# hashistack variable injection playbook
|
# hashistack variable injection playbook
|
||||||
- name: "Deploy"
|
- name: "Load global variables"
|
||||||
hosts: all
|
|
||||||
gather_facts: true
|
|
||||||
become: true
|
|
||||||
tasks:
|
|
||||||
- name: "Load global variables"
|
|
||||||
block:
|
block:
|
||||||
- name: "Stat global configuration file"
|
- name: "Stat global configuration file"
|
||||||
ansible.builtin.stat:
|
ansible.builtin.stat:
|
||||||
path: "{{ configuration_directory }}/{{ configuration_global_vars_file }}"
|
path: "{{ configuration_directory }}/{{ configuration_global_vars_file }}"
|
||||||
register: _global_config_file
|
register: _global_config_file
|
||||||
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: "Make sure global configuration file exists"
|
- name: "Make sure global configuration file exists"
|
||||||
ansible.builtin.assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- _global_config_file.stat.exists
|
- _global_config_file.stat.exists
|
||||||
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: "Load global variables"
|
- name: "Load global variables"
|
||||||
ansible.builtin.include_vars:
|
ansible.builtin.include_vars:
|
||||||
dir: "{{ configuration_directory }}"
|
dir: "{{ configuration_directory }}"
|
||||||
files_matching: "{{ configuration_global_vars_file }}"
|
files_matching: "{{ configuration_global_vars_file }}"
|
||||||
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: "Load group specific variables"
|
- name: "Load group specific variables"
|
||||||
ansible.builtin.include_vars:
|
block:
|
||||||
dir: ""
|
- name: "Stat group specific config file"
|
||||||
files_matching: ""
|
ansible.builtin.stat:
|
||||||
|
path: "{{ configuration_directory }}/{{ item }}/{{ configuration_global_vars_file }}"
|
||||||
|
register: _group_config_file
|
||||||
|
loop: "{{ group_names }}"
|
||||||
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: "Load host specific variables"
|
- name: "debug"
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "{{ _group_config_file }}"
|
||||||
|
|
||||||
|
- name: Load group specific variables
|
||||||
ansible.builtin.include_vars:
|
ansible.builtin.include_vars:
|
||||||
dir: ""
|
dir: "{{ configuration_directory }}/{{ item.item }}"
|
||||||
files_matching: ""
|
files_matching: "{{ configuration_global_vars_file }}"
|
||||||
|
loop: "{{ _group_config_file.results }}"
|
||||||
|
when: item.stat.exists
|
||||||
|
delegate_to: localhost
|
||||||
|
|
||||||
|
|
||||||
|
# - name: "Load host specific variables"
|
||||||
|
# ansible.builtin.include_vars:
|
||||||
|
# dir: ""
|
||||||
|
# files_matching: ""
|
||||||
|
- fail:
|
Loading…
Reference in New Issue
Block a user