main.yml 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. ---
  2. # TODO: add ability to configure certificates given either a local file to
  3. # point to or certificate contents, set in default cert locations.
  4. # Authentication Variable Validation
  5. # TODO: validate the different identity provider kinds as well
  6. - fail:
  7. msg: >
  8. Invalid OAuth grant method: {{ openshift_master_oauth_grant_method }}
  9. when:
  10. - openshift_master_oauth_grant_method not in openshift_master_valid_grant_methods
  11. - import_tasks: pre_pull.yml
  12. - name: Open up firewall ports
  13. import_tasks: firewall.yml
  14. - name: Prepare static pod scripts
  15. import_tasks: static_shim.yml
  16. - name: Create r_openshift_master_data_dir
  17. file:
  18. path: "{{ r_openshift_master_data_dir }}"
  19. state: directory
  20. mode: 0755
  21. owner: root
  22. group: root
  23. - import_tasks: registry_auth.yml
  24. - name: Create config parent directory if it does not exist
  25. file:
  26. path: "/etc/origin/master"
  27. state: directory
  28. - name: Copy recyler pod to config directory
  29. template:
  30. src: "recycler_pod.yaml.j2"
  31. dest: "/etc/origin/master/recycler_pod.yaml"
  32. - name: Create flexvolume directory when on atomic hosts
  33. file:
  34. state: directory
  35. path: "/etc/origin/kubelet-plugins/volume/exec"
  36. mode: '0750'
  37. when: openshift_is_atomic | bool
  38. - name: Flex volume directory on non-atomic host
  39. file:
  40. state: directory
  41. path: "/usr/libexec/kubernetes/kubelet-plugins/volume/exec/"
  42. mode: '0750'
  43. when: not openshift_is_atomic | bool
  44. - name: Create the policy file if it does not already exist
  45. command: >
  46. {{ openshift_client_binary }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  47. adm create-bootstrap-policy-file
  48. --filename={{ openshift_master_policy }}
  49. args:
  50. creates: "{{ openshift_master_policy }}"
  51. - name: Create the scheduler config
  52. copy:
  53. content: "{{ scheduler_config | to_nice_json }}"
  54. dest: "{{ openshift_master_scheduler_conf }}"
  55. backup: true
  56. - import_tasks: htpass_provider.yml
  57. - name: Create the ldap ca file if needed
  58. copy:
  59. dest: "/etc/origin/master/{{ item.name }}_ldap_ca.crt"
  60. content: "{{ openshift.master.ldap_ca }}"
  61. mode: 0600
  62. backup: yes
  63. when:
  64. - openshift.master.ldap_ca is defined
  65. - item.kind == 'LDAPPasswordIdentityProvider'
  66. with_items: "{{ openshift_master_identity_providers }}"
  67. - name: Create the openid ca file if needed
  68. copy:
  69. dest: "/etc/origin/master/{{ item.name }}_openid_ca.crt"
  70. content: "{{ openshift.master.openid_ca }}"
  71. mode: 0600
  72. backup: yes
  73. when:
  74. - openshift.master.openid_ca is defined
  75. - item.kind == 'OpenIDIdentityProvider'
  76. with_items: "{{ openshift_master_identity_providers }}"
  77. - name: Create the request header ca file if needed
  78. copy:
  79. dest: "/etc/origin/master/{{ item.name }}_request_header_ca.crt"
  80. content: "{{ openshift_master_request_header_ca }}"
  81. mode: 0600
  82. backup: yes
  83. when:
  84. - openshift_master_request_header_ca != l_osm_request_header_none
  85. - item.kind == 'RequestHeaderIdentityProvider'
  86. with_items: "{{ openshift_master_identity_providers }}"
  87. - name: Set fact of all etcd host IPs
  88. openshift_facts:
  89. role: common
  90. local_facts:
  91. no_proxy_etcd_host_ips: "{{ openshift_no_proxy_etcd_host_ips }}"
  92. - name: Create session secrets file
  93. template:
  94. dest: "{{ openshift_master_session_secrets_file }}"
  95. src: sessionSecretsFile.yaml.v1.j2
  96. owner: root
  97. group: root
  98. mode: 0600
  99. - set_fact:
  100. # translate_idps is a custom filter in role lib_utils
  101. translated_identity_providers: "{{ openshift_master_identity_providers | translate_idps('v1') }}"
  102. # TODO: add the validate parameter when there is a validation command to run
  103. - name: Create master config
  104. template:
  105. dest: "{{ openshift_master_config_file }}"
  106. src: master.yaml.v1.j2
  107. backup: true
  108. owner: root
  109. group: root
  110. mode: 0600
  111. - import_tasks: set_loopback_context.yml
  112. - name: Create the master service env file
  113. template:
  114. src: "master.env.j2"
  115. dest: /etc/origin/master/master.env
  116. backup: true
  117. - import_tasks: static.yml
  118. - name: Establish the default bootstrap kubeconfig for masters
  119. copy:
  120. remote_src: true
  121. src: "/etc/origin/master/admin.kubeconfig"
  122. dest: "{{ item }}"
  123. mode: 0600
  124. with_items:
  125. # bootstrap as an admin
  126. - /etc/origin/node/bootstrap.kubeconfig
  127. # copy to this location to bypass initial bootstrap request
  128. - /etc/origin/node/node.kubeconfig
  129. - import_tasks: pre_pull_poll.yml
  130. - name: Start and enable self-hosting node
  131. systemd:
  132. name: "{{ openshift_service_type }}-node"
  133. state: restarted
  134. enabled: yes
  135. register: node_start
  136. ignore_errors: yes
  137. - when: node_start is failed
  138. block:
  139. - name: Get node logs
  140. command: journalctl --no-pager -n 300 -u {{ openshift_service_type }}-node
  141. register: logs_node
  142. ignore_errors: true
  143. - debug:
  144. msg: "{{ logs_node.stdout_lines }}"
  145. - fail:
  146. msg: Node start failed.
  147. - name: Wait for control plane pods to appear
  148. oc_obj:
  149. state: list
  150. kind: pod
  151. name: "master-{{ item }}-{{ l_kubelet_node_name | lower }}"
  152. namespace: kube-system
  153. register: control_plane_pods
  154. until:
  155. - "'results' in control_plane_pods"
  156. - "'results' in control_plane_pods.results"
  157. - control_plane_pods.results.results | length > 0
  158. retries: 60
  159. delay: 5
  160. with_items:
  161. - "{{ 'etcd' if inventory_hostname in groups['oo_etcd_to_config'] else omit }}"
  162. - api
  163. - controllers
  164. ignore_errors: true
  165. - when: control_plane_pods is failed
  166. block:
  167. - name: Check status in the kube-system namespace
  168. command: >
  169. {{ openshift_client_binary }} status --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n kube-system
  170. register: control_plane_status
  171. ignore_errors: true
  172. - debug:
  173. msg: "{{ control_plane_status.stdout_lines }}"
  174. - name: Get pods in the kube-system namespace
  175. command: >
  176. {{ openshift_client_binary }} get pods --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n kube-system -o wide
  177. register: control_plane_pods_list
  178. ignore_errors: true
  179. - debug:
  180. msg: "{{ control_plane_pods_list.stdout_lines }}"
  181. - name: Get events in the kube-system namespace
  182. command: >
  183. {{ openshift_client_binary }} get events --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n kube-system
  184. register: control_plane_events
  185. ignore_errors: true
  186. - debug:
  187. msg: "{{ control_plane_events.stdout_lines }}"
  188. - name: Get node logs
  189. command: journalctl --no-pager -n 300 -u {{ openshift_service_type }}-node
  190. register: logs_node
  191. ignore_errors: true
  192. - debug:
  193. msg: "{{ logs_node.stdout_lines }}"
  194. - name: Report control plane errors
  195. fail:
  196. msg: Control plane pods didn't come up
  197. - name: Wait for all control plane pods to become ready
  198. oc_obj:
  199. state: list
  200. kind: pod
  201. name: "master-{{ item }}-{{ l_kubelet_node_name | lower }}"
  202. namespace: kube-system
  203. register: control_plane_health
  204. until:
  205. - "'results' in control_plane_health"
  206. - "'results' in control_plane_health.results"
  207. - control_plane_health.results.results | length > 0
  208. - "'status' in control_plane_health.results.results[0]"
  209. - "'conditions' in control_plane_health.results.results[0].status"
  210. - control_plane_health.results.results[0].status.conditions | selectattr('type', 'match', '^Ready$') | map(attribute='status') | join | bool == True
  211. retries: 60
  212. delay: 5
  213. with_items:
  214. - "{{ 'etcd' if inventory_hostname in groups['oo_etcd_to_config'] else '' }}"
  215. - api
  216. - controllers
  217. when:
  218. - item != ''
  219. - when: control_plane_health is failed
  220. block:
  221. - debug:
  222. msg: "{{ control_plane_pods_list.stdout_lines }}"
  223. - name: Get events in the kube-system namespace
  224. command: >
  225. {{ openshift_client_binary }} get events --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n kube-system
  226. register: control_plane_events
  227. ignore_errors: true
  228. - debug:
  229. msg: "{{ control_plane_events.stdout_lines }}"
  230. - name: Get node logs
  231. command: journalctl --no-pager -n 300 -u {{ openshift_service_type }}-node
  232. register: logs_node
  233. ignore_errors: true
  234. - debug:
  235. msg: "{{ logs_node.stdout_lines }}"
  236. - name: Get API logs
  237. command: >
  238. /usr/local/bin/master-logs api api
  239. register: control_plane_logs_api
  240. ignore_errors: true
  241. - debug:
  242. msg: "{{ control_plane_logs_api.stdout_lines }}"
  243. - name: Get controllers logs
  244. command: >
  245. /usr/local/bin/master-logs controllers controllers
  246. register: control_plane_logs_controllers
  247. ignore_errors: true
  248. - debug:
  249. msg: "{{ control_plane_logs_controllers.stdout_lines }}"
  250. - name: Get etcd logs
  251. command: >
  252. /usr/local/bin/master-logs etcd etcd
  253. register: control_plane_logs_etcd
  254. when: inventory_hostname in groups['oo_etcd_to_config']
  255. ignore_errors: true
  256. - debug:
  257. msg: "{{ control_plane_logs_controllers.stdout_lines }}"
  258. when: inventory_hostname in groups['oo_etcd_to_config']
  259. - name: Report control plane errors
  260. fail:
  261. msg: Control plane pods didn't pass health check
  262. - import_tasks: check_master_api_is_ready.yml
  263. - name: Remove oc cache to refresh a list of APIs
  264. file:
  265. path: "~/.kube/cache"
  266. state: absent