config.yml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. ---
  2. - name: Set master facts and determine if external etcd certs need to be generated
  3. hosts: oo_masters_to_config
  4. pre_tasks:
  5. - name: Check for RPM generated config marker file .config_managed
  6. stat:
  7. path: /etc/origin/.config_managed
  8. register: rpmgenerated_config
  9. - name: Remove RPM generated config files if present
  10. file:
  11. path: "/etc/origin/{{ item }}"
  12. state: absent
  13. when: rpmgenerated_config.stat.exists == true and deployment_type in ['openshift-enterprise', 'atomic-enterprise']
  14. with_items:
  15. - master
  16. - node
  17. - .config_managed
  18. - set_fact:
  19. openshift_master_pod_eviction_timeout: "{{ lookup('oo_option', 'openshift_master_pod_eviction_timeout') | default(none, true) }}"
  20. when: openshift_master_pod_eviction_timeout is not defined
  21. - set_fact:
  22. openshift_master_etcd_port: "{{ (etcd_client_port | default('2379')) if (groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config) else none }}"
  23. openshift_master_etcd_hosts: "{{ hostvars
  24. | oo_select_keys(groups['oo_etcd_to_config']
  25. | default([]))
  26. | oo_collect('openshift.common.hostname')
  27. | default(none, true) }}"
  28. roles:
  29. - openshift_facts
  30. post_tasks:
  31. - openshift_facts:
  32. role: "{{ item.role }}"
  33. local_facts: "{{ item.local_facts }}"
  34. with_items:
  35. - role: common
  36. local_facts:
  37. hostname: "{{ openshift_hostname | default(None) }}"
  38. ip: "{{ openshift_ip | default(None) }}"
  39. public_hostname: "{{ openshift_public_hostname | default(None) }}"
  40. public_ip: "{{ openshift_public_ip | default(None) }}"
  41. deployment_type: "{{ openshift_deployment_type }}"
  42. - role: master
  43. local_facts:
  44. api_port: "{{ openshift_master_api_port | default(None) }}"
  45. api_url: "{{ openshift_master_api_url | default(None) }}"
  46. api_use_ssl: "{{ openshift_master_api_use_ssl | default(None) }}"
  47. controllers_port: "{{ openshift_master_controllers_port | default(None) }}"
  48. public_api_url: "{{ openshift_master_public_api_url | default(None) }}"
  49. cluster_hostname: "{{ openshift_master_cluster_hostname | default(None) }}"
  50. cluster_public_hostname: "{{ openshift_master_cluster_public_hostname | default(None) }}"
  51. console_path: "{{ openshift_master_console_path | default(None) }}"
  52. console_port: "{{ openshift_master_console_port | default(None) }}"
  53. console_url: "{{ openshift_master_console_url | default(None) }}"
  54. console_use_ssl: "{{ openshift_master_console_use_ssl | default(None) }}"
  55. public_console_url: "{{ openshift_master_public_console_url | default(None) }}"
  56. portal_net: "{{ openshift_master_portal_net | default(None) }}"
  57. - openshift_facts:
  58. role: hosted
  59. openshift_env:
  60. openshift_hosted_registry_storage_kind: 'nfs'
  61. when: openshift_hosted_registry_storage_kind is not defined and groups.oo_nfs_to_config is defined and groups.oo_nfs_to_config | length > 0
  62. - name: Check status of external etcd certificatees
  63. stat:
  64. path: "{{ openshift.common.config_base }}/master/{{ item }}"
  65. with_items:
  66. - master.etcd-client.crt
  67. - master.etcd-ca.crt
  68. register: g_external_etcd_cert_stat_result
  69. - set_fact:
  70. etcd_client_certs_missing: "{{ g_external_etcd_cert_stat_result.results
  71. | oo_collect(attribute='stat.exists')
  72. | list | intersect([false])}}"
  73. etcd_cert_subdir: openshift-master-{{ openshift.common.hostname }}
  74. etcd_cert_config_dir: "{{ openshift.common.config_base }}/master"
  75. etcd_cert_prefix: master.etcd-
  76. when: groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config
  77. - name: Create temp directory for syncing certs
  78. hosts: localhost
  79. connection: local
  80. become: no
  81. gather_facts: no
  82. tasks:
  83. - name: Create local temp directory for syncing certs
  84. local_action: command mktemp -d /tmp/openshift-ansible-XXXXXXX
  85. register: g_master_mktemp
  86. changed_when: False
  87. - name: Configure etcd certificates
  88. hosts: oo_first_etcd
  89. vars:
  90. etcd_generated_certs_dir: /etc/etcd/generated_certs
  91. etcd_needing_client_certs: "{{ hostvars
  92. | oo_select_keys(groups['oo_masters_to_config'])
  93. | default([])
  94. | oo_filter_list(filter_attr='etcd_client_certs_missing') }}"
  95. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  96. roles:
  97. - etcd_certificates
  98. post_tasks:
  99. - name: Create a tarball of the etcd certs
  100. command: >
  101. tar -czvf {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz
  102. -C {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }} .
  103. args:
  104. creates: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
  105. with_items: etcd_needing_client_certs
  106. - name: Retrieve the etcd cert tarballs
  107. fetch:
  108. src: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
  109. dest: "{{ sync_tmpdir }}/"
  110. flat: yes
  111. fail_on_missing: yes
  112. validate_checksum: yes
  113. with_items: etcd_needing_client_certs
  114. - name: Copy the external etcd certs to the masters
  115. hosts: oo_masters_to_config
  116. vars:
  117. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  118. tasks:
  119. - name: Ensure certificate directory exists
  120. file:
  121. path: "{{ openshift.common.config_base }}/master"
  122. state: directory
  123. when: etcd_client_certs_missing is defined and etcd_client_certs_missing
  124. - name: Unarchive the tarball on the master
  125. unarchive:
  126. src: "{{ sync_tmpdir }}/{{ etcd_cert_subdir }}.tgz"
  127. dest: "{{ etcd_cert_config_dir }}"
  128. when: etcd_client_certs_missing is defined and etcd_client_certs_missing
  129. - file:
  130. path: "{{ etcd_cert_config_dir }}/{{ item }}"
  131. owner: root
  132. group: root
  133. mode: 0600
  134. with_items:
  135. - master.etcd-client.crt
  136. - master.etcd-client.key
  137. - master.etcd-ca.crt
  138. when: etcd_client_certs_missing is defined and etcd_client_certs_missing
  139. - name: Determine if master certificates need to be generated
  140. hosts: oo_masters_to_config
  141. tasks:
  142. - set_fact:
  143. openshift_master_certs_no_etcd:
  144. - admin.crt
  145. - master.kubelet-client.crt
  146. - "{{ 'master.proxy-client.crt' if openshift.common.version_greater_than_3_1_or_1_1 else omit }}"
  147. - master.server.crt
  148. - openshift-master.crt
  149. - openshift-registry.crt
  150. - openshift-router.crt
  151. - etcd.server.crt
  152. openshift_master_certs_etcd:
  153. - master.etcd-client.crt
  154. - set_fact:
  155. openshift_master_certs: "{{ (openshift_master_certs_no_etcd | union(openshift_master_certs_etcd)) if (groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config) else openshift_master_certs_no_etcd }}"
  156. - name: Check status of master certificates
  157. stat:
  158. path: "{{ openshift.common.config_base }}/master/{{ item }}"
  159. with_items: openshift_master_certs
  160. register: g_master_cert_stat_result
  161. - set_fact:
  162. master_certs_missing: "{{ False in (g_master_cert_stat_result.results
  163. | oo_collect(attribute='stat.exists')
  164. | list ) }}"
  165. master_cert_subdir: master-{{ openshift.common.hostname }}
  166. master_cert_config_dir: "{{ openshift.common.config_base }}/master"
  167. - set_fact:
  168. openshift_infra_nodes: "{{ hostvars | oo_select_keys(groups['nodes'])
  169. | oo_nodes_with_label('region', 'infra')
  170. | oo_collect('inventory_hostname') }}"
  171. when: openshift_infra_nodes is not defined
  172. - name: Configure master certificates
  173. hosts: oo_first_master
  174. vars:
  175. master_generated_certs_dir: "{{ openshift.common.config_base }}/generated-configs"
  176. masters_needing_certs: "{{ hostvars
  177. | oo_select_keys(groups['oo_masters_to_config'] | difference(groups['oo_first_master']))
  178. | oo_filter_list(filter_attr='master_certs_missing') }}"
  179. master_hostnames: "{{ hostvars
  180. | oo_select_keys(groups['oo_masters_to_config'])
  181. | oo_collect('openshift.common.all_hostnames')
  182. | oo_flatten | unique }}"
  183. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  184. roles:
  185. - openshift_master_certificates
  186. post_tasks:
  187. - name: Remove generated etcd client certs when using external etcd
  188. file:
  189. path: "{{ master_generated_certs_dir }}/{{ item.0.master_cert_subdir }}/{{ item.1 }}"
  190. state: absent
  191. when: groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config
  192. with_nested:
  193. - masters_needing_certs
  194. - - master.etcd-client.crt
  195. - master.etcd-client.key
  196. - name: Create a tarball of the master certs
  197. command: >
  198. tar -czvf {{ master_generated_certs_dir }}/{{ item.master_cert_subdir }}.tgz
  199. -C {{ master_generated_certs_dir }}/{{ item.master_cert_subdir }} .
  200. args:
  201. creates: "{{ master_generated_certs_dir }}/{{ item.master_cert_subdir }}.tgz"
  202. with_items: masters_needing_certs
  203. - name: Retrieve the master cert tarball from the master
  204. fetch:
  205. src: "{{ master_generated_certs_dir }}/{{ item.master_cert_subdir }}.tgz"
  206. dest: "{{ sync_tmpdir }}/"
  207. flat: yes
  208. fail_on_missing: yes
  209. validate_checksum: yes
  210. with_items: masters_needing_certs
  211. - name: Compute haproxy_backend_servers
  212. hosts: localhost
  213. connection: local
  214. become: no
  215. gather_facts: no
  216. tasks:
  217. - set_fact:
  218. haproxy_backend_servers: "{{ hostvars | oo_select_keys(groups['oo_masters_to_config']) | oo_haproxy_backend_masters }}"
  219. - name: Configure load balancers
  220. hosts: oo_lb_to_config
  221. vars:
  222. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  223. haproxy_frontend_port: "{{ hostvars[groups.oo_first_master.0].openshift.master.api_port }}"
  224. haproxy_frontends:
  225. - name: atomic-openshift-api
  226. mode: tcp
  227. options:
  228. - tcplog
  229. binds:
  230. - "*:{{ hostvars[groups.oo_first_master.0].openshift.master.api_port }}"
  231. default_backend: atomic-openshift-api
  232. haproxy_backends:
  233. - name: atomic-openshift-api
  234. mode: tcp
  235. option: tcplog
  236. balance: source
  237. servers: "{{ hostvars.localhost.haproxy_backend_servers }}"
  238. roles:
  239. - role: openshift_facts
  240. - role: haproxy
  241. when: groups.oo_masters_to_config | length > 1
  242. - name: Check for cached session secrets
  243. hosts: oo_first_master
  244. roles:
  245. - role: openshift_facts
  246. post_tasks:
  247. - openshift_facts:
  248. role: master
  249. local_facts:
  250. session_auth_secrets: "{{ openshift_master_session_auth_secrets | default(openshift.master.session_auth_secrets | default(None)) }}"
  251. session_encryption_secrets: "{{ openshift_master_session_encryption_secrets | default(openshift.master.session_encryption_secrets | default(None)) }}"
  252. - name: Generate master session secrets
  253. hosts: oo_first_master
  254. vars:
  255. g_session_secrets_present: "{{ (openshift.master.session_auth_secrets | default([]) and openshift.master.session_encryption_secrets | default([])) | length > 0 }}"
  256. g_session_auth_secrets: "{{ [ 24 | oo_generate_secret ] }}"
  257. g_session_encryption_secrets: "{{ [ 24 | oo_generate_secret ] }}"
  258. roles:
  259. - role: openshift_facts
  260. tasks:
  261. - openshift_facts:
  262. role: master
  263. local_facts:
  264. session_auth_secrets: "{{ g_session_auth_secrets }}"
  265. session_encryption_secrets: "{{ g_session_encryption_secrets }}"
  266. when: not g_session_secrets_present | bool
  267. - name: Parse named certificates
  268. hosts: localhost
  269. connection: local
  270. become: no
  271. vars:
  272. internal_hostnames: "{{ hostvars[groups.oo_first_master.0].openshift.common.internal_hostnames }}"
  273. named_certificates: "{{ hostvars[groups.oo_first_master.0].openshift_master_named_certificates | default([]) }}"
  274. named_certificates_dir: "{{ hostvars[groups.oo_first_master.0].master_cert_config_dir }}/named_certificates/"
  275. tasks:
  276. - set_fact:
  277. parsed_named_certificates: "{{ named_certificates | oo_parse_named_certificates(named_certificates_dir, internal_hostnames) }}"
  278. when: named_certificates | length > 0
  279. - name: Deploy named certificates
  280. hosts: oo_masters_to_config
  281. vars:
  282. named_certs_dir: "{{ master_cert_config_dir }}/named_certificates/"
  283. named_certs_specified: "{{ openshift_master_named_certificates is defined }}"
  284. overwrite_named_certs: "{{ openshift_master_overwrite_named_certificates | default(false) }}"
  285. roles:
  286. - role: openshift_facts
  287. post_tasks:
  288. - openshift_facts:
  289. role: master
  290. local_facts:
  291. named_certificates: "{{ hostvars.localhost.parsed_named_certificates | default([]) }}"
  292. additive_facts_to_overwrite:
  293. - "{{ 'master.named_certificates' if overwrite_named_certs | bool else omit }}"
  294. - name: Clear named certificates
  295. file:
  296. path: "{{ named_certs_dir }}"
  297. state: absent
  298. when: overwrite_named_certs | bool
  299. - name: Ensure named certificate directory exists
  300. file:
  301. path: "{{ named_certs_dir }}"
  302. state: directory
  303. when: named_certs_specified | bool
  304. - name: Land named certificates
  305. copy: src="{{ item.certfile }}" dest="{{ named_certs_dir }}"
  306. with_items: openshift_master_named_certificates
  307. when: named_certs_specified | bool
  308. - name: Land named certificate keys
  309. copy: src="{{ item.keyfile }}" dest="{{ named_certs_dir }}"
  310. with_items: openshift_master_named_certificates
  311. when: named_certs_specified | bool
  312. - name: Configure master instances
  313. hosts: oo_masters_to_config
  314. any_errors_fatal: true
  315. serial: 1
  316. vars:
  317. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  318. openshift_master_ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  319. openshift_master_count: "{{ groups.oo_masters_to_config | length }}"
  320. openshift_master_session_auth_secrets: "{{ hostvars[groups.oo_first_master.0].openshift.master.session_auth_secrets }}"
  321. openshift_master_session_encryption_secrets: "{{ hostvars[groups.oo_first_master.0].openshift.master.session_encryption_secrets }}"
  322. pre_tasks:
  323. - name: Ensure certificate directory exists
  324. file:
  325. path: "{{ openshift.common.config_base }}/master"
  326. state: directory
  327. when: master_certs_missing and 'oo_first_master' not in group_names
  328. - name: Unarchive the tarball on the master
  329. unarchive:
  330. src: "{{ sync_tmpdir }}/{{ master_cert_subdir }}.tgz"
  331. dest: "{{ master_cert_config_dir }}"
  332. when: master_certs_missing and 'oo_first_master' not in group_names
  333. roles:
  334. - openshift_master
  335. - role: nickhammond.logrotate
  336. - role: fluentd_master
  337. when: openshift.common.use_fluentd | bool
  338. - role: nuage_master
  339. when: openshift.common.use_nuage | bool
  340. post_tasks:
  341. - name: Create group for deployment type
  342. group_by: key=oo_masters_deployment_type_{{ openshift.common.deployment_type }}
  343. changed_when: False
  344. - name: Additional master configuration
  345. hosts: oo_first_master
  346. vars:
  347. openshift_master_ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  348. omc_cluster_hosts: "{{ groups.oo_masters_to_config | join(' ')}}"
  349. roles:
  350. - role: openshift_master_cluster
  351. when: openshift_master_ha | bool and openshift.master.cluster_method == "pacemaker"
  352. - role: openshift_examples
  353. when: openshift.common.install_examples | bool
  354. - role: openshift_cluster_metrics
  355. when: openshift.common.use_cluster_metrics | bool
  356. - role: openshift_manageiq
  357. when: openshift.common.use_manageiq | bool
  358. - name: Enable cockpit
  359. hosts: oo_first_master
  360. vars:
  361. cockpit_plugins: "{{ osm_cockpit_plugins | default(['cockpit-kubernetes']) }}"
  362. roles:
  363. - role: cockpit
  364. when: not openshift.common.is_atomic and ( deployment_type in ['atomic-enterprise','openshift-enterprise'] ) and
  365. (osm_use_cockpit | bool or osm_use_cockpit is undefined )
  366. - name: Configure flannel
  367. hosts: oo_first_master
  368. vars:
  369. etcd_urls: "{{ openshift.master.etcd_urls }}"
  370. roles:
  371. - role: flannel_register
  372. when: openshift.common.use_flannel | bool
  373. # Additional instance config for online deployments
  374. - name: Additional instance config
  375. hosts: oo_masters_deployment_type_online
  376. roles:
  377. - pods
  378. - os_env_extras
  379. - name: Delete temporary directory on localhost
  380. hosts: localhost
  381. connection: local
  382. become: no
  383. gather_facts: no
  384. tasks:
  385. - file: name={{ g_master_mktemp.stdout }} state=absent
  386. changed_when: False
  387. - name: Configure service accounts
  388. hosts: oo_first_master
  389. vars:
  390. accounts: ["router", "registry"]
  391. roles:
  392. - openshift_serviceaccounts
  393. - name: Create persistent volumes and services
  394. hosts: oo_first_master
  395. vars:
  396. persistent_volumes: "{{ hostvars[groups.oo_first_master.0] | oo_persistent_volumes(groups) }}"
  397. persistent_volume_claims: "{{ hostvars[groups.oo_first_master.0] | oo_persistent_volume_claims }}"
  398. roles:
  399. - role: openshift_persistent_volumes
  400. when: persistent_volumes | length > 0 or persistent_volume_claims | length > 0
  401. - role: openshift_router
  402. when: openshift.master.infra_nodes is defined
  403. - role: openshift_registry
  404. when: openshift.master.infra_nodes is defined and openshift.hosted.registry.storage.kind != None