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.

84 lines
3.3 KiB

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