main.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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. - include: registry_auth.yml
  160. - name: Install the systemd units
  161. include: systemd_units.yml
  162. - name: Install Master system container
  163. include: system_container.yml
  164. when:
  165. - openshift.common.is_containerized | bool
  166. - openshift.common.is_master_system_container | bool
  167. - name: Create session secrets file
  168. template:
  169. dest: "{{ openshift.master.session_secrets_file }}"
  170. src: sessionSecretsFile.yaml.v1.j2
  171. owner: root
  172. group: root
  173. mode: 0600
  174. when:
  175. - openshift.master.session_auth_secrets is defined
  176. - openshift.master.session_encryption_secrets is defined
  177. notify:
  178. - restart master api
  179. - set_fact:
  180. translated_identity_providers: "{{ openshift.master.identity_providers | translate_idps('v1', openshift.common.version, openshift.common.deployment_type) }}"
  181. # TODO: add the validate parameter when there is a validation command to run
  182. - name: Create master config
  183. template:
  184. dest: "{{ openshift_master_config_file }}"
  185. src: master.yaml.v1.j2
  186. backup: true
  187. owner: root
  188. group: root
  189. mode: 0600
  190. notify:
  191. - restart master api
  192. - restart master controllers
  193. - name: modify controller args
  194. yedit:
  195. src: /etc/origin/master/master-config.yaml
  196. edits:
  197. - key: kubernetesMasterConfig.controllerArguments.cluster-signing-cert-file
  198. value:
  199. - /etc/origin/master/ca.crt
  200. - key: kubernetesMasterConfig.controllerArguments.cluster-signing-key-file
  201. value:
  202. - /etc/origin/master/ca.key
  203. notify:
  204. - restart master controllers
  205. when: openshift_master_bootstrap_enabled | default(False)
  206. - include: set_loopback_context.yml
  207. when:
  208. - openshift.common.version_gte_3_2_or_1_2
  209. - name: Start and enable master api on first master
  210. systemd:
  211. name: "{{ openshift.common.service_type }}-master-api"
  212. enabled: yes
  213. state: started
  214. when:
  215. - openshift.master.cluster_method == 'native'
  216. - inventory_hostname == openshift_master_hosts[0]
  217. register: l_start_result
  218. until: not l_start_result | failed
  219. retries: 1
  220. delay: 60
  221. - name: Dump logs from master-api if it failed
  222. command: journalctl --no-pager -n 100 -u {{ openshift.common.service_type }}-master-api
  223. when:
  224. - l_start_result | failed
  225. - set_fact:
  226. master_api_service_status_changed: "{{ l_start_result | changed }}"
  227. when:
  228. - openshift.master.cluster_method == 'native'
  229. - inventory_hostname == openshift_master_hosts[0]
  230. - pause:
  231. seconds: 15
  232. when:
  233. - openshift.master.ha | bool
  234. - openshift.master.cluster_method == 'native'
  235. - name: Start and enable master api all masters
  236. systemd:
  237. name: "{{ openshift.common.service_type }}-master-api"
  238. enabled: yes
  239. state: started
  240. when:
  241. - openshift.master.cluster_method == 'native'
  242. - inventory_hostname != openshift_master_hosts[0]
  243. register: l_start_result
  244. until: not l_start_result | failed
  245. retries: 1
  246. delay: 60
  247. - name: Dump logs from master-api if it failed
  248. command: journalctl --no-pager -n 100 -u {{ openshift.common.service_type }}-master-api
  249. when:
  250. - l_start_result | failed
  251. - set_fact:
  252. master_api_service_status_changed: "{{ l_start_result | changed }}"
  253. when:
  254. - openshift.master.cluster_method == 'native'
  255. - inventory_hostname != openshift_master_hosts[0]
  256. # A separate wait is required here for native HA since notifies will
  257. # be resolved after all tasks in the role.
  258. - name: Wait for API to become available
  259. # Using curl here since the uri module requires python-httplib2 and
  260. # wait_for port doesn't provide health information.
  261. command: >
  262. curl --silent --tlsv1.2
  263. {% if openshift.common.version_gte_3_2_or_1_2 | bool %}
  264. --cacert {{ openshift.common.config_base }}/master/ca-bundle.crt
  265. {% else %}
  266. --cacert {{ openshift.common.config_base }}/master/ca.crt
  267. {% endif %}
  268. {{ openshift.master.api_url }}/healthz/ready
  269. register: l_api_available_output
  270. until: l_api_available_output.stdout == 'ok'
  271. retries: 120
  272. delay: 1
  273. run_once: true
  274. changed_when: false
  275. when:
  276. - openshift.master.cluster_method == 'native'
  277. - master_api_service_status_changed | bool
  278. - name: Start and enable master controller on first master
  279. systemd:
  280. name: "{{ openshift.common.service_type }}-master-controllers"
  281. enabled: yes
  282. state: started
  283. when:
  284. - openshift.master.cluster_method == 'native'
  285. - inventory_hostname == openshift_master_hosts[0]
  286. register: l_start_result
  287. until: not l_start_result | failed
  288. retries: 1
  289. delay: 60
  290. - name: Dump logs from master-controllers if it failed
  291. command: journalctl --no-pager -n 100 -u {{ openshift.common.service_type }}-master-controllers
  292. when:
  293. - l_start_result | failed
  294. - name: Wait for master controller service to start on first master
  295. pause:
  296. seconds: 15
  297. when:
  298. - openshift.master.cluster_method == 'native'
  299. - name: Start and enable master controller on all masters
  300. systemd:
  301. name: "{{ openshift.common.service_type }}-master-controllers"
  302. enabled: yes
  303. state: started
  304. when:
  305. - openshift.master.cluster_method == 'native'
  306. - inventory_hostname != openshift_master_hosts[0]
  307. register: l_start_result
  308. until: not l_start_result | failed
  309. retries: 1
  310. delay: 60
  311. - name: Dump logs from master-controllers if it failed
  312. command: journalctl --no-pager -n 100 -u {{ openshift.common.service_type }}-master-controllers
  313. when:
  314. - l_start_result | failed
  315. - set_fact:
  316. master_controllers_service_status_changed: "{{ l_start_result | changed }}"
  317. when:
  318. - openshift.master.cluster_method == 'native'
  319. - name: Install cluster packages
  320. package: name=pcs state=present
  321. when:
  322. - openshift.master.cluster_method == 'pacemaker'
  323. - not openshift.common.is_containerized | bool
  324. register: l_install_result
  325. - name: Start and enable cluster service
  326. systemd:
  327. name: pcsd
  328. enabled: yes
  329. state: started
  330. when:
  331. - openshift.master.cluster_method == 'pacemaker'
  332. - not openshift.common.is_containerized | bool
  333. - name: Set the cluster user password
  334. shell: echo {{ openshift_master_cluster_password | quote }} | passwd --stdin hacluster
  335. when:
  336. - l_install_result | changed
  337. - name: node bootstrap settings
  338. include: bootstrap.yml
  339. when: openshift_master_bootstrap_enabled | default(False)