You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
2.0 KiB

  1. ---
  2. # Stop temporary Vault if it's running (can linger if playbook fails out)
  3. - name: stop vault-temp container
  4. shell: docker stop {{ vault_temp_container_name }} || rkt stop {{ vault_temp_container_name }}
  5. failed_when: false
  6. register: vault_temp_stop
  7. changed_when: vault_temp_stop|succeeded
  8. # Check if vault is reachable on the localhost
  9. - name: check_vault | Attempt to pull local https Vault health
  10. command: /bin/true
  11. notify: wait for vault up nowait
  12. - meta: flush_handlers
  13. - name: check_vault | Set facts about local Vault health
  14. set_fact:
  15. vault_is_running: "{{ vault_health_check.get('status', '-1') in vault_successful_http_codes }}"
  16. - name: check_vault | Set facts about local Vault health
  17. set_fact:
  18. vault_is_initialized: "{{ vault_health_check.get('json', {}).get('initialized', false) }}"
  19. vault_is_sealed: "{{ vault_health_check.get('json', {}).get('sealed', true) }}"
  20. # vault_in_standby: "{{ vault_health_check.get('json', {}).get('standby', true) }}"
  21. # vault_run_version: "{{ vault_local_service_health.get('json', {}).get('version', '') }}"
  22. - name: check_vault | Check is vault is initialized in etcd if vault is not running
  23. command: |-
  24. curl \
  25. --cacert {{ etcd_cert_dir }}/ca.pem \
  26. --cert {{ etcd_cert_dir}}/node-{{ inventory_hostname }}.pem \
  27. --key {{ etcd_cert_dir }}/node-{{ inventory_hostname }}-key.pem \
  28. -X POST -d '{"key": "{{ "/vault/core/seal-config" | b64encode }}"}' \
  29. {{ etcd_access_addresses.split(',') | first }}/v3alpha/kv/range
  30. register: vault_etcd_exists
  31. retries: 4
  32. delay: "{{ retry_stagger | random + 3 }}"
  33. run_once: true
  34. when: not vault_is_running and vault_etcd_available
  35. changed_when: false
  36. - name: check_vault | Set fact about the Vault cluster's initialization state
  37. set_fact:
  38. vault_cluster_is_initialized: >-
  39. {{ vault_is_initialized or
  40. hostvars[item]['vault_is_initialized'] or
  41. 'Key not found' not in vault_etcd_exists.stdout|default('Key not found') }}
  42. with_items: "{{ groups.vault }}"
  43. run_once: true