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.

334 lines
13 KiB

6 years ago
6 years ago
6 years ago
6 years ago
  1. ---
  2. - name: Stop if kube_control_plane group is empty
  3. assert:
  4. that: groups.get( 'kube_control_plane' )
  5. run_once: true
  6. when: not ignore_assert_errors
  7. - name: Stop if etcd group is empty in external etcd mode
  8. assert:
  9. that: groups.get('etcd')
  10. fail_msg: "Group 'etcd' cannot be empty in external etcd mode"
  11. run_once: true
  12. when:
  13. - not ignore_assert_errors
  14. - etcd_deployment_type != "kubeadm"
  15. - name: Stop if non systemd OS type
  16. assert:
  17. that: ansible_service_mgr == "systemd"
  18. when: not ignore_assert_errors
  19. - name: Stop if the os does not support
  20. assert:
  21. that: (allow_unsupported_distribution_setup | default(false)) or ansible_distribution in supported_os_distributions
  22. msg: "{{ ansible_distribution }} is not a known OS"
  23. when: not ignore_assert_errors
  24. - name: Stop if unknown network plugin
  25. assert:
  26. that: kube_network_plugin in ['calico', 'flannel', 'weave', 'cloud', 'cilium', 'cni', 'kube-ovn', 'kube-router', 'macvlan', 'custom_cni']
  27. msg: "{{ kube_network_plugin }} is not supported"
  28. when:
  29. - kube_network_plugin is defined
  30. - not ignore_assert_errors
  31. - name: Stop if unsupported version of Kubernetes
  32. assert:
  33. that: kube_version is version(kube_version_min_required, '>=')
  34. msg: "The current release of Kubespray only support newer version of Kubernetes than {{ kube_version_min_required }} - You are trying to apply {{ kube_version }}"
  35. when: not ignore_assert_errors
  36. # simplify this items-list when https://github.com/ansible/ansible/issues/15753 is resolved
  37. - name: "Stop if known booleans are set as strings (Use JSON format on CLI: -e \"{'key': true }\")"
  38. assert:
  39. that: item.value | type_debug == 'bool'
  40. msg: "{{ item.value }} isn't a bool"
  41. run_once: true
  42. with_items:
  43. - { name: download_run_once, value: "{{ download_run_once }}" }
  44. - { name: deploy_netchecker, value: "{{ deploy_netchecker }}" }
  45. - { name: download_always_pull, value: "{{ download_always_pull }}" }
  46. - { name: helm_enabled, value: "{{ helm_enabled }}" }
  47. - { name: openstack_lbaas_enabled, value: "{{ openstack_lbaas_enabled }}" }
  48. when: not ignore_assert_errors
  49. - name: Stop if even number of etcd hosts
  50. assert:
  51. that: groups.etcd | length is not divisibleby 2
  52. when:
  53. - not ignore_assert_errors
  54. - inventory_hostname in groups.get('etcd',[])
  55. - name: Stop if memory is too small for control plane nodes
  56. assert:
  57. that: ansible_memtotal_mb >= minimal_master_memory_mb
  58. when:
  59. - not ignore_assert_errors
  60. - ('kube_control_plane' in group_names)
  61. - name: Stop if memory is too small for nodes
  62. assert:
  63. that: ansible_memtotal_mb >= minimal_node_memory_mb
  64. when:
  65. - not ignore_assert_errors
  66. - ('kube_node' in group_names)
  67. # This command will fail if cgroups are not enabled on the node.
  68. # For reference: https://kubernetes.io/docs/concepts/architecture/cgroups/#check-cgroup-version
  69. - name: Stop if cgroups are not enabled on nodes
  70. command: stat -fc %T /sys/fs/cgroup/
  71. changed_when: false
  72. when: not ignore_assert_errors
  73. # This assertion will fail on the safe side: One can indeed schedule more pods
  74. # on a node than the CIDR-range has space for when additional pods use the host
  75. # network namespace. It is impossible to ascertain the number of such pods at
  76. # provisioning time, so to establish a guarantee, we factor these out.
  77. # NOTICE: the check blatantly ignores the inet6-case
  78. - name: Guarantee that enough network address space is available for all pods
  79. assert:
  80. that: "{{ (kubelet_max_pods | default(110)) | int <= (2 ** (32 - kube_network_node_prefix | int)) - 2 }}"
  81. msg: "Do not schedule more pods on a node than inet addresses are available."
  82. when:
  83. - not ignore_assert_errors
  84. - ('k8s_cluster' in group_names)
  85. - kube_network_node_prefix is defined
  86. - kube_network_plugin != 'calico'
  87. - name: Stop if ip var does not match local ips
  88. assert:
  89. that: (ip in ansible_all_ipv4_addresses) or (ip in ansible_all_ipv6_addresses)
  90. msg: "IPv4: '{{ ansible_all_ipv4_addresses }}' and IPv6: '{{ ansible_all_ipv6_addresses }}' do not contain '{{ ip }}'"
  91. when:
  92. - not ignore_assert_errors
  93. - ip is defined
  94. - name: Ensure ping package
  95. package:
  96. # noqa: jinja[spacing]
  97. name: >-
  98. {%- if ansible_os_family == 'Debian' -%}
  99. iputils-ping
  100. {%- else -%}
  101. iputils
  102. {%- endif -%}
  103. state: present
  104. when:
  105. - access_ip is defined
  106. - not ignore_assert_errors
  107. - ping_access_ip
  108. - not is_fedora_coreos
  109. - not ansible_os_family in ["Flatcar", "Flatcar Container Linux by Kinvolk"]
  110. - name: Stop if access_ip is not pingable
  111. command: ping -c1 {{ access_ip }}
  112. when:
  113. - access_ip is defined
  114. - not ignore_assert_errors
  115. - ping_access_ip
  116. changed_when: false
  117. - name: Stop if RBAC is not enabled when dashboard is enabled
  118. assert:
  119. that: rbac_enabled
  120. when:
  121. - dashboard_enabled
  122. - not ignore_assert_errors
  123. - name: Stop if RBAC is not enabled when OCI cloud controller is enabled
  124. assert:
  125. that: rbac_enabled
  126. when:
  127. - cloud_provider is defined and cloud_provider == "oci"
  128. - not ignore_assert_errors
  129. - name: Stop if kernel version is too low
  130. assert:
  131. that: ansible_kernel.split('-')[0] is version('4.9.17', '>=')
  132. when:
  133. - kube_network_plugin == 'cilium' or cilium_deploy_additionally | default(false) | bool
  134. - not ignore_assert_errors
  135. - name: Stop if bad hostname
  136. assert:
  137. that: inventory_hostname is match("[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$")
  138. msg: "Hostname must consist of lower case alphanumeric characters, '.' or '-', and must start and end with an alphanumeric character"
  139. when: not ignore_assert_errors
  140. - name: Check cloud_provider value
  141. assert:
  142. that: cloud_provider in ['gce', 'aws', 'azure', 'openstack', 'vsphere', 'oci', 'external']
  143. msg: "If set the 'cloud_provider' var must be set either to 'gce', 'aws', 'azure', 'openstack', 'vsphere', 'oci' or 'external'"
  144. when:
  145. - cloud_provider is defined
  146. - not ignore_assert_errors
  147. tags:
  148. - cloud-provider
  149. - facts
  150. - name: "Check that kube_service_addresses is a network range"
  151. assert:
  152. that:
  153. - kube_service_addresses | ansible.utils.ipaddr('net')
  154. msg: "kube_service_addresses = '{{ kube_service_addresses }}' is not a valid network range"
  155. run_once: true
  156. - name: "Check that kube_pods_subnet is a network range"
  157. assert:
  158. that:
  159. - kube_pods_subnet | ansible.utils.ipaddr('net')
  160. msg: "kube_pods_subnet = '{{ kube_pods_subnet }}' is not a valid network range"
  161. run_once: true
  162. - name: "Check that kube_pods_subnet does not collide with kube_service_addresses"
  163. assert:
  164. that:
  165. - kube_pods_subnet | ansible.utils.ipaddr(kube_service_addresses) | string == 'None'
  166. msg: "kube_pods_subnet cannot be the same network segment as kube_service_addresses"
  167. run_once: true
  168. - name: "Check that IP range is enough for the nodes"
  169. assert:
  170. that:
  171. - 2 ** (kube_network_node_prefix - kube_pods_subnet | ansible.utils.ipaddr('prefix')) >= groups['k8s_cluster'] | length
  172. msg: "Not enough IPs are available for the desired node count."
  173. when: kube_network_plugin != 'calico'
  174. run_once: true
  175. - name: Stop if unknown dns mode
  176. assert:
  177. that: dns_mode in ['coredns', 'coredns_dual', 'manual', 'none']
  178. msg: "dns_mode can only be 'coredns', 'coredns_dual', 'manual' or 'none'"
  179. when: dns_mode is defined
  180. run_once: true
  181. - name: Stop if unknown kube proxy mode
  182. assert:
  183. that: kube_proxy_mode in ['iptables', 'ipvs']
  184. msg: "kube_proxy_mode can only be 'iptables' or 'ipvs'"
  185. when: kube_proxy_mode is defined
  186. run_once: true
  187. - name: Stop if unknown cert_management
  188. assert:
  189. that: cert_management | d('script') in ['script', 'none']
  190. msg: "cert_management can only be 'script' or 'none'"
  191. run_once: true
  192. - name: Stop if unknown resolvconf_mode
  193. assert:
  194. that: resolvconf_mode in ['docker_dns', 'host_resolvconf', 'none']
  195. msg: "resolvconf_mode can only be 'docker_dns', 'host_resolvconf' or 'none'"
  196. when: resolvconf_mode is defined
  197. run_once: true
  198. - name: Stop if etcd deployment type is not host, docker or kubeadm
  199. assert:
  200. that: etcd_deployment_type in ['host', 'docker', 'kubeadm']
  201. msg: "The etcd deployment type, 'etcd_deployment_type', must be host, docker or kubeadm"
  202. when:
  203. - inventory_hostname in groups.get('etcd',[])
  204. - name: Stop if container manager is not docker, crio or containerd
  205. assert:
  206. that: container_manager in ['docker', 'crio', 'containerd']
  207. msg: "The container manager, 'container_manager', must be docker, crio or containerd"
  208. run_once: true
  209. - name: Stop if etcd deployment type is not host or kubeadm when container_manager != docker
  210. assert:
  211. that: etcd_deployment_type in ['host', 'kubeadm']
  212. msg: "The etcd deployment type, 'etcd_deployment_type', must be host or kubeadm when container_manager is not docker"
  213. when:
  214. - inventory_hostname in groups.get('etcd',[])
  215. - container_manager != 'docker'
  216. # TODO: Clean this task up when we drop backward compatibility support for `etcd_kubeadm_enabled`
  217. - name: Stop if etcd deployment type is not host or kubeadm when container_manager != docker and etcd_kubeadm_enabled is not defined
  218. run_once: true
  219. when: etcd_kubeadm_enabled is defined
  220. block:
  221. - name: Warn the user if they are still using `etcd_kubeadm_enabled`
  222. debug:
  223. msg: >
  224. "WARNING! => `etcd_kubeadm_enabled` is deprecated and will be removed in a future release.
  225. You can set `etcd_deployment_type` to `kubeadm` instead of setting `etcd_kubeadm_enabled` to `true`."
  226. changed_when: true
  227. - name: Stop if `etcd_kubeadm_enabled` is defined and `etcd_deployment_type` is not `kubeadm` or `host`
  228. assert:
  229. that: etcd_deployment_type == 'kubeadm'
  230. msg: >
  231. It is not possible to use `etcd_kubeadm_enabled` when `etcd_deployment_type` is set to {{ etcd_deployment_type }}.
  232. Unset the `etcd_kubeadm_enabled` variable and set `etcd_deployment_type` to desired deployment type (`host`, `kubeadm`, `docker`) instead."
  233. when: etcd_kubeadm_enabled
  234. - name: Stop if download_localhost is enabled but download_run_once is not
  235. assert:
  236. that: download_run_once
  237. msg: "download_localhost requires enable download_run_once"
  238. when: download_localhost
  239. - name: Stop if kata_containers_enabled is enabled when container_manager is docker
  240. assert:
  241. that: container_manager != 'docker'
  242. msg: "kata_containers_enabled support only for containerd and crio-o. See https://github.com/kata-containers/documentation/blob/1.11.4/how-to/run-kata-with-k8s.md#install-a-cri-implementation for details"
  243. when: kata_containers_enabled
  244. - name: Stop if gvisor_enabled is enabled when container_manager is not containerd
  245. assert:
  246. that: container_manager == 'containerd'
  247. msg: "gvisor_enabled support only compatible with containerd. See https://github.com/kubernetes-sigs/kubespray/issues/7650 for details"
  248. when: gvisor_enabled
  249. - name: Stop if download_localhost is enabled for Flatcar Container Linux
  250. assert:
  251. that: ansible_os_family not in ["Flatcar", "Flatcar Container Linux by Kinvolk"]
  252. msg: "download_run_once not supported for Flatcar Container Linux"
  253. when: download_run_once or download_force_cache
  254. - name: Ensure minimum containerd version
  255. assert:
  256. that: containerd_version is version(containerd_min_version_required, '>=')
  257. msg: "containerd_version is too low. Minimum version {{ containerd_min_version_required }}"
  258. run_once: true
  259. when:
  260. - containerd_version not in ['latest', 'edge', 'stable']
  261. - container_manager == 'containerd'
  262. - name: Stop if using deprecated containerd_config variable
  263. assert:
  264. that: containerd_config is not defined
  265. msg: "Variable containerd_config is now deprecated. See https://github.com/kubernetes-sigs/kubespray/blob/master/inventory/sample/group_vars/all/containerd.yml for details."
  266. when:
  267. - containerd_config is defined
  268. - not ignore_assert_errors
  269. - name: Stop if auto_renew_certificates is enabled when certificates are managed externally (kube_external_ca_mode is true)
  270. assert:
  271. that: not auto_renew_certificates
  272. msg: "Variable auto_renew_certificates must be disabled when CA are managed externally: kube_external_ca_mode = true"
  273. when:
  274. - kube_external_ca_mode
  275. - not ignore_assert_errors
  276. - name: Stop if using deprecated comma separated list for admission plugins
  277. assert:
  278. that: "',' not in kube_apiserver_enable_admission_plugins[0]"
  279. msg: "Comma-separated list for kube_apiserver_enable_admission_plugins is now deprecated, use separate list items for each plugin."
  280. when:
  281. - kube_apiserver_enable_admission_plugins is defined
  282. - kube_apiserver_enable_admission_plugins | length > 0
  283. - name: Verify that the packages list structure is valid
  284. ansible.utils.validate:
  285. criteria: "{{ lookup('file', 'pkgs-schema.json') }}"
  286. data: "{{ pkgs }}"
  287. - name: Verify that the packages list is sorted
  288. vars:
  289. pkgs_lists: "{{ pkgs.keys() | list }}"
  290. assert:
  291. that: "pkgs_lists | sort == pkgs_lists"
  292. fail_msg: "pkgs is not sorted: {{ pkgs_lists | ansible.utils.fact_diff(pkgs_lists | sort) }}"