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.

87 lines
3.0 KiB

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