2017-02-08 21:41:36 +00:00
|
|
|
---
|
|
|
|
# Stop temporary Vault if it's running (can linger if playbook fails out)
|
|
|
|
- name: stop vault-temp container
|
|
|
|
shell: docker stop {{ vault_temp_container_name }} || rkt stop {{ vault_temp_container_name }}
|
|
|
|
failed_when: false
|
|
|
|
register: vault_temp_stop
|
2018-10-16 22:33:30 +00:00
|
|
|
changed_when: vault_temp_stop is succeeded
|
2017-02-08 21:41:36 +00:00
|
|
|
|
|
|
|
# Check if vault is reachable on the localhost
|
|
|
|
- name: check_vault | Attempt to pull local https Vault health
|
2018-05-11 16:11:38 +00:00
|
|
|
command: /bin/true
|
2018-07-05 09:27:45 +00:00
|
|
|
notify:
|
|
|
|
- wait for vault up nowait
|
|
|
|
- set facts about local Vault health
|
2018-05-11 16:11:38 +00:00
|
|
|
|
|
|
|
- meta: flush_handlers
|
|
|
|
|
|
|
|
- name: check_vault | Set facts about local Vault health
|
|
|
|
set_fact:
|
|
|
|
vault_is_running: "{{ vault_health_check.get('status', '-1') in vault_successful_http_codes }}"
|
2017-02-08 21:41:36 +00:00
|
|
|
|
|
|
|
- name: check_vault | Set facts about local Vault health
|
|
|
|
set_fact:
|
2018-05-11 16:11:38 +00:00
|
|
|
vault_is_initialized: "{{ vault_health_check.get('json', {}).get('initialized', false) }}"
|
|
|
|
vault_is_sealed: "{{ vault_health_check.get('json', {}).get('sealed', true) }}"
|
|
|
|
# vault_in_standby: "{{ vault_health_check.get('json', {}).get('standby', true) }}"
|
2017-08-24 09:09:52 +00:00
|
|
|
# vault_run_version: "{{ vault_local_service_health.get('json', {}).get('version', '') }}"
|
2017-02-08 21:41:36 +00:00
|
|
|
|
2018-05-11 16:11:38 +00:00
|
|
|
- name: check_vault | Check is vault is initialized in etcd if vault is not running
|
|
|
|
command: |-
|
|
|
|
curl \
|
|
|
|
--cacert {{ etcd_cert_dir }}/ca.pem \
|
|
|
|
--cert {{ etcd_cert_dir}}/node-{{ inventory_hostname }}.pem \
|
|
|
|
--key {{ etcd_cert_dir }}/node-{{ inventory_hostname }}-key.pem \
|
|
|
|
-X POST -d '{"key": "{{ "/vault/core/seal-config" | b64encode }}"}' \
|
|
|
|
{{ etcd_access_addresses.split(',') | first }}/v3alpha/kv/range
|
|
|
|
register: vault_etcd_exists
|
|
|
|
retries: 4
|
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
|
|
|
run_once: true
|
|
|
|
when: not vault_is_running and vault_etcd_available
|
|
|
|
changed_when: false
|
|
|
|
|
2017-02-08 21:41:36 +00:00
|
|
|
- name: check_vault | Set fact about the Vault cluster's initialization state
|
|
|
|
set_fact:
|
2018-05-11 16:11:38 +00:00
|
|
|
vault_cluster_is_initialized: >-
|
|
|
|
{{ vault_is_initialized or
|
|
|
|
hostvars[item]['vault_is_initialized'] or
|
2018-07-05 09:27:45 +00:00
|
|
|
('value' in vault_etcd_exists.stdout|default('')) }}
|
2017-02-08 21:41:36 +00:00
|
|
|
with_items: "{{ groups.vault }}"
|
2017-07-27 17:46:21 +00:00
|
|
|
run_once: true
|