main.yml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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:
  10. - openshift_master_oauth_grant_method is defined
  11. - openshift_master_oauth_grant_method not in openshift_master_valid_grant_methods
  12. # HA Variable Validation
  13. - fail:
  14. msg: "openshift_master_cluster_method must be set to either 'native' or 'pacemaker' for multi-master installations"
  15. when:
  16. - openshift.master.ha | bool
  17. - (openshift.master.cluster_method is not defined) or (openshift.master.cluster_method is defined and openshift.master.cluster_method not in ["native", "pacemaker"])
  18. - fail:
  19. msg: "'native' high availability is not supported for the requested OpenShift version"
  20. when:
  21. - openshift.master.ha | bool
  22. - openshift.master.cluster_method == "native"
  23. - not openshift.common.version_gte_3_1_or_1_1 | bool
  24. - fail:
  25. msg: "openshift_master_cluster_password must be set for multi-master installations"
  26. when:
  27. - openshift.master.ha | bool
  28. - openshift.master.cluster_method == "pacemaker"
  29. - openshift_master_cluster_password is not defined or not openshift_master_cluster_password
  30. - fail:
  31. msg: "Pacemaker based HA is not supported at this time when used with containerized installs"
  32. when:
  33. - openshift.master.ha | bool
  34. - openshift.master.cluster_method == "pacemaker"
  35. - openshift.common.is_containerized | bool
  36. - name: Open up firewall ports
  37. include: firewall.yml
  38. static: yes
  39. - name: Install Master package
  40. package:
  41. name: "{{ openshift.common.service_type }}-master{{ openshift_pkg_version | default('') | oo_image_tag_to_rpm_version(include_dash=True) }}"
  42. state: present
  43. when:
  44. - not openshift.common.is_containerized | bool
  45. - name: Create openshift.common.data_dir
  46. file:
  47. path: "{{ openshift.common.data_dir }}"
  48. state: directory
  49. mode: 0755
  50. owner: root
  51. group: root
  52. when:
  53. - openshift.common.is_containerized | bool
  54. - name: Reload systemd units
  55. command: systemctl daemon-reload
  56. when:
  57. - openshift.common.is_containerized | bool
  58. - name: Re-gather package dependent master facts
  59. openshift_facts:
  60. - name: Create config parent directory if it does not exist
  61. file:
  62. path: "{{ openshift_master_config_dir }}"
  63. state: directory
  64. - name: Create the policy file if it does not already exist
  65. command: >
  66. {{ openshift.common.client_binary }} adm create-bootstrap-policy-file
  67. --filename={{ openshift_master_policy }}
  68. args:
  69. creates: "{{ openshift_master_policy }}"
  70. notify:
  71. - restart master api
  72. - restart master controllers
  73. - name: Create the scheduler config
  74. copy:
  75. content: "{{ scheduler_config | to_nice_json }}"
  76. dest: "{{ openshift_master_scheduler_conf }}"
  77. backup: true
  78. notify:
  79. - restart master api
  80. - restart master controllers
  81. - name: Install httpd-tools if needed
  82. package: name=httpd-tools state=present
  83. when:
  84. - item.kind == 'HTPasswdPasswordIdentityProvider'
  85. - not openshift.common.is_atomic | bool
  86. with_items: "{{ openshift.master.identity_providers }}"
  87. - name: Ensure htpasswd directory exists
  88. file:
  89. path: "{{ item.filename | dirname }}"
  90. state: directory
  91. when:
  92. - item.kind == 'HTPasswdPasswordIdentityProvider'
  93. with_items: "{{ openshift.master.identity_providers }}"
  94. - name: Create the htpasswd file if needed
  95. template:
  96. dest: "{{ item.filename }}"
  97. src: htpasswd.j2
  98. backup: yes
  99. when:
  100. - item.kind == 'HTPasswdPasswordIdentityProvider'
  101. - openshift.master.manage_htpasswd | bool
  102. with_items: "{{ openshift.master.identity_providers }}"
  103. - name: Ensure htpasswd file exists
  104. copy:
  105. dest: "{{ item.filename }}"
  106. force: no
  107. content: ""
  108. mode: 0600
  109. when:
  110. - item.kind == 'HTPasswdPasswordIdentityProvider'
  111. with_items: "{{ openshift.master.identity_providers }}"
  112. - name: Create the ldap ca file if needed
  113. copy:
  114. dest: "{{ item.ca if 'ca' in item and '/' in item.ca else openshift_master_config_dir ~ '/' ~ item.ca | default('ldap_ca.crt') }}"
  115. content: "{{ openshift.master.ldap_ca }}"
  116. mode: 0600
  117. backup: yes
  118. when:
  119. - openshift.master.ldap_ca is defined
  120. - item.kind == 'LDAPPasswordIdentityProvider'
  121. with_items: "{{ openshift.master.identity_providers }}"
  122. - name: Create the openid ca file if needed
  123. copy:
  124. dest: "{{ item.ca if 'ca' in item and '/' in item.ca else openshift_master_config_dir ~ '/' ~ item.ca | default('openid_ca.crt') }}"
  125. content: "{{ openshift.master.openid_ca }}"
  126. mode: 0600
  127. backup: yes
  128. when:
  129. - openshift.master.openid_ca is defined
  130. - item.kind == 'OpenIDIdentityProvider'
  131. - item.ca | default('') != ''
  132. with_items: "{{ openshift.master.identity_providers }}"
  133. - name: Create the request header ca file if needed
  134. copy:
  135. dest: "{{ item.clientCA if 'clientCA' in item and '/' in item.clientCA else openshift_master_config_dir ~ '/' ~ item.clientCA | default('request_header_ca.crt') }}"
  136. content: "{{ openshift.master.request_header_ca }}"
  137. mode: 0600
  138. backup: yes
  139. when:
  140. - openshift.master.request_header_ca is defined
  141. - item.kind == 'RequestHeaderIdentityProvider'
  142. - item.clientCA | default('') != ''
  143. with_items: "{{ openshift.master.identity_providers }}"
  144. # This is an ugly hack to verify settings are in a file without modifying them with lineinfile.
  145. # The template file will stomp any other settings made.
  146. - block:
  147. - name: check whether our docker-registry setting exists in the env file
  148. command: "awk '/^OPENSHIFT_DEFAULT_REGISTRY=docker-registry.default.svc:5000/' /etc/sysconfig/{{ openshift.common.service_type }}-master"
  149. failed_when: false
  150. changed_when: false
  151. register: l_already_set
  152. - set_fact:
  153. openshift_push_via_dns: "{{ (openshift_use_dnsmasq | default(true) and openshift.common.version_gte_3_6) or (l_already_set.stdout is defined and l_already_set.stdout | match('OPENSHIFT_DEFAULT_REGISTRY=docker-registry.default.svc:5000')) }}"
  154. - name: Set fact of all etcd host IPs
  155. openshift_facts:
  156. role: common
  157. local_facts:
  158. no_proxy_etcd_host_ips: "{{ openshift_no_proxy_etcd_host_ips }}"
  159. - name: Remove the legacy master service if it exists
  160. include: clean_systemd_units.yml
  161. - name: Install the systemd units
  162. include: systemd_units.yml
  163. - name: Install Master system container
  164. include: system_container.yml
  165. when:
  166. - openshift.common.is_containerized | bool
  167. - openshift.common.is_master_system_container | bool
  168. - name: Create session secrets file
  169. template:
  170. dest: "{{ openshift.master.session_secrets_file }}"
  171. src: sessionSecretsFile.yaml.v1.j2
  172. owner: root
  173. group: root
  174. mode: 0600
  175. when:
  176. - openshift.master.session_auth_secrets is defined
  177. - openshift.master.session_encryption_secrets is defined
  178. notify:
  179. - restart master api
  180. - set_fact:
  181. translated_identity_providers: "{{ openshift.master.identity_providers | translate_idps('v1', openshift.common.version, openshift.common.deployment_type) }}"
  182. # TODO: add the validate parameter when there is a validation command to run
  183. - name: Create master config
  184. template:
  185. dest: "{{ openshift_master_config_file }}"
  186. src: master.yaml.v1.j2
  187. backup: true
  188. owner: root
  189. group: root
  190. mode: 0600
  191. notify:
  192. - restart master api
  193. - restart master controllers
  194. - name: modify controller args
  195. yedit:
  196. src: /etc/origin/master/master-config.yaml
  197. edits:
  198. - key: kubernetesMasterConfig.controllerArguments.cluster-signing-cert-file
  199. value:
  200. - /etc/origin/master/ca.crt
  201. - key: kubernetesMasterConfig.controllerArguments.cluster-signing-key-file
  202. value:
  203. - /etc/origin/master/ca.key
  204. notify:
  205. - restart master controllers
  206. when: openshift_master_bootstrap_enabled | default(False)
  207. - name: Check for credentials file for registry auth
  208. stat:
  209. path: "{{oreg_auth_credentials_path }}"
  210. when:
  211. - oreg_auth_user is defined
  212. register: master_oreg_auth_credentials_stat
  213. - name: Create credentials for registry auth
  214. command: "docker --config={{ oreg_auth_credentials_path }} login -u {{ oreg_auth_user }} -p {{ oreg_auth_password }} {{ oreg_host }}"
  215. when:
  216. - oreg_auth_user is defined
  217. - (not master_oreg_auth_credentials_stat.stat.exists or oreg_auth_credentials_replace) | bool
  218. notify:
  219. - restart master api
  220. - restart master controllers
  221. - include: set_loopback_context.yml
  222. when:
  223. - openshift.common.version_gte_3_2_or_1_2
  224. - name: Start and enable master api on first master
  225. systemd:
  226. name: "{{ openshift.common.service_type }}-master-api"
  227. enabled: yes
  228. state: started
  229. when:
  230. - openshift.master.cluster_method == 'native'
  231. - inventory_hostname == openshift_master_hosts[0]
  232. register: l_start_result
  233. until: not l_start_result | failed
  234. retries: 1
  235. delay: 60
  236. - name: Dump logs from master-api if it failed
  237. command: journalctl --no-pager -n 100 -u {{ openshift.common.service_type }}-master-api
  238. when:
  239. - l_start_result | failed
  240. - set_fact:
  241. master_api_service_status_changed: "{{ l_start_result | changed }}"
  242. when:
  243. - openshift.master.cluster_method == 'native'
  244. - inventory_hostname == openshift_master_hosts[0]
  245. - pause:
  246. seconds: 15
  247. when:
  248. - openshift.master.ha | bool
  249. - openshift.master.cluster_method == 'native'
  250. - name: Start and enable master api all masters
  251. systemd:
  252. name: "{{ openshift.common.service_type }}-master-api"
  253. enabled: yes
  254. state: started
  255. when:
  256. - openshift.master.cluster_method == 'native'
  257. - inventory_hostname != openshift_master_hosts[0]
  258. register: l_start_result
  259. until: not l_start_result | failed
  260. retries: 1
  261. delay: 60
  262. - name: Dump logs from master-api if it failed
  263. command: journalctl --no-pager -n 100 -u {{ openshift.common.service_type }}-master-api
  264. when:
  265. - l_start_result | failed
  266. - set_fact:
  267. master_api_service_status_changed: "{{ l_start_result | changed }}"
  268. when:
  269. - openshift.master.cluster_method == 'native'
  270. - inventory_hostname != openshift_master_hosts[0]
  271. # A separate wait is required here for native HA since notifies will
  272. # be resolved after all tasks in the role.
  273. - name: Wait for API to become available
  274. # Using curl here since the uri module requires python-httplib2 and
  275. # wait_for port doesn't provide health information.
  276. command: >
  277. curl --silent --tlsv1.2
  278. {% if openshift.common.version_gte_3_2_or_1_2 | bool %}
  279. --cacert {{ openshift.common.config_base }}/master/ca-bundle.crt
  280. {% else %}
  281. --cacert {{ openshift.common.config_base }}/master/ca.crt
  282. {% endif %}
  283. {{ openshift.master.api_url }}/healthz/ready
  284. register: l_api_available_output
  285. until: l_api_available_output.stdout == 'ok'
  286. retries: 120
  287. delay: 1
  288. run_once: true
  289. changed_when: false
  290. when:
  291. - openshift.master.cluster_method == 'native'
  292. - master_api_service_status_changed | bool
  293. - name: Start and enable master controller on first master
  294. systemd:
  295. name: "{{ openshift.common.service_type }}-master-controllers"
  296. enabled: yes
  297. state: started
  298. when:
  299. - openshift.master.cluster_method == 'native'
  300. - inventory_hostname == openshift_master_hosts[0]
  301. register: l_start_result
  302. until: not l_start_result | failed
  303. retries: 1
  304. delay: 60
  305. - name: Dump logs from master-controllers if it failed
  306. command: journalctl --no-pager -n 100 -u {{ openshift.common.service_type }}-master-controllers
  307. when:
  308. - l_start_result | failed
  309. - name: Wait for master controller service to start on first master
  310. pause:
  311. seconds: 15
  312. when:
  313. - openshift.master.cluster_method == 'native'
  314. - name: Start and enable master controller on all masters
  315. systemd:
  316. name: "{{ openshift.common.service_type }}-master-controllers"
  317. enabled: yes
  318. state: started
  319. when:
  320. - openshift.master.cluster_method == 'native'
  321. - inventory_hostname != openshift_master_hosts[0]
  322. register: l_start_result
  323. until: not l_start_result | failed
  324. retries: 1
  325. delay: 60
  326. - name: Dump logs from master-controllers if it failed
  327. command: journalctl --no-pager -n 100 -u {{ openshift.common.service_type }}-master-controllers
  328. when:
  329. - l_start_result | failed
  330. - set_fact:
  331. master_controllers_service_status_changed: "{{ l_start_result | changed }}"
  332. when:
  333. - openshift.master.cluster_method == 'native'
  334. - name: Install cluster packages
  335. package: name=pcs state=present
  336. when:
  337. - openshift.master.cluster_method == 'pacemaker'
  338. - not openshift.common.is_containerized | bool
  339. register: l_install_result
  340. - name: Start and enable cluster service
  341. systemd:
  342. name: pcsd
  343. enabled: yes
  344. state: started
  345. when:
  346. - openshift.master.cluster_method == 'pacemaker'
  347. - not openshift.common.is_containerized | bool
  348. - name: Set the cluster user password
  349. shell: echo {{ openshift_master_cluster_password | quote }} | passwd --stdin hacluster
  350. when:
  351. - l_install_result | changed
  352. - name: node bootstrap settings
  353. include: bootstrap.yml
  354. when: openshift_master_bootstrap_enabled | default(False)