main.yml 11 KB

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