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.

176 lines
5.4 KiB

  1. ---
  2. - name: Kubernetes Apps | Wait for kube-apiserver
  3. uri:
  4. url: "{{ kube_apiserver_endpoint }}/healthz"
  5. validate_certs: no
  6. client_cert: "{{ kube_apiserver_client_cert }}"
  7. client_key: "{{ kube_apiserver_client_key }}"
  8. register: result
  9. until: result.status == 200
  10. retries: 10
  11. delay: 6
  12. when: inventory_hostname == groups['kube-master'][0]
  13. - name: Kubernetes Apps | Check AppArmor status
  14. command: which apparmor_parser
  15. register: apparmor_status
  16. when:
  17. - podsecuritypolicy_enabled
  18. - inventory_hostname == groups['kube-master'][0]
  19. failed_when: false
  20. - name: Kubernetes Apps | Set apparmor_enabled
  21. set_fact:
  22. apparmor_enabled: "{{ apparmor_status.rc == 0 }}"
  23. when:
  24. - podsecuritypolicy_enabled
  25. - inventory_hostname == groups['kube-master'][0]
  26. - name: Kubernetes Apps | Render templates for PodSecurityPolicy
  27. template:
  28. src: "{{ item.file }}.j2"
  29. dest: "{{ kube_config_dir }}/{{ item.file }}"
  30. register: psp_manifests
  31. with_items:
  32. - {file: psp.yml, type: psp, name: psp}
  33. - {file: psp-cr.yml, type: clusterrole, name: psp-cr}
  34. - {file: psp-crb.yml, type: rolebinding, name: psp-crb}
  35. when:
  36. - podsecuritypolicy_enabled
  37. - inventory_hostname == groups['kube-master'][0]
  38. - name: Kubernetes Apps | Add policies, roles, bindings for PodSecurityPolicy
  39. kube:
  40. name: "{{item.item.name}}"
  41. kubectl: "{{bin_dir}}/kubectl"
  42. resource: "{{item.item.type}}"
  43. filename: "{{kube_config_dir}}/{{item.item.file}}"
  44. state: "latest"
  45. with_items: "{{ psp_manifests.results }}"
  46. when:
  47. - inventory_hostname == groups['kube-master'][0]
  48. - not item|skipped
  49. - name: Kubernetes Apps | Add ClusterRoleBinding to admit nodes
  50. template:
  51. src: "node-crb.yml.j2"
  52. dest: "{{ kube_config_dir }}/node-crb.yml"
  53. register: node_crb_manifest
  54. when:
  55. - rbac_enabled
  56. - inventory_hostname == groups['kube-master'][0]
  57. - name: Apply workaround to allow all nodes with cert O=system:nodes to register
  58. kube:
  59. name: "kubespray:system:node"
  60. kubectl: "{{bin_dir}}/kubectl"
  61. resource: "clusterrolebinding"
  62. filename: "{{ kube_config_dir }}/node-crb.yml"
  63. state: latest
  64. when:
  65. - rbac_enabled
  66. - node_crb_manifest.changed
  67. - inventory_hostname == groups['kube-master'][0]
  68. - name: Kubernetes Apps | Add webhook ClusterRole that grants access to proxy, stats, log, spec, and metrics on a kubelet
  69. template:
  70. src: "node-webhook-cr.yml.j2"
  71. dest: "{{ kube_config_dir }}/node-webhook-cr.yml"
  72. register: node_webhook_cr_manifest
  73. when:
  74. - rbac_enabled
  75. - kubelet_authorization_mode_webhook
  76. - inventory_hostname == groups['kube-master'][0]
  77. tags: node-webhook
  78. - name: Apply webhook ClusterRole
  79. kube:
  80. name: "system:node-webhook"
  81. kubectl: "{{bin_dir}}/kubectl"
  82. resource: "clusterrole"
  83. filename: "{{ kube_config_dir }}/node-webhook-cr.yml"
  84. state: latest
  85. when:
  86. - rbac_enabled
  87. - kubelet_authorization_mode_webhook
  88. - node_webhook_cr_manifest.changed
  89. - inventory_hostname == groups['kube-master'][0]
  90. tags: node-webhook
  91. - name: Kubernetes Apps | Add ClusterRoleBinding for system:nodes to webhook ClusterRole
  92. template:
  93. src: "node-webhook-crb.yml.j2"
  94. dest: "{{ kube_config_dir }}/node-webhook-crb.yml"
  95. register: node_webhook_crb_manifest
  96. when:
  97. - rbac_enabled
  98. - kubelet_authorization_mode_webhook
  99. - inventory_hostname == groups['kube-master'][0]
  100. tags: node-webhook
  101. - name: Grant system:nodes the webhook ClusterRole
  102. kube:
  103. name: "system:node-webhook"
  104. kubectl: "{{bin_dir}}/kubectl"
  105. resource: "clusterrolebinding"
  106. filename: "{{ kube_config_dir }}/node-webhook-crb.yml"
  107. state: latest
  108. when:
  109. - rbac_enabled
  110. - kubelet_authorization_mode_webhook
  111. - node_webhook_crb_manifest.changed
  112. - inventory_hostname == groups['kube-master'][0]
  113. tags: node-webhook
  114. - name: Check if vsphere-cloud-provider ClusterRole exists
  115. command: "{{ bin_dir }}/kubectl get clusterroles system:vsphere-cloud-provider"
  116. register: vsphere_cloud_provider
  117. ignore_errors: true
  118. when:
  119. - rbac_enabled
  120. - cloud_provider is defined
  121. - cloud_provider == 'vsphere'
  122. - kube_version | version_compare('v1.9.0', '>=')
  123. - kube_version | version_compare('v1.9.3', '<=')
  124. - inventory_hostname == groups['kube-master'][0]
  125. tags: vsphere
  126. - name: Write vsphere-cloud-provider ClusterRole manifest
  127. template:
  128. src: "vsphere-rbac.yml.j2"
  129. dest: "{{ kube_config_dir }}/vsphere-rbac.yml"
  130. register: vsphere_rbac_manifest
  131. when:
  132. - rbac_enabled
  133. - cloud_provider is defined
  134. - cloud_provider == 'vsphere'
  135. - vsphere_cloud_provider.rc is defined
  136. - vsphere_cloud_provider.rc != 0
  137. - kube_version | version_compare('v1.9.0', '>=')
  138. - kube_version | version_compare('v1.9.3', '<=')
  139. - inventory_hostname == groups['kube-master'][0]
  140. tags: vsphere
  141. - name: Apply vsphere-cloud-provider ClusterRole
  142. kube:
  143. name: "system:vsphere-cloud-provider"
  144. kubectl: "{{bin_dir}}/kubectl"
  145. resource: "clusterrolebinding"
  146. filename: "{{ kube_config_dir }}/vsphere-rbac.yml"
  147. state: latest
  148. when:
  149. - rbac_enabled
  150. - cloud_provider is defined
  151. - cloud_provider == 'vsphere'
  152. - vsphere_cloud_provider.rc is defined
  153. - vsphere_cloud_provider.rc != 0
  154. - kube_version | version_compare('v1.9.0', '>=')
  155. - kube_version | version_compare('v1.9.3', '<=')
  156. - inventory_hostname == groups['kube-master'][0]
  157. tags: vsphere
  158. - include_tasks: oci.yml
  159. tags: oci
  160. when:
  161. - cloud_provider is defined
  162. - cloud_provider == 'oci'