2024-04-01 21:59:48 +00:00
|
|
|
---
|
2024-03-13 22:27:12 +00:00
|
|
|
- name: "Vault"
|
|
|
|
block:
|
2024-05-07 17:23:48 +00:00
|
|
|
- name: "Create consul token for service registration"
|
|
|
|
when:
|
2024-07-11 21:27:44 +00:00
|
|
|
- vault_init_cluster
|
2024-05-07 17:23:48 +00:00
|
|
|
- enable_consul
|
|
|
|
- vault_enable_service_registration
|
|
|
|
vars:
|
|
|
|
_consul_vault_sr_host: "{{ hostvars[groups['consul_servers'][0]].api_interface_address }}"
|
|
|
|
_consul_vault_sr_port: "{{ hostvars[groups['consul_servers'][0]].consul_api_port[hostvars[groups['consul_servers'][0]].consul_api_scheme] }}"
|
|
|
|
_consul_vault_sr_scheme: "{{ hostvars[groups['consul_servers'][0]].consul_api_scheme }}"
|
|
|
|
block:
|
|
|
|
- name: "Create consul vault policy"
|
|
|
|
community.general.consul_policy:
|
|
|
|
token: "{{ _credentials.consul.root_token.secret_id }}"
|
|
|
|
host: "{{ _consul_vault_sr_host }}"
|
|
|
|
port: "{{ _consul_vault_sr_port }}"
|
|
|
|
scheme: "{{ _consul_vault_sr_scheme }}"
|
|
|
|
validate_certs: false
|
|
|
|
state: present
|
|
|
|
name: vault-policy
|
|
|
|
rules: "{{ vault_service_registration_policy }}"
|
|
|
|
register: _consul_vault_policy
|
|
|
|
|
|
|
|
- name: "Create consul vault token"
|
|
|
|
community.general.consul_token:
|
|
|
|
token: "{{ _credentials.consul.root_token.secret_id }}"
|
|
|
|
host: "{{ _consul_vault_sr_host }}"
|
|
|
|
port: "{{ _consul_vault_sr_port }}"
|
|
|
|
scheme: "{{ _consul_vault_sr_scheme }}"
|
|
|
|
validate_certs: false
|
|
|
|
accessor_id: "{{ _credentials.consul.tokens.vault.accessor_id }}"
|
|
|
|
secret_id: "{{ _credentials.consul.tokens.vault.secret_id }}"
|
|
|
|
policies:
|
|
|
|
- id: "{{ _consul_vault_policy.policy.ID }}"
|
|
|
|
state: present
|
|
|
|
when: _consul_vault_policy.changed
|
|
|
|
|
2024-05-16 15:29:41 +00:00
|
|
|
- name: "Include ednz_cloud.hashicorp_consul"
|
2024-03-13 22:27:12 +00:00
|
|
|
ansible.builtin.include_role:
|
2024-05-16 15:29:41 +00:00
|
|
|
name: ednz_cloud.hashicorp_vault
|
2024-03-13 22:27:12 +00:00
|
|
|
|
|
|
|
- name: "Initialize vault cluster" # noqa: run-once[task]
|
|
|
|
ednz_cloud.hashistack.vault_init:
|
2024-06-19 22:32:33 +00:00
|
|
|
api_url: "{{ hashicorp_vault_configuration['api_addr'] }}"
|
2024-04-06 21:47:35 +00:00
|
|
|
tls_verify: "{{ vault_tls_verify }}"
|
2024-03-13 22:27:12 +00:00
|
|
|
key_shares: "{{ vault_seal_configuration['key_shares'] }}"
|
|
|
|
key_threshold: "{{ vault_seal_configuration['key_threshold'] }}"
|
|
|
|
retries: 5
|
|
|
|
delay: 5
|
|
|
|
register: _vault_init_secret
|
|
|
|
until: not _vault_init_secret.failed
|
2024-07-11 21:27:44 +00:00
|
|
|
when: vault_init_cluster
|
2024-03-13 22:27:12 +00:00
|
|
|
|
|
|
|
- name: "Write vault configuration to file" # noqa: run-once[task] no-handler
|
|
|
|
ansible.builtin.copy:
|
2024-05-03 20:23:47 +00:00
|
|
|
content: "{{ _vault_init_secret.state | to_nice_yaml(indent=2) }}"
|
|
|
|
dest: "{{ sub_configuration_directories.secrets }}/vault.yml"
|
2024-03-13 22:27:12 +00:00
|
|
|
owner: "{{ lookup('env', 'USER') }}"
|
|
|
|
group: "{{ lookup('env', 'USER') }}"
|
|
|
|
mode: "0644"
|
2024-07-11 21:27:44 +00:00
|
|
|
when:
|
|
|
|
- vault_init_cluster
|
|
|
|
- _vault_init_secret.changed
|
2024-03-13 22:27:12 +00:00
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
- name: "Load vault cluster variables necessary for unseal operation"
|
2024-05-03 20:23:47 +00:00
|
|
|
ansible.builtin.import_tasks:
|
|
|
|
file: ../misc/load_credentials_vars.yml
|
2024-03-13 22:27:12 +00:00
|
|
|
|
|
|
|
- name: "Unseal the bootstrap node" # noqa: run-once[task] no-handler
|
|
|
|
ednz_cloud.hashistack.vault_unseal:
|
2024-06-19 22:32:33 +00:00
|
|
|
api_url: "{{ hashicorp_vault_configuration['api_addr'] }}"
|
2024-04-06 21:47:35 +00:00
|
|
|
tls_verify: "{{ vault_tls_verify }}"
|
2024-05-03 20:23:47 +00:00
|
|
|
key_shares: "{{ _credentials.vault['keys'] }}"
|
2024-07-11 21:27:44 +00:00
|
|
|
when:
|
|
|
|
- vault_init_cluster
|
|
|
|
- _vault_init_secret.changed
|
2024-03-13 22:27:12 +00:00
|
|
|
register: _vault_unseal_secret
|
|
|
|
|
|
|
|
- name: "Unseal all vault nodes"
|
|
|
|
ednz_cloud.hashistack.vault_unseal:
|
2024-06-19 22:32:33 +00:00
|
|
|
api_url: "{{ hashicorp_vault_configuration['api_addr'] }}"
|
2024-04-06 21:47:35 +00:00
|
|
|
tls_verify: "{{ vault_tls_verify }}"
|
2024-05-03 20:23:47 +00:00
|
|
|
key_shares: "{{ _credentials.vault['keys'] }}"
|
2024-03-13 22:27:12 +00:00
|
|
|
retries: 5
|
|
|
|
delay: 5
|
2024-04-01 21:59:48 +00:00
|
|
|
until: _unseal_status.changed or not _unseal_status.failed
|
2024-03-13 22:27:12 +00:00
|
|
|
register: _unseal_status
|