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.

91 lines
3.5 KiB

  1. ---
  2. - include: sync_kube_master_certs.yml
  3. when: inventory_hostname in groups['kube-master']
  4. tags: k8s-secrets
  5. - include: sync_kube_node_certs.yml
  6. when: inventory_hostname in groups['k8s-cluster']
  7. tags: k8s-secrets
  8. - name: gen_certs_vault | Read in the local credentials
  9. command: cat /etc/vault/roles/kube/userpass
  10. register: kube_vault_creds_cat
  11. when: inventory_hostname == groups['k8s-cluster']|first
  12. - name: gen_certs_vault | Set facts for read Vault Creds
  13. set_fact:
  14. kube_vault_creds: "{{ hostvars[groups['k8s-cluster']|first]['kube_vault_creds_cat']['stdout'] | from_json }}"
  15. when: inventory_hostname == groups['k8s-cluster']|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/{{ kube_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: "{{ kube_vault_creds.password }}"
  26. register: kube_vault_login_result
  27. when: inventory_hostname == groups['k8s-cluster']|first
  28. - name: gen_certs_vault | Set fact for Vault API token
  29. set_fact:
  30. kube_vault_headers:
  31. Accept: application/json
  32. Content-Type: application/json
  33. X-Vault-Token: "{{ hostvars[groups['k8s-cluster']|first]['kube_vault_login_result']['json']['auth']['client_token'] }}"
  34. # Issue certs to kube-master nodes
  35. - include: ../../../vault/tasks/shared/issue_cert.yml
  36. vars:
  37. issue_cert_copy_ca: "{{ item == kube_master_certs_needed|first }}"
  38. issue_cert_file_group: "{{ kube_cert_group }}"
  39. issue_cert_file_owner: kube
  40. issue_cert_headers: "{{ kube_vault_headers }}"
  41. issue_cert_hosts: "{{ groups['kube-master'] }}"
  42. issue_cert_path: "{{ item }}"
  43. issue_cert_role: kube
  44. issue_cert_url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}"
  45. with_items: "{{ kube_master_certs_needed|d([]) }}"
  46. when: inventory_hostname in groups['kube-master']
  47. - include: ../../../vault/tasks/shared/issue_cert.yml
  48. vars:
  49. issue_cert_alt_names: >-
  50. {{
  51. groups['kube-master'] +
  52. ['kubernetes.default.svc.cluster.local', 'kubernetes.default.svc', 'kubernetes.default', 'kubernetes'] +
  53. ['localhost']
  54. }}
  55. issue_cert_file_group: "{{ kube_cert_group }}"
  56. issue_cert_file_owner: kube
  57. issue_cert_headers: "{{ kube_vault_headers }}"
  58. issue_cert_hosts: "{{ groups['kube-master'] }}"
  59. issue_cert_ip_sans: >-
  60. [
  61. {%- for host in groups['kube-master'] -%}
  62. "{{ hostvars[host]['ansible_default_ipv4']['address'] }}",
  63. {%- endfor -%}
  64. "127.0.0.1","::1","{{ kube_apiserver_ip }}"
  65. ]
  66. issue_cert_path: "{{ item }}"
  67. issue_cert_role: kube
  68. issue_cert_url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}"
  69. with_items: "{{ kube_api_certs_needed|d([]) }}"
  70. when: inventory_hostname in groups['kube-master']
  71. # Issue node certs to k8s-cluster nodes
  72. - include: ../../../vault/tasks/shared/issue_cert.yml
  73. vars:
  74. issue_cert_copy_ca: "{{ item == kube_node_certs_needed|first }}"
  75. issue_cert_file_group: "{{ kube_cert_group }}"
  76. issue_cert_file_owner: kube
  77. issue_cert_headers: "{{ kube_vault_headers }}"
  78. issue_cert_hosts: "{{ groups['k8s-cluster'] }}"
  79. issue_cert_path: "{{ item }}"
  80. issue_cert_role: kube
  81. issue_cert_url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}"
  82. with_items: "{{ kube_node_certs_needed|d([]) }}"
  83. when: inventory_hostname in groups['k8s-cluster']