main.yml 8.8 KB

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