main.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. - name: Configure master to use etcd3 storage backend on 3.6 clean installs
  146. yedit:
  147. src: /etc/origin/master/master-config.yaml
  148. key: "{{ item.key }}"
  149. value: "{{ item.value }}"
  150. with_items:
  151. - key: kubernetesMasterConfig.apiServerArguments.storage-backend
  152. value:
  153. - etcd3
  154. - key: kubernetesMasterConfig.apiServerArguments.storage-media-type
  155. value:
  156. - application/vnd.kubernetes.protobuf
  157. when:
  158. - r_openshift_master_clean_install
  159. - openshift.common.version_gte_3_6
  160. notify:
  161. - restart master
  162. - restart master api
  163. - restart master controllers
  164. - include: set_loopback_context.yml
  165. when: openshift.common.version_gte_3_2_or_1_2
  166. # TODO: Master startup can fail when ec2 transparently reallocates the block
  167. # storage, causing etcd writes to temporarily fail. Retry failures blindly just
  168. # once to allow time for this transient condition to to resolve and for systemd
  169. # to restart the master (which will eventually succeed).
  170. #
  171. # https://github.com/coreos/etcd/issues/3864
  172. # https://github.com/openshift/origin/issues/6065
  173. # https://github.com/openshift/origin/issues/6447
  174. - name: Start and enable master
  175. systemd:
  176. daemon_reload: yes
  177. name: "{{ openshift.common.service_type }}-master"
  178. enabled: yes
  179. state: started
  180. when: not openshift_master_ha | bool
  181. register: start_result
  182. until: not start_result | failed
  183. retries: 1
  184. delay: 60
  185. notify: Verify API Server
  186. - name: Stop and disable non-HA master when running HA
  187. systemd:
  188. name: "{{ openshift.common.service_type }}-master"
  189. enabled: no
  190. state: stopped
  191. when: openshift_master_ha | bool
  192. register: task_result
  193. failed_when: task_result|failed and 'could not' not in task_result.msg|lower
  194. - set_fact:
  195. master_service_status_changed: "{{ start_result | changed }}"
  196. when: not openshift_master_ha | bool
  197. - name: Mask master service
  198. systemd:
  199. name: "{{ openshift.common.service_type }}-master"
  200. masked: yes
  201. when: >
  202. openshift_master_ha | bool and
  203. openshift.master.cluster_method == 'native' and
  204. not openshift.common.is_containerized | bool
  205. - name: Start and enable master api on first master
  206. systemd:
  207. name: "{{ openshift.common.service_type }}-master-api"
  208. enabled: yes
  209. state: started
  210. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native' and inventory_hostname == openshift_master_hosts[0]
  211. register: start_result
  212. until: not start_result | failed
  213. retries: 1
  214. delay: 60
  215. - set_fact:
  216. master_api_service_status_changed: "{{ start_result | changed }}"
  217. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native' and inventory_hostname == openshift_master_hosts[0]
  218. - pause:
  219. seconds: 15
  220. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native'
  221. - name: Start and enable master api all masters
  222. systemd:
  223. name: "{{ openshift.common.service_type }}-master-api"
  224. enabled: yes
  225. state: started
  226. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native' and inventory_hostname != openshift_master_hosts[0]
  227. register: start_result
  228. until: not start_result | failed
  229. retries: 1
  230. delay: 60
  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: Wait for master controller service to start on first master
  265. pause:
  266. seconds: 15
  267. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native'
  268. - name: Start and enable master controller on all masters
  269. systemd:
  270. name: "{{ openshift.common.service_type }}-master-controllers"
  271. enabled: yes
  272. state: started
  273. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native' and inventory_hostname != openshift_master_hosts[0]
  274. register: start_result
  275. until: not start_result | failed
  276. retries: 1
  277. delay: 60
  278. - set_fact:
  279. master_controllers_service_status_changed: "{{ start_result | changed }}"
  280. when: openshift_master_ha | bool and openshift.master.cluster_method == 'native'
  281. - name: Install cluster packages
  282. package: name=pcs state=present
  283. when: openshift_master_ha | bool and openshift.master.cluster_method == 'pacemaker'
  284. and not openshift.common.is_containerized | bool
  285. register: install_result
  286. - name: Start and enable cluster service
  287. systemd:
  288. name: pcsd
  289. enabled: yes
  290. state: started
  291. when: openshift_master_ha | bool and openshift.master.cluster_method == 'pacemaker'
  292. and not openshift.common.is_containerized | bool
  293. - name: Set the cluster user password
  294. shell: echo {{ openshift_master_cluster_password | quote }} | passwd --stdin hacluster
  295. when: install_result | changed