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.

203 lines
6.2 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. register: result
  46. until: result is succeeded
  47. retries: 10
  48. delay: 6
  49. with_items: "{{ psp_manifests.results }}"
  50. when:
  51. - inventory_hostname == groups['kube-master'][0]
  52. - not item is skipped
  53. loop_control:
  54. label: "{{ item.item.file }}"
  55. - name: Kubernetes Apps | Add ClusterRoleBinding to admit nodes
  56. template:
  57. src: "node-crb.yml.j2"
  58. dest: "{{ kube_config_dir }}/node-crb.yml"
  59. register: node_crb_manifest
  60. when:
  61. - rbac_enabled
  62. - inventory_hostname == groups['kube-master'][0]
  63. - name: Apply workaround to allow all nodes with cert O=system:nodes to register
  64. kube:
  65. name: "kubespray:system:node"
  66. kubectl: "{{bin_dir}}/kubectl"
  67. resource: "clusterrolebinding"
  68. filename: "{{ kube_config_dir }}/node-crb.yml"
  69. state: latest
  70. register: result
  71. until: result is succeeded
  72. retries: 10
  73. delay: 6
  74. when:
  75. - rbac_enabled
  76. - node_crb_manifest.changed
  77. - inventory_hostname == groups['kube-master'][0]
  78. - name: Kubernetes Apps | Add webhook ClusterRole that grants access to proxy, stats, log, spec, and metrics on a kubelet
  79. template:
  80. src: "node-webhook-cr.yml.j2"
  81. dest: "{{ kube_config_dir }}/node-webhook-cr.yml"
  82. register: node_webhook_cr_manifest
  83. when:
  84. - rbac_enabled
  85. - kubelet_authorization_mode_webhook
  86. - inventory_hostname == groups['kube-master'][0]
  87. tags: node-webhook
  88. - name: Apply webhook ClusterRole
  89. kube:
  90. name: "system:node-webhook"
  91. kubectl: "{{bin_dir}}/kubectl"
  92. resource: "clusterrole"
  93. filename: "{{ kube_config_dir }}/node-webhook-cr.yml"
  94. state: latest
  95. when:
  96. - rbac_enabled
  97. - kubelet_authorization_mode_webhook
  98. - node_webhook_cr_manifest.changed
  99. - inventory_hostname == groups['kube-master'][0]
  100. tags: node-webhook
  101. - name: Kubernetes Apps | Add ClusterRoleBinding for system:nodes to webhook ClusterRole
  102. template:
  103. src: "node-webhook-crb.yml.j2"
  104. dest: "{{ kube_config_dir }}/node-webhook-crb.yml"
  105. register: node_webhook_crb_manifest
  106. when:
  107. - rbac_enabled
  108. - kubelet_authorization_mode_webhook
  109. - inventory_hostname == groups['kube-master'][0]
  110. tags: node-webhook
  111. - name: Grant system:nodes the webhook ClusterRole
  112. kube:
  113. name: "system:node-webhook"
  114. kubectl: "{{bin_dir}}/kubectl"
  115. resource: "clusterrolebinding"
  116. filename: "{{ kube_config_dir }}/node-webhook-crb.yml"
  117. state: latest
  118. when:
  119. - rbac_enabled
  120. - kubelet_authorization_mode_webhook
  121. - node_webhook_crb_manifest.changed
  122. - inventory_hostname == groups['kube-master'][0]
  123. tags: node-webhook
  124. - name: Check if vsphere-cloud-provider ClusterRole exists
  125. command: "{{ bin_dir }}/kubectl get clusterroles system:vsphere-cloud-provider"
  126. register: vsphere_cloud_provider
  127. ignore_errors: true
  128. when:
  129. - rbac_enabled
  130. - cloud_provider is defined
  131. - cloud_provider == 'vsphere'
  132. - kube_version is version('v1.9.0', '>=')
  133. - kube_version is version('v1.9.3', '<=')
  134. - inventory_hostname == groups['kube-master'][0]
  135. tags: vsphere
  136. - name: Write vsphere-cloud-provider ClusterRole manifest
  137. template:
  138. src: "vsphere-rbac.yml.j2"
  139. dest: "{{ kube_config_dir }}/vsphere-rbac.yml"
  140. register: vsphere_rbac_manifest
  141. when:
  142. - rbac_enabled
  143. - cloud_provider is defined
  144. - cloud_provider == 'vsphere'
  145. - vsphere_cloud_provider.rc is defined
  146. - vsphere_cloud_provider.rc != 0
  147. - kube_version is version('v1.9.0', '>=')
  148. - kube_version is version('v1.9.3', '<=')
  149. - inventory_hostname == groups['kube-master'][0]
  150. tags: vsphere
  151. - name: Apply vsphere-cloud-provider ClusterRole
  152. kube:
  153. name: "system:vsphere-cloud-provider"
  154. kubectl: "{{bin_dir}}/kubectl"
  155. resource: "clusterrolebinding"
  156. filename: "{{ kube_config_dir }}/vsphere-rbac.yml"
  157. state: latest
  158. when:
  159. - rbac_enabled
  160. - cloud_provider is defined
  161. - cloud_provider == 'vsphere'
  162. - vsphere_cloud_provider.rc is defined
  163. - vsphere_cloud_provider.rc != 0
  164. - kube_version is version('v1.9.0', '>=')
  165. - kube_version is version('v1.9.3', '<=')
  166. - inventory_hostname == groups['kube-master'][0]
  167. tags: vsphere
  168. - include_tasks: oci.yml
  169. tags: oci
  170. when:
  171. - cloud_provider is defined
  172. - cloud_provider == 'oci'
  173. - name: PriorityClass | Copy k8s-cluster-critical-pc.yml file
  174. copy: src=k8s-cluster-critical-pc.yml dest={{ kube_config_dir }}/k8s-cluster-critical-pc.yml
  175. when:
  176. - kube_version is version('v1.11.1', '>=')
  177. - inventory_hostname == groups['kube-master']|last
  178. - name: PriorityClass | Create k8s-cluster-critical
  179. kube:
  180. name: k8s-cluster-critical
  181. kubectl: "{{bin_dir}}/kubectl"
  182. resource: "PriorityClass"
  183. filename: "{{ kube_config_dir }}/k8s-cluster-critical-pc.yml"
  184. state: latest
  185. when:
  186. - kube_version is version('v1.11.1', '>=')
  187. - inventory_hostname == groups['kube-master']|last