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.

95 lines
3.9 KiB

  1. ---
  2. - import_tasks: sync_kube_master_certs.yml
  3. when: inventory_hostname in groups['kube-master']
  4. - import_tasks: sync_kube_node_certs.yml
  5. when: inventory_hostname in groups['k8s-cluster']
  6. # Issue admin certs to kube-master hosts
  7. - include_tasks: ../../../vault/tasks/shared/issue_cert.yml
  8. vars:
  9. issue_cert_common_name: "admin"
  10. issue_cert_copy_ca: "{{ item == kube_admin_certs_needed|first }}"
  11. issue_cert_file_group: "{{ kube_cert_group }}"
  12. issue_cert_file_owner: kube
  13. issue_cert_hosts: "{{ groups['kube-master'] }}"
  14. issue_cert_path: "{{ item }}"
  15. issue_cert_role: kube-master
  16. issue_cert_url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}"
  17. issue_cert_mount_path: "{{ kube_vault_mount_path }}"
  18. with_items: "{{ kube_admin_certs_needed|d([]) }}"
  19. when: inventory_hostname in groups['kube-master']
  20. - name: gen_certs_vault | Set fact about certificate alt names
  21. set_fact:
  22. kube_cert_alt_names: >-
  23. {{
  24. groups['kube-master'] +
  25. ['kubernetes.default.svc.cluster.local', 'kubernetes.default.svc', 'kubernetes.default', 'kubernetes'] +
  26. ['localhost']
  27. }}
  28. run_once: true
  29. - name: gen_certs_vault | Add external load balancer domain name to certificate alt names
  30. set_fact:
  31. kube_cert_alt_names: "{{ kube_cert_alt_names + [apiserver_loadbalancer_domain_name] }}"
  32. when: loadbalancer_apiserver is defined
  33. run_once: true
  34. # Issue master components certs to kube-master hosts
  35. - include_tasks: ../../../vault/tasks/shared/issue_cert.yml
  36. vars:
  37. issue_cert_common_name: "kubernetes"
  38. issue_cert_alt_names: "{{ kube_cert_alt_names }}"
  39. issue_cert_file_group: "{{ kube_cert_group }}"
  40. issue_cert_file_owner: kube
  41. issue_cert_hosts: "{{ groups['kube-master'] }}"
  42. issue_cert_ip_sans: >-
  43. [
  44. {%- for host in groups['kube-master'] -%}
  45. "{{ hostvars[host]['ansible_default_ipv4']['address'] }}",
  46. {%- if hostvars[host]['ip'] is defined -%}
  47. "{{ hostvars[host]['ip'] }}",
  48. {%- endif -%}
  49. {%- endfor -%}
  50. "127.0.0.1","::1","{{ kube_apiserver_ip }}"
  51. ]
  52. issue_cert_path: "{{ item }}"
  53. issue_cert_role: kube-master
  54. issue_cert_url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}"
  55. issue_cert_mount_path: "{{ kube_vault_mount_path }}"
  56. with_items: "{{ kube_master_components_certs_needed|d([]) }}"
  57. when: inventory_hostname in groups['kube-master']
  58. notify: set secret_changed
  59. # Issue node certs to k8s-cluster nodes
  60. - include_tasks: ../../../vault/tasks/shared/issue_cert.yml
  61. vars:
  62. # Need to strip out the 'node-' prefix from the cert name so it can be used
  63. # with the node authorization plugin ( CN matches kubelet node name )
  64. issue_cert_common_name: "system:node:{{ item.rsplit('/', 1)[1].rsplit('.', 1)[0] | regex_replace('^node-', '') }}"
  65. issue_cert_copy_ca: "{{ item == kube_node_certs_needed|first }}"
  66. issue_cert_file_group: "{{ kube_cert_group }}"
  67. issue_cert_file_owner: kube
  68. issue_cert_hosts: "{{ groups['k8s-cluster'] }}"
  69. issue_cert_path: "{{ item }}"
  70. issue_cert_role: kube-node
  71. issue_cert_url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}"
  72. issue_cert_mount_path: "{{ kube_vault_mount_path }}"
  73. with_items: "{{ kube_node_certs_needed|d([]) }}"
  74. when: inventory_hostname in groups['k8s-cluster']
  75. # Issue proxy certs to k8s-cluster nodes
  76. - include_tasks: ../../../vault/tasks/shared/issue_cert.yml
  77. vars:
  78. issue_cert_common_name: "system:kube-proxy"
  79. issue_cert_copy_ca: "{{ item == kube_proxy_certs_needed|first }}"
  80. issue_cert_file_group: "{{ kube_cert_group }}"
  81. issue_cert_file_owner: kube
  82. issue_cert_hosts: "{{ groups['k8s-cluster'] }}"
  83. issue_cert_path: "{{ item }}"
  84. issue_cert_role: kube-proxy
  85. issue_cert_url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}"
  86. issue_cert_mount_path: "{{ kube_vault_mount_path }}"
  87. with_items: "{{ kube_proxy_certs_needed|d([]) }}"
  88. when: inventory_hostname in groups['k8s-cluster']