hcp-ansible/playbooks/load_vars.yml

69 lines
2.2 KiB
YAML

---
# hashistack variable injection playbook
- name: "Load global variables"
block:
- name: "Stat global configuration file"
ansible.builtin.stat:
path: "{{ configuration_directory }}/{{ configuration_global_vars_file }}"
register: _global_config_file
delegate_to: localhost
- name: "Make sure global configuration file exists"
ansible.builtin.assert:
that:
- _global_config_file.stat.exists
delegate_to: localhost
- name: "Load global variables"
ansible.builtin.include_vars:
dir: "{{ configuration_directory }}"
files_matching: "{{ configuration_global_vars_file }}"
delegate_to: localhost
- name: "Load group specific variables"
block:
- name: "Stat group specific config file"
ansible.builtin.stat:
path: "{{ configuration_directory }}/{{ item }}/{{ configuration_global_vars_file }}"
register: _group_config_file
loop: "{{ group_names }}"
delegate_to: localhost
- name: "debug"
ansible.builtin.debug:
msg: "{{ _group_config_file }}"
- name: Load group specific variables
ansible.builtin.include_vars:
dir: "{{ configuration_directory }}/{{ item.item }}"
files_matching: "{{ configuration_global_vars_file }}"
loop: "{{ _group_config_file.results }}"
when: item.stat.exists
delegate_to: localhost
- name: "Load host specific variables"
block:
- name: "Stat host specific config file"
ansible.builtin.stat:
path: "{{ configuration_directory }}/{{ item }}/{{ inventory_hostname }}/{{ configuration_global_vars_file }}"
register: _host_config_file
loop: "{{ group_names }}"
delegate_to: localhost
- name: "debug"
ansible.builtin.debug:
msg: "{{ _host_config_file }}"
- name: Load host specific variables
ansible.builtin.include_vars:
dir: "{{ configuration_directory }}/{{ item.item }}/{{ inventory_hostname }}"
files_matching: "{{ configuration_global_vars_file }}"
loop: "{{ _host_config_file.results }}"
when: item.stat.exists
delegate_to: localhost
# - name: "Load host specific variables"
# ansible.builtin.include_vars:
# dir: ""
# files_matching: ""
- fail: