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.

48 lines
2.0 KiB

  1. ---
  2. - include_tasks: ../shared/sync_file.yml
  3. vars:
  4. sync_file: "{{ item }}"
  5. sync_file_dir: "{{ vault_secrets_dir }}"
  6. sync_file_hosts: "{{ groups.vault }}"
  7. with_items:
  8. - root_token
  9. - unseal_keys
  10. - name: bootstrap/sync_secrets | Set fact based on sync_file_results
  11. set_fact:
  12. vault_secrets_available: "{{ vault_secrets_available|default(true) and not item.no_srcs }}"
  13. with_items: "{{ sync_file_results|d([]) }}"
  14. - name: bootstrap/sync_secrets | Reset sync_file_results to avoid variable bleed
  15. set_fact:
  16. sync_file_results: []
  17. - name: bootstrap/sync_secrets | Print out warning message if secrets are not available and vault is initialized
  18. pause:
  19. prompt: >
  20. Vault orchestration may not be able to proceed. The Vault cluster is initialzed, but
  21. 'root_token' or 'unseal_keys' were not found in {{ vault_secrets_dir }}. These are
  22. needed for many vault orchestration steps.
  23. when: vault_cluster_is_initialized and not vault_secrets_available
  24. - name: bootstrap/sync_secrets | Cat root_token from a vault host
  25. command: "cat {{ vault_secrets_dir }}/root_token"
  26. register: vault_root_token_cat
  27. when: vault_secrets_available and inventory_hostname == groups.vault|first
  28. - name: bootstrap/sync_secrets | Cat unseal_keys from a vault host
  29. command: "cat {{ vault_secrets_dir }}/unseal_keys"
  30. register: vault_unseal_keys_cat
  31. when: vault_secrets_available and inventory_hostname == groups.vault|first
  32. - name: bootstrap/sync_secrets | Set needed facts for Vault API interaction when Vault is already running
  33. set_fact:
  34. vault_root_token: "{{ hostvars[groups.vault|first]['vault_root_token_cat']['stdout'] }}"
  35. vault_unseal_keys: "{{ hostvars[groups.vault|first]['vault_unseal_keys_cat']['stdout_lines'] }}"
  36. when: vault_secrets_available
  37. - name: bootstrap/sync_secrets | Update vault_headers if we have the root_token
  38. set_fact:
  39. vault_headers: "{{ vault_client_headers | combine({'X-Vault-Token': vault_root_token}) }}"
  40. when: vault_secrets_available