main.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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 is defined
  11. - openshift_master_oauth_grant_method not in openshift_master_valid_grant_methods
  12. # HA Variable Validation
  13. - fail:
  14. msg: "openshift_master_cluster_method must be set to either 'native' or 'pacemaker' for multi-master installations"
  15. when:
  16. - openshift.master.ha | bool
  17. - (openshift.master.cluster_method is not defined) or (openshift.master.cluster_method is defined and openshift.master.cluster_method not in ["native", "pacemaker"])
  18. - fail:
  19. msg: "'native' high availability is not supported for the requested OpenShift version"
  20. when:
  21. - openshift.master.ha | bool
  22. - openshift.master.cluster_method == "native"
  23. - not openshift.common.version_gte_3_1_or_1_1 | bool
  24. - fail:
  25. msg: "openshift_master_cluster_password must be set for multi-master installations"
  26. when:
  27. - openshift.master.ha | bool
  28. - openshift.master.cluster_method == "pacemaker"
  29. - openshift_master_cluster_password is not defined or not openshift_master_cluster_password
  30. - fail:
  31. msg: "Pacemaker based HA is not supported at this time when used with containerized installs"
  32. when:
  33. - openshift.master.ha | bool
  34. - openshift.master.cluster_method == "pacemaker"
  35. - openshift.common.is_containerized | bool
  36. - name: Open up firewall ports
  37. include: firewall.yml
  38. static: yes
  39. - name: Install Master package
  40. package:
  41. name: "{{ openshift.common.service_type }}-master{{ openshift_pkg_version | default('') | oo_image_tag_to_rpm_version(include_dash=True) }}"
  42. state: present
  43. when:
  44. - not openshift.common.is_containerized | bool
  45. - name: Create r_openshift_master_data_dir
  46. file:
  47. path: "{{ r_openshift_master_data_dir }}"
  48. state: directory
  49. mode: 0755
  50. owner: root
  51. group: root
  52. when:
  53. - openshift.common.is_containerized | bool
  54. - name: Reload systemd units
  55. command: systemctl daemon-reload
  56. when:
  57. - openshift.common.is_containerized | bool
  58. - name: Re-gather package dependent master facts
  59. openshift_facts:
  60. - name: Create config parent directory if it does not exist
  61. file:
  62. path: "{{ openshift_master_config_dir }}"
  63. state: directory
  64. - name: Create the policy file if it does not already exist
  65. command: >
  66. {{ openshift.common.client_binary }} adm create-bootstrap-policy-file
  67. --filename={{ openshift_master_policy }}
  68. args:
  69. creates: "{{ openshift_master_policy }}"
  70. notify:
  71. - restart master api
  72. - restart master controllers
  73. - name: Create the scheduler config
  74. copy:
  75. content: "{{ scheduler_config | to_nice_json }}"
  76. dest: "{{ openshift_master_scheduler_conf }}"
  77. backup: true
  78. notify:
  79. - restart master api
  80. - restart master controllers
  81. - name: Install httpd-tools if needed
  82. package: name=httpd-tools state=present
  83. when:
  84. - item.kind == 'HTPasswdPasswordIdentityProvider'
  85. - not openshift.common.is_atomic | bool
  86. with_items: "{{ openshift.master.identity_providers }}"
  87. - name: Ensure htpasswd directory exists
  88. file:
  89. path: "{{ item.filename | dirname }}"
  90. state: directory
  91. when:
  92. - item.kind == 'HTPasswdPasswordIdentityProvider'
  93. with_items: "{{ openshift.master.identity_providers }}"
  94. - name: Create the htpasswd file if needed
  95. template:
  96. dest: "{{ item.filename }}"
  97. src: htpasswd.j2
  98. backup: yes
  99. when:
  100. - item.kind == 'HTPasswdPasswordIdentityProvider'
  101. - openshift.master.manage_htpasswd | bool
  102. with_items: "{{ openshift.master.identity_providers }}"
  103. - name: Ensure htpasswd file exists
  104. copy:
  105. dest: "{{ item.filename }}"
  106. force: no
  107. content: ""
  108. mode: 0600
  109. when:
  110. - item.kind == 'HTPasswdPasswordIdentityProvider'
  111. with_items: "{{ openshift.master.identity_providers }}"
  112. - name: Create the ldap ca file if needed
  113. copy:
  114. dest: "{{ item.ca if 'ca' in item and '/' in item.ca else openshift_master_config_dir ~ '/' ~ item.ca | default('ldap_ca.crt') }}"
  115. content: "{{ openshift.master.ldap_ca }}"
  116. mode: 0600
  117. backup: yes
  118. when:
  119. - openshift.master.ldap_ca is defined
  120. - item.kind == 'LDAPPasswordIdentityProvider'
  121. with_items: "{{ openshift.master.identity_providers }}"
  122. - name: Create the openid ca file if needed
  123. copy:
  124. dest: "{{ item.ca if 'ca' in item and '/' in item.ca else openshift_master_config_dir ~ '/' ~ item.ca | default('openid_ca.crt') }}"
  125. content: "{{ openshift.master.openid_ca }}"
  126. mode: 0600
  127. backup: yes
  128. when:
  129. - openshift.master.openid_ca is defined
  130. - item.kind == 'OpenIDIdentityProvider'
  131. - item.ca | default('') != ''
  132. with_items: "{{ openshift.master.identity_providers }}"
  133. - name: Create the request header ca file if needed
  134. copy:
  135. dest: "{{ item.clientCA if 'clientCA' in item and '/' in item.clientCA else openshift_master_config_dir ~ '/' ~ item.clientCA | default('request_header_ca.crt') }}"
  136. content: "{{ openshift.master.request_header_ca }}"
  137. mode: 0600
  138. backup: yes
  139. when:
  140. - openshift.master.request_header_ca is defined
  141. - item.kind == 'RequestHeaderIdentityProvider'
  142. - item.clientCA | default('') != ''
  143. with_items: "{{ openshift.master.identity_providers }}"
  144. # This is an ugly hack to verify settings are in a file without modifying them with lineinfile.
  145. # The template file will stomp any other settings made.
  146. - block:
  147. - name: check whether our docker-registry setting exists in the env file
  148. command: "awk '/^OPENSHIFT_DEFAULT_REGISTRY=docker-registry.default.svc:5000/' /etc/sysconfig/{{ openshift.common.service_type }}-master"
  149. failed_when: false
  150. changed_when: false
  151. register: l_already_set
  152. - set_fact:
  153. openshift_push_via_dns: "{{ openshift.common.version_gte_3_6 or (l_already_set.stdout is defined and l_already_set.stdout | match('OPENSHIFT_DEFAULT_REGISTRY=docker-registry.default.svc:5000')) }}"
  154. - name: Set fact of all etcd host IPs
  155. openshift_facts:
  156. role: common
  157. local_facts:
  158. no_proxy_etcd_host_ips: "{{ openshift_no_proxy_etcd_host_ips }}"
  159. - name: Update journald config
  160. include: journald.yml
  161. - name: Install the systemd units
  162. include: systemd_units.yml
  163. - name: Install Master system container
  164. include: system_container.yml
  165. when:
  166. - openshift.common.is_containerized | bool
  167. - openshift.common.is_master_system_container | bool
  168. - name: Create session secrets file
  169. template:
  170. dest: "{{ openshift.master.session_secrets_file }}"
  171. src: sessionSecretsFile.yaml.v1.j2
  172. owner: root
  173. group: root
  174. mode: 0600
  175. when:
  176. - openshift.master.session_auth_secrets is defined
  177. - openshift.master.session_encryption_secrets is defined
  178. notify:
  179. - restart master api
  180. - set_fact:
  181. translated_identity_providers: "{{ openshift.master.identity_providers | translate_idps('v1') }}"
  182. # TODO: add the validate parameter when there is a validation command to run
  183. - name: Create master config
  184. template:
  185. dest: "{{ openshift_master_config_file }}"
  186. src: master.yaml.v1.j2
  187. backup: true
  188. owner: root
  189. group: root
  190. mode: 0600
  191. notify:
  192. - restart master api
  193. - restart master controllers
  194. - name: modify controller args
  195. yedit:
  196. src: /etc/origin/master/master-config.yaml
  197. edits:
  198. - key: kubernetesMasterConfig.controllerArguments.cluster-signing-cert-file
  199. value:
  200. - /etc/origin/master/ca.crt
  201. - key: kubernetesMasterConfig.controllerArguments.cluster-signing-key-file
  202. value:
  203. - /etc/origin/master/ca.key
  204. notify:
  205. - restart master controllers
  206. when: openshift_master_bootstrap_enabled | default(False)
  207. - include: set_loopback_context.yml
  208. when:
  209. - openshift.common.version_gte_3_2_or_1_2
  210. - name: Start and enable master api on first master
  211. systemd:
  212. name: "{{ openshift.common.service_type }}-master-api"
  213. enabled: yes
  214. state: started
  215. when:
  216. - openshift.master.cluster_method == 'native'
  217. - inventory_hostname == openshift_master_hosts[0]
  218. register: l_start_result
  219. until: not l_start_result | failed
  220. retries: 1
  221. delay: 60
  222. - name: Dump logs from master-api if it failed
  223. command: journalctl --no-pager -n 100 -u {{ openshift.common.service_type }}-master-api
  224. when:
  225. - l_start_result | failed
  226. - set_fact:
  227. master_api_service_status_changed: "{{ l_start_result | changed }}"
  228. when:
  229. - openshift.master.cluster_method == 'native'
  230. - inventory_hostname == openshift_master_hosts[0]
  231. - pause:
  232. seconds: 15
  233. when:
  234. - openshift.master.ha | bool
  235. - openshift.master.cluster_method == 'native'
  236. - name: Start and enable master api all masters
  237. systemd:
  238. name: "{{ openshift.common.service_type }}-master-api"
  239. enabled: yes
  240. state: started
  241. when:
  242. - openshift.master.cluster_method == 'native'
  243. - inventory_hostname != openshift_master_hosts[0]
  244. register: l_start_result
  245. until: not l_start_result | failed
  246. retries: 1
  247. delay: 60
  248. - name: Dump logs from master-api if it failed
  249. command: journalctl --no-pager -n 100 -u {{ openshift.common.service_type }}-master-api
  250. when:
  251. - l_start_result | failed
  252. - set_fact:
  253. master_api_service_status_changed: "{{ l_start_result | changed }}"
  254. when:
  255. - openshift.master.cluster_method == 'native'
  256. - inventory_hostname != openshift_master_hosts[0]
  257. # A separate wait is required here for native HA since notifies will
  258. # be resolved after all tasks in the role.
  259. - include: check_master_api_is_ready.yml
  260. when:
  261. - openshift.master.cluster_method == 'native'
  262. - master_api_service_status_changed | bool
  263. - name: Start and enable master controller on first master
  264. systemd:
  265. name: "{{ openshift.common.service_type }}-master-controllers"
  266. enabled: yes
  267. state: started
  268. when:
  269. - openshift.master.cluster_method == 'native'
  270. - inventory_hostname == openshift_master_hosts[0]
  271. register: l_start_result
  272. until: not l_start_result | failed
  273. retries: 1
  274. delay: 60
  275. - name: Dump logs from master-controllers if it failed
  276. command: journalctl --no-pager -n 100 -u {{ openshift.common.service_type }}-master-controllers
  277. when:
  278. - l_start_result | failed
  279. - name: Wait for master controller service to start on first master
  280. pause:
  281. seconds: 15
  282. when:
  283. - openshift.master.cluster_method == 'native'
  284. - name: Start and enable master controller on all masters
  285. systemd:
  286. name: "{{ openshift.common.service_type }}-master-controllers"
  287. enabled: yes
  288. state: started
  289. when:
  290. - openshift.master.cluster_method == 'native'
  291. - inventory_hostname != openshift_master_hosts[0]
  292. register: l_start_result
  293. until: not l_start_result | failed
  294. retries: 1
  295. delay: 60
  296. - name: Dump logs from master-controllers if it failed
  297. command: journalctl --no-pager -n 100 -u {{ openshift.common.service_type }}-master-controllers
  298. when:
  299. - l_start_result | failed
  300. - set_fact:
  301. master_controllers_service_status_changed: "{{ l_start_result | changed }}"
  302. when:
  303. - openshift.master.cluster_method == 'native'
  304. - name: Install cluster packages
  305. package: name=pcs state=present
  306. when:
  307. - openshift.master.cluster_method == 'pacemaker'
  308. - not openshift.common.is_containerized | bool
  309. register: l_install_result
  310. - name: Start and enable cluster service
  311. systemd:
  312. name: pcsd
  313. enabled: yes
  314. state: started
  315. when:
  316. - openshift.master.cluster_method == 'pacemaker'
  317. - not openshift.common.is_containerized | bool
  318. - name: Set the cluster user password
  319. shell: echo {{ openshift_master_cluster_password | quote }} | passwd --stdin hacluster
  320. when:
  321. - l_install_result | changed
  322. - name: node bootstrap settings
  323. include: bootstrap.yml
  324. when: openshift_master_bootstrap_enabled | default(False)