2024-01-25 21:40:44 +00:00
|
|
|
---
|
|
|
|
# hashistack configuration merging for consul
|
|
|
|
- name: "Consul | Merge stringified configuration"
|
|
|
|
vars:
|
|
|
|
_config_to_merge: "{{ hashi_consul_configuration_string }}"
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
hashi_consul_configuration: "{{
|
|
|
|
hashi_consul_configuration |
|
|
|
|
combine(_config_to_merge|from_yaml)
|
|
|
|
}}"
|
2024-03-17 18:05:02 +00:00
|
|
|
when:
|
|
|
|
- hashi_consul_configuration_string is defined
|
|
|
|
- "'consul_servers' in group_names"
|
2024-01-25 21:40:44 +00:00
|
|
|
|
|
|
|
- name: "Consul | Merge addresses configuration"
|
|
|
|
vars:
|
|
|
|
_config_to_merge: "{{ consul_address_configuration }}"
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
hashi_consul_configuration: "{{
|
|
|
|
hashi_consul_configuration |
|
|
|
|
combine(_config_to_merge)
|
|
|
|
}}"
|
|
|
|
when: consul_address_configuration is defined
|
|
|
|
|
2024-03-12 23:02:14 +00:00
|
|
|
- name: "Consul | Merge token configuration"
|
|
|
|
delegate_to: localhost
|
|
|
|
block:
|
|
|
|
- name: "Consul | Stat consul secrets file"
|
|
|
|
ansible.builtin.stat:
|
2024-03-13 22:27:12 +00:00
|
|
|
path: "{{ sub_configuration_directories.consul_servers }}/consul_config.yml"
|
2024-03-12 23:02:14 +00:00
|
|
|
register: _consul_config_file
|
|
|
|
|
|
|
|
- name: "Consul | Load consul secrets file"
|
|
|
|
ansible.builtin.include_vars:
|
2024-03-13 22:27:12 +00:00
|
|
|
file: "{{ sub_configuration_directories.consul_servers }}/consul_config.yml"
|
2024-03-12 23:02:14 +00:00
|
|
|
name: _consul_cluster_config
|
|
|
|
when: _consul_config_file.stat.exists
|
|
|
|
|
2024-03-17 18:05:02 +00:00
|
|
|
- name: "Consul | Merge token configuration"
|
2024-03-12 23:02:14 +00:00
|
|
|
vars:
|
|
|
|
_config_to_merge:
|
|
|
|
acl:
|
2024-03-13 22:27:12 +00:00
|
|
|
tokens: "{{ _consul_cluster_config.tokens }}"
|
2024-03-12 23:02:14 +00:00
|
|
|
ansible.builtin.set_fact:
|
|
|
|
hashi_consul_configuration: "{{ hashi_consul_configuration | default({}) | combine(_config_to_merge, recursive=true) }}"
|
2024-03-13 22:27:12 +00:00
|
|
|
when: _consul_cluster_config.tokens is defined
|
2024-03-12 23:02:14 +00:00
|
|
|
|
2024-03-17 18:05:02 +00:00
|
|
|
- name: "Consul | Create secrets file if not present"
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: "{{ sub_configuration_directories.consul_servers }}/consul_config.yml"
|
|
|
|
state: touch
|
|
|
|
owner: "{{ lookup('env', 'USER') }}"
|
|
|
|
group: "{{ lookup('env', 'USER') }}"
|
|
|
|
mode: "0644"
|
|
|
|
run_once: true
|
|
|
|
when: not _consul_config_file.stat.exists
|
|
|
|
|
2024-01-25 21:40:44 +00:00
|
|
|
- name: "Consul | Merge extra configuration settings"
|
|
|
|
vars:
|
|
|
|
_config_to_merge: "{{ consul_extra_configuration }}"
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
hashi_consul_configuration: "{{
|
|
|
|
hashi_consul_configuration |
|
|
|
|
combine(_config_to_merge)
|
|
|
|
}}"
|
|
|
|
when: consul_extra_configuration is defined
|