main.yml 13 KB

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