2023-12-15 17:45:58 +00:00
|
|
|
---
|
|
|
|
# hashistack deployment playbook
|
|
|
|
- name: "Deploy"
|
|
|
|
hosts: all
|
2024-01-04 21:09:49 +00:00
|
|
|
strategy: linear
|
2023-12-15 17:45:58 +00:00
|
|
|
gather_facts: true
|
2023-12-24 17:09:08 +00:00
|
|
|
become: true
|
2023-12-15 17:45:58 +00:00
|
|
|
tasks:
|
2024-01-04 21:09:49 +00:00
|
|
|
- name: "Debug"
|
2023-12-31 17:28:23 +00:00
|
|
|
ansible.builtin.debug:
|
|
|
|
msg: "{{ hashi_vault_configuration.listener }}"
|
2024-01-02 20:11:32 +00:00
|
|
|
|
2024-01-02 22:25:59 +00:00
|
|
|
- name: "Import variables"
|
|
|
|
ansible.builtin.import_tasks:
|
2024-01-04 21:09:49 +00:00
|
|
|
file: tasks/load_vars.yml
|
2024-01-02 22:25:59 +00:00
|
|
|
|
2024-01-05 22:58:30 +00:00
|
|
|
- name: "Debug"
|
|
|
|
ansible.builtin.debug:
|
|
|
|
msg: "{{ hashi_vault_configuration }}"
|
|
|
|
|
2024-01-25 21:40:44 +00:00
|
|
|
- name: "Debug"
|
|
|
|
ansible.builtin.debug:
|
|
|
|
msg: "{{ hashi_consul_configuration }}"
|
|
|
|
|
2024-01-06 14:50:51 +00:00
|
|
|
# - ansible.builtin.fail:
|
2024-01-05 22:58:30 +00:00
|
|
|
|
2024-01-25 21:40:44 +00:00
|
|
|
- name: "Consul"
|
|
|
|
when:
|
|
|
|
- enable_consul | bool
|
|
|
|
- "'consul_servers' in group_names"
|
|
|
|
tags:
|
|
|
|
- consul
|
|
|
|
block:
|
|
|
|
- name: "Include ednxzu.hashistack.hashicorp_consul"
|
|
|
|
ansible.builtin.include_role:
|
|
|
|
name: ednxzu.hashistack.hashicorp_consul
|
|
|
|
|
2023-12-30 14:54:37 +00:00
|
|
|
- name: "Vault"
|
2024-01-04 21:09:49 +00:00
|
|
|
when:
|
|
|
|
- enable_vault | bool
|
|
|
|
- "'vault_servers' in group_names"
|
2023-12-30 14:54:37 +00:00
|
|
|
tags:
|
|
|
|
- vault
|
|
|
|
block:
|
2024-01-25 21:40:44 +00:00
|
|
|
- name: "Include ednxzu.hashistack.hashicorp_consul"
|
2023-12-30 14:54:37 +00:00
|
|
|
ansible.builtin.include_role:
|
|
|
|
name: ednxzu.hashistack.hashicorp_vault
|
2023-12-24 17:09:08 +00:00
|
|
|
|
2024-01-04 21:09:49 +00:00
|
|
|
- name: "Initialize vault cluster" # noqa: run-once[task]
|
2023-12-30 14:54:37 +00:00
|
|
|
ednxzu.hashistack.vault_init:
|
2023-12-31 09:26:25 +00:00
|
|
|
api_url: "{{ hashi_vault_configuration['api_addr'] }}"
|
2024-01-05 22:05:57 +00:00
|
|
|
key_shares: "{{ vault_seal_configuration['key_shares'] }}"
|
|
|
|
key_threshold: "{{ vault_seal_configuration['key_threshold'] }}"
|
2023-12-30 14:54:37 +00:00
|
|
|
run_once: true
|
|
|
|
retries: 5
|
|
|
|
delay: 5
|
|
|
|
delegate_to: "{{ groups['vault_servers'] | first }}"
|
|
|
|
register: _vault_init_secret
|
|
|
|
until: not _vault_init_secret.failed
|
2023-12-28 21:38:26 +00:00
|
|
|
|
2024-01-04 21:09:49 +00:00
|
|
|
- name: "Write vault configuration to file" # noqa: run-once[task] no-handler
|
2023-12-30 14:54:37 +00:00
|
|
|
ansible.builtin.copy:
|
|
|
|
content: "{{ _vault_init_secret.state | to_nice_yaml}}"
|
2024-01-04 21:09:49 +00:00
|
|
|
dest: "{{ sub_configuration_directories.vault_servers }}/vault_config"
|
2023-12-30 14:54:37 +00:00
|
|
|
mode: '0644'
|
|
|
|
when: _vault_init_secret.changed
|
|
|
|
run_once: true
|
|
|
|
delegate_to: localhost
|
2023-12-28 22:10:17 +00:00
|
|
|
|
2023-12-30 14:54:37 +00:00
|
|
|
- name: "Load vault cluster variables necessary for unseal operation"
|
|
|
|
ansible.builtin.include_vars:
|
2024-01-04 21:09:49 +00:00
|
|
|
file: "{{ sub_configuration_directories.vault_servers }}/vault_config"
|
2023-12-30 14:54:37 +00:00
|
|
|
name: _vault_cluster_config
|
2023-12-29 11:51:00 +00:00
|
|
|
|
2024-01-04 21:09:49 +00:00
|
|
|
- name: "Unseal the bootstrap node" # noqa: run-once[task] no-handler
|
2023-12-30 14:54:37 +00:00
|
|
|
ednxzu.hashistack.vault_unseal:
|
2023-12-31 09:26:25 +00:00
|
|
|
api_url: "{{ hashi_vault_configuration['api_addr'] }}"
|
2023-12-30 14:54:37 +00:00
|
|
|
key_shares: "{{ _vault_cluster_config['keys'] }}"
|
|
|
|
run_once: true
|
|
|
|
delegate_to: "{{ groups['vault_servers'] | first }}"
|
|
|
|
when: _vault_init_secret.changed
|
2024-01-24 22:54:58 +00:00
|
|
|
register: _vault_unseal_secret
|
|
|
|
|
2023-12-30 14:54:37 +00:00
|
|
|
- name: "Unseal all vault nodes"
|
|
|
|
ednxzu.hashistack.vault_unseal:
|
2023-12-31 09:26:25 +00:00
|
|
|
api_url: "{{ hashi_vault_configuration['api_addr'] }}"
|
2023-12-30 14:54:37 +00:00
|
|
|
key_shares: "{{ _vault_cluster_config['keys'] }}"
|
|
|
|
retries: 5
|
|
|
|
delay: 5
|
|
|
|
register: _unseal_status
|