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. - name: bootstrap/start_vault_temp | Ensure vault-temp isn't already running
  3. shell: if docker rm -f {{ vault_temp_container_name }} 2>&1 1>/dev/null;then echo true;else echo false;fi
  4. register: vault_temp_stop_check
  5. changed_when: "'true' in vault_temp_stop_check.stdout"
  6. - name: bootstrap/start_vault_temp | Start single node Vault with file backend
  7. command: >
  8. docker run -d --cap-add=IPC_LOCK --name {{ vault_temp_container_name }}
  9. -p {{ vault_port }}:{{ vault_port }}
  10. -e 'VAULT_LOCAL_CONFIG={{ vault_temp_config|to_json }}'
  11. -v /etc/vault:/etc/vault
  12. {{ vault_image_repo }}:{{ vault_version }} server
  13. # FIXME(mattymo): Crashes on first start with aufs docker storage. See hashicorp/docker-vault#19
  14. - name: bootstrap/start_vault_temp | Start again single node Vault with file backend
  15. command: docker start {{ vault_temp_container_name }}
  16. - name: bootstrap/start_vault_temp | Initialize vault-temp
  17. uri:
  18. url: "http://localhost:{{ vault_port }}/v1/sys/init"
  19. headers: "{{ vault_client_headers }}"
  20. method: PUT
  21. body_format: json
  22. body:
  23. secret_shares: 1
  24. secret_threshold: 1
  25. until: "vault_temp_init|succeeded"
  26. retries: 4
  27. delay: "{{ retry_stagger | random + 3 }}"
  28. register: vault_temp_init
  29. # NOTE: vault_headers and vault_url are used by subsequent issue calls
  30. - name: bootstrap/start_vault_temp | Set needed vault facts
  31. set_fact:
  32. vault_leader_url: "http://{{ inventory_hostname }}:{{ vault_port }}"
  33. vault_temp_unseal_keys: "{{ vault_temp_init.json['keys'] }}"
  34. vault_temp_root_token: "{{ vault_temp_init.json.root_token }}"
  35. vault_headers: "{{ vault_client_headers|combine({'X-Vault-Token': vault_temp_init.json.root_token}) }}"
  36. - name: bootstrap/start_vault_temp | Unseal vault-temp
  37. uri:
  38. url: "http://localhost:{{ vault_port }}/v1/sys/unseal"
  39. headers: "{{ vault_headers }}"
  40. method: POST
  41. body_format: json
  42. body:
  43. key: "{{ item }}"
  44. with_items: "{{ vault_temp_unseal_keys|default([]) }}"