main.yml 9.1 KB

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