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.

77 lines
2.8 KiB

  1. ---
  2. - name: gen_certs_vault | Read in the local credentials
  3. command: cat /etc/vault/roles/etcd/userpass
  4. register: etcd_vault_creds_cat
  5. when: inventory_hostname == groups.etcd|first
  6. - name: gen_certs_vault | Set facts for read Vault Creds
  7. set_fact:
  8. etcd_vault_creds: "{{ hostvars[groups.etcd|first]['etcd_vault_creds_cat']['stdout']|from_json }}"
  9. when: inventory_hostname == groups.etcd|first
  10. - name: gen_certs_vault | Log into Vault and obtain an token
  11. uri:
  12. url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}/v1/auth/userpass/login/{{ etcd_vault_creds.username }}"
  13. headers:
  14. Accept: application/json
  15. Content-Type: application/json
  16. method: POST
  17. body_format: json
  18. body:
  19. password: "{{ etcd_vault_creds.password }}"
  20. register: etcd_vault_login_result
  21. when: inventory_hostname == groups.etcd|first
  22. - name: gen_certs_vault | Set fact for Vault API token
  23. set_fact:
  24. etcd_vault_headers:
  25. Accept: application/json
  26. Content-Type: application/json
  27. X-Vault-Token: "{{ hostvars[groups.etcd|first]['etcd_vault_login_result']['json']['auth']['client_token'] }}"
  28. # Issue master certs to Etcd nodes
  29. - include: ../../vault/tasks/shared/issue_cert.yml
  30. vars:
  31. issue_cert_alt_names: "{{ groups.etcd + ['localhost'] }}"
  32. issue_cert_copy_ca: "{{ item == etcd_master_certs_needed|first }}"
  33. issue_cert_file_group: "{{ etcd_cert_group }}"
  34. issue_cert_file_owner: kube
  35. issue_cert_headers: "{{ etcd_vault_headers }}"
  36. issue_cert_hosts: "{{ groups.etcd }}"
  37. issue_cert_ip_sans: >-
  38. [
  39. {%- for host in groups.etcd -%}
  40. "{{ hostvars[host]['ansible_default_ipv4']['address'] }}",
  41. {%- endfor -%}
  42. "127.0.0.1","::1"
  43. ]
  44. issue_cert_path: "{{ item }}"
  45. issue_cert_role: etcd
  46. issue_cert_url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}"
  47. with_items: "{{ etcd_master_certs_needed|d([]) }}"
  48. when: inventory_hostname in groups.etcd
  49. notify: set etcd_secret_changed
  50. # Issue node certs to everyone else
  51. - include: ../../vault/tasks/shared/issue_cert.yml
  52. vars:
  53. issue_cert_alt_names: "{{ etcd_node_cert_hosts }}"
  54. issue_cert_copy_ca: "{{ item == etcd_node_certs_needed|first }}"
  55. issue_cert_file_group: "{{ etcd_cert_group }}"
  56. issue_cert_file_owner: kube
  57. issue_cert_headers: "{{ etcd_vault_headers }}"
  58. issue_cert_hosts: "{{ etcd_node_cert_hosts }}"
  59. issue_cert_ip_sans: >-
  60. [
  61. {%- for host in etcd_node_cert_hosts -%}
  62. "{{ hostvars[host]['ansible_default_ipv4']['address'] }}",
  63. {%- endfor -%}
  64. "127.0.0.1","::1"
  65. ]
  66. issue_cert_path: "{{ item }}"
  67. issue_cert_role: etcd
  68. issue_cert_url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}"
  69. with_items: "{{ etcd_node_certs_needed|d([]) }}"
  70. when: inventory_hostname in etcd_node_cert_hosts
  71. notify: set etcd_secret_changed