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.

52 lines
2.0 KiB

  1. ---
  2. - name: cluster/init | Initialize Vault
  3. uri:
  4. url: "https://{{ groups.vault|first }}:{{ vault_port }}/v1/sys/init"
  5. headers: "{{ vault_client_headers }}"
  6. method: POST
  7. body_format: json
  8. body:
  9. secret_shares: "{{ vault_secret_shares }}"
  10. secret_threshold: "{{ vault_secret_threshold }}"
  11. validate_certs: false
  12. register: vault_init_result
  13. when: not vault_cluster_is_initialized and inventory_hostname == groups.vault|first
  14. - name: cluster/init | Set facts on the results of the initialization
  15. set_fact:
  16. vault_unseal_keys: "{{ vault_init_result.json['keys'] }}"
  17. vault_root_token: "{{ vault_init_result.json.root_token }}"
  18. vault_headers: "{{ vault_client_headers|combine({'X-Vault-Token': vault_init_result.json.root_token}) }}"
  19. when: not vault_cluster_is_initialized and inventory_hostname == groups.vault|first
  20. - name: cluster/init | Ensure all hosts have these facts
  21. set_fact:
  22. vault_unseal_keys: "{{ hostvars[groups.vault|first]['vault_unseal_keys'] }}"
  23. vault_root_token: "{{ hostvars[groups.vault|first]['vault_root_token'] }}"
  24. when: not vault_cluster_is_initialized and inventory_hostname != groups.vault|first
  25. - name: cluster/init | Ensure the vault_secrets_dir exists
  26. file:
  27. mode: 0750
  28. path: "{{ vault_secrets_dir }}"
  29. state: directory
  30. - name: cluster/init | Ensure all in groups.vault have the unseal_keys locally
  31. copy:
  32. content: "{{ vault_unseal_keys|join('\n') }}"
  33. dest: "{{ vault_secrets_dir }}/unseal_keys"
  34. mode: 0640
  35. when: not vault_cluster_is_initialized
  36. - name: cluster/init | Ensure all in groups.vault have the root_token locally
  37. copy:
  38. content: "{{ vault_root_token }}"
  39. dest: "{{ vault_secrets_dir }}/root_token"
  40. mode: 0640
  41. when: not vault_cluster_is_initialized
  42. - name: cluster/init | Ensure vault_headers and vault statuses are updated
  43. set_fact:
  44. vault_headers: "{{ vault_client_headers | combine({'X-Vault-Token': vault_root_token})}}"
  45. vault_cluster_is_initialized: true