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.

293 lines
10 KiB

6 years ago
6 years ago
6 years ago
  1. ---
  2. - name: Stop if either kube-master or kube-node group is empty
  3. assert:
  4. that: "groups.get('{{ item }}')"
  5. with_items:
  6. - kube-master
  7. - kube-node
  8. run_once: true
  9. when: not ignore_assert_errors
  10. - name: Stop if etcd group is empty in external etcd mode
  11. assert:
  12. that: groups.get('etcd')
  13. fail_msg: "Group 'etcd' cannot be empty in external etcd mode"
  14. run_once: true
  15. when:
  16. - not ignore_assert_errors
  17. - not etcd_kubeadm_enabled
  18. - name: Stop if non systemd OS type
  19. assert:
  20. that: ansible_service_mgr == "systemd"
  21. when: not ignore_assert_errors
  22. - name: Stop if unknown OS
  23. assert:
  24. that: ansible_os_family in ['RedHat', 'CentOS', 'Fedora', 'Ubuntu', 'Debian', 'Flatcar Container Linux by Kinvolk', 'Suse', 'ClearLinux', 'OracleLinux']
  25. msg: "{{ ansible_os_family }} is not a known OS"
  26. when: not ignore_assert_errors
  27. - name: Stop if unknown network plugin
  28. assert:
  29. that: kube_network_plugin in ['calico', 'canal', 'flannel', 'weave', 'cloud', 'cilium', 'cni', 'contiv', 'ovn4nfv','kube-ovn', 'kube-router', 'macvlan']
  30. msg: "{{ kube_network_plugin }} is not supported"
  31. when:
  32. - kube_network_plugin is defined
  33. - not ignore_assert_errors
  34. - name: Stop if incompatible network plugin and cloudprovider
  35. assert:
  36. that: kube_network_plugin != 'calico'
  37. msg: "Azure and Calico are not compatible. See https://github.com/projectcalico/calicoctl/issues/949 for details."
  38. when:
  39. - cloud_provider is defined and cloud_provider == 'azure'
  40. - not ignore_assert_errors
  41. - name: Stop if unsupported version of Kubernetes
  42. assert:
  43. that: kube_version is version(kube_version_min_required, '>=')
  44. msg: "The current release of Kubespray only support newer version of Kubernetes than {{ kube_version_min_required }} - You are trying to apply {{ kube_version }}"
  45. when: not ignore_assert_errors
  46. # simplify this items-list when https://github.com/ansible/ansible/issues/15753 is resolved
  47. - name: "Stop if known booleans are set as strings (Use JSON format on CLI: -e \"{'key': true }\")"
  48. assert:
  49. that: item.value|type_debug == 'bool'
  50. msg: "{{ item.value }} isn't a bool"
  51. run_once: yes
  52. with_items:
  53. - { name: download_run_once, value: "{{ download_run_once }}" }
  54. - { name: deploy_netchecker, value: "{{ deploy_netchecker }}" }
  55. - { name: download_always_pull, value: "{{ download_always_pull }}" }
  56. - { name: helm_enabled, value: "{{ helm_enabled }}" }
  57. - { name: openstack_lbaas_enabled, value: "{{ openstack_lbaas_enabled }}" }
  58. when: not ignore_assert_errors
  59. - name: Stop if even number of etcd hosts
  60. assert:
  61. that: groups.etcd|length is not divisibleby 2
  62. when:
  63. - not ignore_assert_errors
  64. - groups.get('etcd')
  65. - inventory_hostname in groups['etcd']
  66. - name: Stop if memory is too small for masters
  67. assert:
  68. that: ansible_memtotal_mb >= minimal_master_memory_mb
  69. when:
  70. - not ignore_assert_errors
  71. - inventory_hostname in groups['kube-master']
  72. - name: Stop if memory is too small for nodes
  73. assert:
  74. that: ansible_memtotal_mb >= minimal_node_memory_mb
  75. when:
  76. - not ignore_assert_errors
  77. - inventory_hostname in groups['kube-node']
  78. # This assertion will fail on the safe side: One can indeed schedule more pods
  79. # on a node than the CIDR-range has space for when additional pods use the host
  80. # network namespace. It is impossible to ascertain the number of such pods at
  81. # provisioning time, so to establish a guarantee, we factor these out.
  82. # NOTICE: the check blatantly ignores the inet6-case
  83. - name: Guarantee that enough network address space is available for all pods
  84. assert:
  85. that: "{{ (kubelet_max_pods | default(110)) | int <= (2 ** (32 - kube_network_node_prefix | int)) - 2 }}"
  86. msg: "Do not schedule more pods on a node than inet addresses are available."
  87. when:
  88. - not ignore_assert_errors
  89. - inventory_hostname in groups['k8s-cluster']
  90. - kube_network_node_prefix is defined
  91. - kube_network_plugin != 'calico'
  92. - name: Stop if ip var does not match local ips
  93. assert:
  94. that: ip in ansible_all_ipv4_addresses
  95. msg: "'{{ ansible_all_ipv4_addresses }}' do not contain '{{ ip }}'"
  96. when:
  97. - not ignore_assert_errors
  98. - ip is defined
  99. - name: Stop if access_ip is not pingable
  100. command: ping -c1 {{ access_ip }}
  101. when:
  102. - access_ip is defined
  103. - not ignore_assert_errors
  104. - name: Stop if RBAC is not enabled when dashboard is enabled
  105. assert:
  106. that: rbac_enabled
  107. when:
  108. - dashboard_enabled
  109. - not ignore_assert_errors
  110. - name: Stop if RBAC is not enabled when OCI cloud controller is enabled
  111. assert:
  112. that: rbac_enabled
  113. when:
  114. - cloud_provider is defined and cloud_provider == "oci"
  115. - not ignore_assert_errors
  116. - name: Stop if RBAC and anonymous-auth are not enabled when insecure port is disabled
  117. assert:
  118. that: rbac_enabled and kube_api_anonymous_auth
  119. when:
  120. - kube_apiserver_insecure_port == 0 and inventory_hostname in groups['kube-master']
  121. - not ignore_assert_errors
  122. - name: Stop if kernel version is too low
  123. assert:
  124. that: ansible_kernel.split('-')[0] is version('4.9.17', '>=')
  125. when:
  126. - kube_network_plugin == 'cilium' or cilium_deploy_additionally | default(false) | bool
  127. - not ignore_assert_errors
  128. - name: Stop if bad hostname
  129. assert:
  130. that: inventory_hostname is match("[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$")
  131. msg: "Hostname must consist of lower case alphanumeric characters, '.' or '-', and must start and end with an alphanumeric character"
  132. when: not ignore_assert_errors
  133. - name: check cloud_provider value
  134. assert:
  135. that: cloud_provider in ['generic', 'gce', 'aws', 'azure', 'openstack', 'vsphere', 'oci', 'external']
  136. msg: "If set the 'cloud_provider' var must be set either to 'generic', 'gce', 'aws', 'azure', 'openstack', 'vsphere', or external"
  137. when:
  138. - cloud_provider is defined
  139. - not ignore_assert_errors
  140. tags:
  141. - cloud-provider
  142. - facts
  143. - name: Ensure minimum calico version
  144. assert:
  145. that: calico_version is version(calico_min_version_required, '>=')
  146. msg: "calico_version is too low. Minimum version {{ calico_min_version_required }}"
  147. run_once: yes
  148. when:
  149. - kube_network_plugin == 'calico'
  150. - name: Get current calico cluster version
  151. shell: "set -o pipefail && {{ bin_dir }}/calicoctl.sh version | grep 'Cluster Version:' | awk '{ print $3}'"
  152. args:
  153. executable: /bin/bash
  154. register: calico_version_on_server
  155. async: 10
  156. poll: 3
  157. run_once: yes
  158. changed_when: false
  159. failed_when: false
  160. when:
  161. - kube_network_plugin == 'calico'
  162. - name: Check that current calico version is enough for upgrade
  163. assert:
  164. that:
  165. - calico_version_on_server.stdout is version(calico_min_version_required, '>=')
  166. msg: "Your version of calico is not fresh enough for upgrade. Minimum version {{ calico_min_version_required }}"
  167. when:
  168. - kube_network_plugin == 'calico'
  169. - 'calico_version_on_server.stdout is defined'
  170. - calico_version_on_server.stdout
  171. - inventory_hostname == groups['kube-master'][0]
  172. run_once: yes
  173. - name: "Check that cluster_id is set if calico_rr enabled"
  174. assert:
  175. that:
  176. - cluster_id is defined
  177. msg: "A unique cluster_id is required if using calico_rr"
  178. when:
  179. - kube_network_plugin == 'calico'
  180. - peer_with_calico_rr
  181. - inventory_hostname == groups['kube-master'][0]
  182. run_once: yes
  183. - name: "Check that calico_rr nodes are in k8s-cluster group"
  184. assert:
  185. that:
  186. - '"k8s-cluster" in group_names'
  187. msg: "calico-rr must be a child group of k8s-cluster group"
  188. when:
  189. - kube_network_plugin == 'calico'
  190. - '"calico-rr" in group_names'
  191. - name: "Check that kube_service_addresses is a network range"
  192. assert:
  193. that:
  194. - kube_service_addresses | ipaddr('net')
  195. msg: "kube_service_addresses = '{{ kube_service_addresses }}' is not a valid network range"
  196. run_once: yes
  197. - name: "Check that kube_pods_subnet is a network range"
  198. assert:
  199. that:
  200. - kube_pods_subnet | ipaddr('net')
  201. msg: "kube_pods_subnet = '{{ kube_pods_subnet }}' is not a valid network range"
  202. run_once: yes
  203. - name: "Check that kube_pods_subnet does not collide with kube_service_addresses"
  204. assert:
  205. that:
  206. - kube_pods_subnet | ipaddr(kube_service_addresses) | string == 'None'
  207. msg: "kube_pods_subnet cannot be the same network segment as kube_service_addresses"
  208. run_once: yes
  209. - name: Stop if unknown dns mode
  210. assert:
  211. that: dns_mode in ['coredns', 'coredns_dual', 'manual', 'none']
  212. msg: "dns_mode can only be 'coredns', 'coredns_dual', 'manual' or 'none'"
  213. when: dns_mode is defined
  214. run_once: true
  215. - name: Stop if unknown kube proxy mode
  216. assert:
  217. that: kube_proxy_mode in ['iptables', 'ipvs']
  218. msg: "kube_proxy_mode can only be 'iptables' or 'ipvs'"
  219. when: kube_proxy_mode is defined
  220. run_once: true
  221. - name: Stop if vault is chose
  222. assert:
  223. that: cert_management != 'vault'
  224. msg: "Support for vault have been removed, please use 'script' or 'none'"
  225. when: cert_management is defined
  226. run_once: true
  227. - name: Stop if unknown cert_management
  228. assert:
  229. that: cert_management|d('script') in ['script', 'none']
  230. msg: "cert_management can only be 'script' or 'none'"
  231. run_once: true
  232. - name: Stop if unknown resolvconf_mode
  233. assert:
  234. that: resolvconf_mode in ['docker_dns', 'host_resolvconf', 'none']
  235. msg: "resolvconf_mode can only be 'docker_dns', 'host_resolvconf' or 'none'"
  236. when: resolvconf_mode is defined
  237. run_once: true
  238. - name: Stop if etcd deployment type is not host or docker
  239. assert:
  240. that: etcd_deployment_type in ['host', 'docker']
  241. msg: "The etcd deployment type, 'etcd_deployment_type', must be host or docker"
  242. run_once: true
  243. - name: Stop if download_localhost is enabled but download_run_once is not
  244. assert:
  245. that: download_run_once
  246. msg: "download_localhost requires enable download_run_once"
  247. when: download_localhost
  248. - name: Stop if download_localhost is enabled when container_manager not docker
  249. assert:
  250. that: container_manager == 'docker'
  251. msg: "download_run_once support only for docker. See https://github.com/containerd/containerd/issues/4075 for details"
  252. when: download_run_once or download_force_cache
  253. - name: Stop if download_localhost is enabled for Flatcar Container Linux
  254. assert:
  255. that: ansible_os_family not in ["Flatcar Container Linux by Kinvolk"]
  256. msg: "download_run_once not supported for Flatcar Container Linux"
  257. when: download_run_once or download_force_cache