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.

283 lines
10 KiB

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