main.yml 8.9 KB

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