main.yml 12 KB

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