config.yml 20 KB

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