main.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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 api
  53. - restart master controllers
  54. - name: Create the scheduler config
  55. copy:
  56. content: "{{ scheduler_config | to_nice_json }}"
  57. dest: "{{ openshift_master_scheduler_conf }}"
  58. backup: true
  59. notify:
  60. - restart master api
  61. - restart master controllers
  62. - name: Install httpd-tools if needed
  63. package: name=httpd-tools state=present
  64. when: (item.kind == 'HTPasswdPasswordIdentityProvider') and
  65. not openshift.common.is_atomic | bool
  66. with_items: "{{ openshift.master.identity_providers }}"
  67. - name: Ensure htpasswd directory exists
  68. file:
  69. path: "{{ item.filename | dirname }}"
  70. state: directory
  71. when: item.kind == 'HTPasswdPasswordIdentityProvider'
  72. with_items: "{{ openshift.master.identity_providers }}"
  73. - name: Create the htpasswd file if needed
  74. template:
  75. dest: "{{ item.filename }}"
  76. src: htpasswd.j2
  77. backup: yes
  78. when: item.kind == 'HTPasswdPasswordIdentityProvider' and openshift.master.manage_htpasswd | bool
  79. with_items: "{{ openshift.master.identity_providers }}"
  80. - name: Ensure htpasswd file exists
  81. copy:
  82. dest: "{{ item.filename }}"
  83. force: no
  84. content: ""
  85. mode: 0600
  86. when: item.kind == 'HTPasswdPasswordIdentityProvider'
  87. with_items: "{{ openshift.master.identity_providers }}"
  88. - name: Create the ldap ca file if needed
  89. copy:
  90. dest: "{{ item.ca if 'ca' in item and '/' in item.ca else openshift_master_config_dir ~ '/' ~ item.ca | default('ldap_ca.crt') }}"
  91. content: "{{ openshift.master.ldap_ca }}"
  92. mode: 0600
  93. backup: yes
  94. when: openshift.master.ldap_ca is defined and item.kind == 'LDAPPasswordIdentityProvider'
  95. with_items: "{{ openshift.master.identity_providers }}"
  96. - name: Create the openid ca file if needed
  97. copy:
  98. dest: "{{ item.ca if 'ca' in item and '/' in item.ca else openshift_master_config_dir ~ '/' ~ item.ca | default('openid_ca.crt') }}"
  99. content: "{{ openshift.master.openid_ca }}"
  100. mode: 0600
  101. backup: yes
  102. when: openshift.master.openid_ca is defined and item.kind == 'OpenIDIdentityProvider' and item.ca | default('') != ''
  103. with_items: "{{ openshift.master.identity_providers }}"
  104. - name: Create the request header ca file if needed
  105. copy:
  106. dest: "{{ item.clientCA if 'clientCA' in item and '/' in item.clientCA else openshift_master_config_dir ~ '/' ~ item.clientCA | default('request_header_ca.crt') }}"
  107. content: "{{ openshift.master.request_header_ca }}"
  108. mode: 0600
  109. backup: yes
  110. when: openshift.master.request_header_ca is defined and item.kind == 'RequestHeaderIdentityProvider' and item.clientCA | default('') != ''
  111. with_items: "{{ openshift.master.identity_providers }}"
  112. # This is an ugly hack to verify settings are in a file without modifying them with lineinfile.
  113. # The template file will stomp any other settings made.
  114. - block:
  115. - name: check whether our docker-registry setting exists in the env file
  116. command: "awk '/^OPENSHIFT_DEFAULT_REGISTRY=docker-registry.default.svc:5000/' /etc/sysconfig/{{ openshift.common.service_type }}-master"
  117. failed_when: false
  118. changed_when: false
  119. register: already_set
  120. - set_fact:
  121. openshift_push_via_dns: "{{ (openshift_use_dnsmasq | default(true) and openshift.common.version_gte_3_6) or (already_set.stdout is defined and already_set.stdout | match('OPENSHIFT_DEFAULT_REGISTRY=docker-registry.default.svc:5000')) }}"
  122. - name: Set fact of all etcd host IPs
  123. openshift_facts:
  124. role: common
  125. local_facts:
  126. no_proxy_etcd_host_ips: "{{ openshift_no_proxy_etcd_host_ips }}"
  127. - name: Install the systemd units
  128. include: systemd_units.yml
  129. - name: Install Master system container
  130. include: system_container.yml
  131. when: openshift.common.is_containerized | bool and openshift.common.is_master_system_container | bool
  132. - name: Create session secrets file
  133. template:
  134. dest: "{{ openshift.master.session_secrets_file }}"
  135. src: sessionSecretsFile.yaml.v1.j2
  136. owner: root
  137. group: root
  138. mode: 0600
  139. when: openshift.master.session_auth_secrets is defined and openshift.master.session_encryption_secrets is defined
  140. notify:
  141. - restart master api
  142. - set_fact:
  143. translated_identity_providers: "{{ openshift.master.identity_providers | translate_idps('v1', openshift.common.version, openshift.common.deployment_type) }}"
  144. # TODO: add the validate parameter when there is a validation command to run
  145. - name: Create master config
  146. template:
  147. dest: "{{ openshift_master_config_file }}"
  148. src: master.yaml.v1.j2
  149. backup: true
  150. owner: root
  151. group: root
  152. mode: 0600
  153. notify:
  154. - restart master api
  155. - restart master controllers
  156. - include: set_loopback_context.yml
  157. when: openshift.common.version_gte_3_2_or_1_2
  158. - name: Start and enable master api on first master
  159. systemd:
  160. name: "{{ openshift.common.service_type }}-master-api"
  161. enabled: yes
  162. state: started
  163. when: openshift.master.cluster_method == 'native' and inventory_hostname == openshift_master_hosts[0]
  164. register: start_result
  165. until: not start_result | failed
  166. retries: 1
  167. delay: 60
  168. - name: Dump logs from master-api if it failed
  169. command: journalctl --no-pager -n 100 -u {{ openshift.common.service_type }}-master-api
  170. when: start_result | failed
  171. - set_fact:
  172. master_api_service_status_changed: "{{ start_result | changed }}"
  173. when: openshift.master.cluster_method == 'native' and inventory_hostname == openshift_master_hosts[0]
  174. - pause:
  175. seconds: 15
  176. when: openshift.master.ha | bool and openshift.master.cluster_method == 'native'
  177. - name: Start and enable master api all masters
  178. systemd:
  179. name: "{{ openshift.common.service_type }}-master-api"
  180. enabled: yes
  181. state: started
  182. when: openshift.master.cluster_method == 'native' and inventory_hostname != openshift_master_hosts[0]
  183. register: start_result
  184. until: not start_result | failed
  185. retries: 1
  186. delay: 60
  187. - name: Dump logs from master-api if it failed
  188. command: journalctl --no-pager -n 100 -u {{ openshift.common.service_type }}-master-api
  189. when: start_result | failed
  190. - set_fact:
  191. master_api_service_status_changed: "{{ start_result | changed }}"
  192. when: openshift.master.cluster_method == 'native' and inventory_hostname != openshift_master_hosts[0]
  193. # A separate wait is required here for native HA since notifies will
  194. # be resolved after all tasks in the role.
  195. - name: Wait for API to become available
  196. # Using curl here since the uri module requires python-httplib2 and
  197. # wait_for port doesn't provide health information.
  198. command: >
  199. curl --silent --tlsv1.2
  200. {% if openshift.common.version_gte_3_2_or_1_2 | bool %}
  201. --cacert {{ openshift.common.config_base }}/master/ca-bundle.crt
  202. {% else %}
  203. --cacert {{ openshift.common.config_base }}/master/ca.crt
  204. {% endif %}
  205. {{ openshift.master.api_url }}/healthz/ready
  206. register: api_available_output
  207. until: api_available_output.stdout == 'ok'
  208. retries: 120
  209. delay: 1
  210. run_once: true
  211. changed_when: false
  212. when: openshift.master.cluster_method == 'native' and master_api_service_status_changed | bool
  213. - name: Start and enable master controller on first master
  214. systemd:
  215. name: "{{ openshift.common.service_type }}-master-controllers"
  216. enabled: yes
  217. state: started
  218. when: openshift.master.cluster_method == 'native' and inventory_hostname == openshift_master_hosts[0]
  219. register: start_result
  220. until: not start_result | failed
  221. retries: 1
  222. delay: 60
  223. - name: Dump logs from master-controllers if it failed
  224. command: journalctl --no-pager -n 100 -u {{ openshift.common.service_type }}-master-controllers
  225. when: start_result | failed
  226. - name: Wait for master controller service to start on first master
  227. pause:
  228. seconds: 15
  229. when: openshift.master.cluster_method == 'native'
  230. - name: Start and enable master controller on all masters
  231. systemd:
  232. name: "{{ openshift.common.service_type }}-master-controllers"
  233. enabled: yes
  234. state: started
  235. when: openshift.master.cluster_method == 'native' and inventory_hostname != openshift_master_hosts[0]
  236. register: start_result
  237. until: not start_result | failed
  238. retries: 1
  239. delay: 60
  240. - name: Dump logs from master-controllers if it failed
  241. command: journalctl --no-pager -n 100 -u {{ openshift.common.service_type }}-master-controllers
  242. when: start_result | failed
  243. - set_fact:
  244. master_controllers_service_status_changed: "{{ start_result | changed }}"
  245. when: openshift.master.cluster_method == 'native'
  246. - name: Install cluster packages
  247. package: name=pcs state=present
  248. when: openshift.master.cluster_method == 'pacemaker'
  249. and not openshift.common.is_containerized | bool
  250. register: install_result
  251. - name: Start and enable cluster service
  252. systemd:
  253. name: pcsd
  254. enabled: yes
  255. state: started
  256. when: openshift.master.cluster_method == 'pacemaker'
  257. and not openshift.common.is_containerized | bool
  258. - name: Set the cluster user password
  259. shell: echo {{ openshift_master_cluster_password | quote }} | passwd --stdin hacluster
  260. when: install_result | changed