2023-12-30 14:54:37 +00:00
|
|
|
---
|
|
|
|
# hashistack variable injection playbook
|
2024-01-02 22:25:59 +00:00
|
|
|
- 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
|
|
|
|
|
2023-12-30 14:54:37 +00:00
|
|
|
- name: "Load global variables"
|
2024-01-02 22:25:59 +00:00
|
|
|
ansible.builtin.include_vars:
|
|
|
|
dir: "{{ configuration_directory }}"
|
|
|
|
files_matching: "{{ configuration_global_vars_file }}"
|
2024-01-03 20:06:30 +00:00
|
|
|
depth: 1
|
2024-01-02 22:25:59 +00:00
|
|
|
delegate_to: localhost
|
2024-01-02 20:11:32 +00:00
|
|
|
|
2024-01-02 22:25:59 +00:00
|
|
|
- name: "Load group specific variables"
|
|
|
|
block:
|
|
|
|
- name: "Stat group specific config file"
|
|
|
|
ansible.builtin.stat:
|
2024-01-03 20:06:30 +00:00
|
|
|
path: "{{ configuration_directory }}/{{ group_name }}/{{ configuration_global_vars_file }}"
|
2024-01-02 22:25:59 +00:00
|
|
|
register: _group_config_file
|
|
|
|
loop: "{{ group_names }}"
|
2024-01-03 20:06:30 +00:00
|
|
|
loop_control:
|
|
|
|
loop_var: group_name
|
2023-12-30 14:54:37 +00:00
|
|
|
|
2024-01-02 22:25:59 +00:00
|
|
|
- name: Load group specific variables
|
2023-12-30 14:54:37 +00:00
|
|
|
ansible.builtin.include_vars:
|
2024-01-03 20:06:30 +00:00
|
|
|
dir: "{{ configuration_directory }}/{{ item.group_name }}"
|
2024-01-02 22:25:59 +00:00
|
|
|
files_matching: "{{ configuration_global_vars_file }}"
|
2024-01-03 20:06:30 +00:00
|
|
|
depth: 1
|
2024-01-02 22:25:59 +00:00
|
|
|
loop: "{{ _group_config_file.results }}"
|
|
|
|
when: item.stat.exists
|
2024-01-03 20:06:30 +00:00
|
|
|
and item.group_name in group_names
|
|
|
|
loop_control:
|
|
|
|
loop_var: item
|
2024-01-02 22:25:59 +00:00
|
|
|
delegate_to: localhost
|
2023-12-30 14:54:37 +00:00
|
|
|
|
2024-01-03 16:38:09 +00:00
|
|
|
- name: "Load host specific variables"
|
|
|
|
block:
|
|
|
|
- name: "Stat host specific config file"
|
|
|
|
ansible.builtin.stat:
|
2024-01-03 20:06:30 +00:00
|
|
|
path: "{{ configuration_directory }}/{{ group_name }}/{{ inventory_hostname }}/{{ configuration_global_vars_file }}"
|
2024-01-03 16:38:09 +00:00
|
|
|
register: _host_config_file
|
|
|
|
loop: "{{ group_names }}"
|
2024-01-03 20:06:30 +00:00
|
|
|
loop_control:
|
|
|
|
loop_var: group_name
|
2024-01-03 16:38:09 +00:00
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
- name: Load host specific variables
|
|
|
|
ansible.builtin.include_vars:
|
2024-01-03 20:06:30 +00:00
|
|
|
dir: "{{ configuration_directory }}/{{ item.group_name }}/{{ inventory_hostname }}"
|
2024-01-03 16:38:09 +00:00
|
|
|
files_matching: "{{ configuration_global_vars_file }}"
|
|
|
|
loop: "{{ _host_config_file.results }}"
|
|
|
|
when: item.stat.exists
|
2024-01-03 20:06:30 +00:00
|
|
|
loop_control:
|
|
|
|
loop_var: item
|
2024-01-03 16:38:09 +00:00
|
|
|
delegate_to: localhost
|
2024-01-02 22:25:59 +00:00
|
|
|
|
2024-04-06 21:47:35 +00:00
|
|
|
- name: "Ensure remote directories exists"
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: "{{ item }}"
|
|
|
|
state: directory
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0755
|
|
|
|
recurse: yes
|
|
|
|
loop:
|
|
|
|
- "{{ hashistack_remote_config_dir }}"
|
|
|
|
- "{{ hashistack_remote_data_dir }}"
|
|
|
|
|
|
|
|
- name: "Load custom CA certificates"
|
|
|
|
block:
|
|
|
|
- name: "Check if CA directory exists"
|
|
|
|
ansible.builtin.stat:
|
|
|
|
path: "{{ sub_configuration_directories['certificates'] }}/ca"
|
|
|
|
register: _hashistack_ca_directory
|
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
- name: "Find custom ca certificates to copy"
|
|
|
|
ansible.builtin.find:
|
|
|
|
paths: "{{ sub_configuration_directories['certificates'] }}/ca"
|
|
|
|
patterns: "*.crt"
|
|
|
|
register: _hashistack_cacert_files
|
|
|
|
delegate_to: localhost
|
|
|
|
when: _hashistack_ca_directory.stat.exists and _hashistack_ca_directory.stat.isdir
|
|
|
|
|
|
|
|
- ansible.builtin.debug:
|
|
|
|
msg: "{{ _hashistack_cacert_files }}"
|
|
|
|
|
|
|
|
- name: "Ensure remote ca directory exists"
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: "{{ hashistack_remote_config_dir }}/ca"
|
|
|
|
state: directory
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0755
|
|
|
|
|
|
|
|
- name: "Copy custom ca certificates"
|
|
|
|
ansible.builtin.copy:
|
|
|
|
src: "{{ item.path }}"
|
|
|
|
dest: "{{ hashistack_remote_config_dir }}/ca/{{ item.path | basename }}"
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0644
|
|
|
|
loop: "{{ _hashistack_cacert_files.files }}"
|
|
|
|
register: _hashistack_copied_ca
|
|
|
|
|
|
|
|
- name: "Copy and update trust store"
|
|
|
|
block:
|
|
|
|
- name: "Copy ca certificates to /usr/loca/share/ca-certificates"
|
|
|
|
ansible.builtin.file:
|
|
|
|
state: link
|
|
|
|
src: "{{ item.dest }}"
|
|
|
|
dest: "/usr/local/share/ca-certificates/hashistack-customca-{{ item.dest | basename }}"
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
loop: "{{ _hashistack_copied_ca.results }}"
|
|
|
|
register: _hashistack_usr_local_share_ca_certificates
|
|
|
|
|
|
|
|
- name: "Update the trust store"
|
|
|
|
ansible.builtin.command: update-ca-certificates
|
|
|
|
changed_when: false
|
|
|
|
when: _hashistack_usr_local_share_ca_certificates.changed
|
|
|
|
|
|
|
|
# - name: "Initialize list of CA certificates"
|
|
|
|
# ansible.builtin.set_fact:
|
|
|
|
# hashistack_cacert_extra_files: []
|
|
|
|
# delegate_to: localhost
|
|
|
|
|
|
|
|
# - name: "Add custom CA to list of extra certificates"
|
|
|
|
# ansible.builtin.set_fact:
|
|
|
|
# hashistack_cacert_extra_files: "{{
|
|
|
|
# hashistack_cacert_extra_files | default([])
|
|
|
|
# + [{'src': item.path, 'dest': '/etc/ssl/certs/hashistack-custom-' + item.path | basename}] }}"
|
|
|
|
# loop: "{{ _hashistack_cacert_files.files }}"
|
|
|
|
# delegate_to: localhost
|
|
|
|
# when: _hashistack_cacert_files.matched > 0
|
|
|
|
|
2024-01-25 21:40:44 +00:00
|
|
|
- name: "Merge consul configurations"
|
|
|
|
ansible.builtin.import_tasks:
|
2024-03-13 22:27:12 +00:00
|
|
|
file: "consul/consul_vars.yml"
|
2024-01-25 21:40:44 +00:00
|
|
|
when:
|
|
|
|
- enable_consul | bool
|
2024-03-17 18:05:02 +00:00
|
|
|
- "('consul_servers' in group_names) or ('consul_agents' in group_names)"
|
2024-01-25 21:40:44 +00:00
|
|
|
|
2024-01-05 22:58:30 +00:00
|
|
|
- name: "Merge vault configurations"
|
|
|
|
ansible.builtin.import_tasks:
|
2024-03-13 22:27:12 +00:00
|
|
|
file: "vault/vault_vars.yml"
|
2024-01-05 22:58:30 +00:00
|
|
|
when:
|
|
|
|
- enable_vault | bool
|
|
|
|
- "'vault_servers' in group_names"
|
2024-03-17 09:57:02 +00:00
|
|
|
|
|
|
|
- debug:
|
|
|
|
msg: "{{ deploy_haproxy_frontends }}"
|
|
|
|
|
|
|
|
- debug:
|
|
|
|
msg: "{{ deploy_haproxy_backends }}"
|
|
|
|
# - fail:
|