config.yml 17 KB

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