config.yml 16 KB

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