main.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. - name: Install the systemd units
  115. include: systemd_units.yml
  116. - name: Install Master system container
  117. include: system_container.yml
  118. when: openshift.common.is_containerized | bool and openshift.common.is_master_system_container | bool
  119. - name: Create session secrets file
  120. template:
  121. dest: "{{ openshift.master.session_secrets_file }}"
  122. src: sessionSecretsFile.yaml.v1.j2
  123. owner: root
  124. group: root
  125. mode: 0600
  126. when: openshift.master.session_auth_secrets is defined and openshift.master.session_encryption_secrets is defined
  127. notify:
  128. - restart master
  129. - restart master api
  130. - set_fact:
  131. translated_identity_providers: "{{ openshift.master.identity_providers | translate_idps('v1', openshift.common.version, openshift.common.deployment_type) }}"
  132. # TODO: add the validate parameter when there is a validation command to run
  133. - name: Create master config
  134. template:
  135. dest: "{{ openshift_master_config_file }}"
  136. src: master.yaml.v1.j2
  137. backup: true
  138. owner: root
  139. group: root
  140. mode: 0600
  141. notify:
  142. - restart master
  143. - restart master api
  144. - restart master controllers
  145. - include: set_loopback_context.yml
  146. when: openshift.common.version_gte_3_2_or_1_2
  147. # TODO: Master startup can fail when ec2 transparently reallocates the block
  148. # storage, causing etcd writes to temporarily fail. Retry failures blindly just
  149. # once to allow time for this transient condition to to resolve and for systemd
  150. # to restart the master (which will eventually succeed).
  151. #
  152. # https://github.com/coreos/etcd/issues/3864
  153. # https://github.com/openshift/origin/issues/6065
  154. # https://github.com/openshift/origin/issues/6447
  155. - name: Start and enable master
  156. systemd:
  157. name: "{{ openshift.common.service_type }}-master"
  158. enabled: yes
  159. state: started
  160. when: not openshift_master_ha | bool
  161. register: start_result
  162. until: not start_result | failed
  163. retries: 1
  164. delay: 60
  165. notify: Verify API Server
  166. - name: Stop and disable non-HA master when running HA
  167. systemd:
  168. name: "{{ openshift.common.service_type }}-master"
  169. enabled: no
  170. state: stopped
  171. when: openshift_master_ha | bool
  172. register: task_result
  173. failed_when: task_result|failed and 'could not' not in task_result.msg|lower
  174. - set_fact:
  175. master_service_status_changed: "{{ start_result | changed }}"
  176. when: not openshift_master_ha | bool
  177. - name: Mask master service
  178. systemd:
  179. name: "{{ openshift.common.service_type }}-master"
  180. masked: yes
  181. when: >
  182. openshift_master_ha | bool and
  183. openshift.master.cluster_method == 'native' and
  184. not openshift.common.is_containerized | bool
  185. - name: Start and enable master api on first master
  186. systemd:
  187. name: "{{ openshift.common.service_type }}-master-api"
  188. enabled: yes
  189. state: started
  190. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native' and inventory_hostname == openshift_master_hosts[0]
  191. register: start_result
  192. until: not start_result | failed
  193. retries: 1
  194. delay: 60
  195. - set_fact:
  196. master_api_service_status_changed: "{{ start_result | changed }}"
  197. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native' and inventory_hostname == openshift_master_hosts[0]
  198. - pause:
  199. seconds: 15
  200. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native'
  201. - name: Start and enable master api all masters
  202. systemd:
  203. name: "{{ openshift.common.service_type }}-master-api"
  204. enabled: yes
  205. state: started
  206. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native' and inventory_hostname != openshift_master_hosts[0]
  207. register: start_result
  208. until: not start_result | failed
  209. retries: 1
  210. delay: 60
  211. - set_fact:
  212. master_api_service_status_changed: "{{ start_result | changed }}"
  213. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native' and inventory_hostname != openshift_master_hosts[0]
  214. # A separate wait is required here for native HA since notifies will
  215. # be resolved after all tasks in the role.
  216. - name: Wait for API to become available
  217. # Using curl here since the uri module requires python-httplib2 and
  218. # wait_for port doesn't provide health information.
  219. command: >
  220. curl --silent --tlsv1.2
  221. {% if openshift.common.version_gte_3_2_or_1_2 | bool %}
  222. --cacert {{ openshift.common.config_base }}/master/ca-bundle.crt
  223. {% else %}
  224. --cacert {{ openshift.common.config_base }}/master/ca.crt
  225. {% endif %}
  226. {{ openshift.master.api_url }}/healthz/ready
  227. register: api_available_output
  228. until: api_available_output.stdout == 'ok'
  229. retries: 120
  230. delay: 1
  231. run_once: true
  232. changed_when: false
  233. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native' and master_api_service_status_changed | bool
  234. - name: Start and enable master controller on first master
  235. systemd:
  236. name: "{{ openshift.common.service_type }}-master-controllers"
  237. enabled: yes
  238. state: started
  239. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native' and inventory_hostname == openshift_master_hosts[0]
  240. register: start_result
  241. until: not start_result | failed
  242. retries: 1
  243. delay: 60
  244. - name: Wait for master controller service to start on first master
  245. pause:
  246. seconds: 15
  247. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native'
  248. - name: Start and enable master controller on all masters
  249. systemd:
  250. name: "{{ openshift.common.service_type }}-master-controllers"
  251. enabled: yes
  252. state: started
  253. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native' and inventory_hostname != openshift_master_hosts[0]
  254. register: start_result
  255. until: not start_result | failed
  256. retries: 1
  257. delay: 60
  258. - set_fact:
  259. master_controllers_service_status_changed: "{{ start_result | changed }}"
  260. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native'
  261. - name: Install cluster packages
  262. package: name=pcs state=present
  263. when: openshift_master_ha | bool and openshift.master.cluster_method == 'pacemaker'
  264. and not openshift.common.is_containerized | bool
  265. register: install_result
  266. - name: Start and enable cluster service
  267. systemd:
  268. name: pcsd
  269. enabled: yes
  270. state: started
  271. when: openshift_master_ha | bool and openshift.master.cluster_method == 'pacemaker'
  272. and not openshift.common.is_containerized | bool
  273. - name: Set the cluster user password
  274. shell: echo {{ openshift_master_cluster_password | quote }} | passwd --stdin hacluster
  275. when: install_result | changed