config.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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) }}"
  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. roles:
  40. - openshift_facts
  41. post_tasks:
  42. - openshift_facts:
  43. role: master
  44. local_facts:
  45. api_port: "{{ openshift_master_api_port | default(None) }}"
  46. api_url: "{{ openshift_master_api_url | default(None) }}"
  47. api_use_ssl: "{{ openshift_master_api_use_ssl | default(None) }}"
  48. controllers_port: "{{ openshift_master_controllers_port | default(None) }}"
  49. public_api_url: "{{ openshift_master_public_api_url | default(None) }}"
  50. cluster_hostname: "{{ openshift_master_cluster_hostname | default(None) }}"
  51. cluster_public_hostname: "{{ openshift_master_cluster_public_hostname | default(None) }}"
  52. console_path: "{{ openshift_master_console_path | default(None) }}"
  53. console_port: "{{ openshift_master_console_port | default(None) }}"
  54. console_url: "{{ openshift_master_console_url | default(None) }}"
  55. console_use_ssl: "{{ openshift_master_console_use_ssl | default(None) }}"
  56. public_console_url: "{{ openshift_master_public_console_url | default(None) }}"
  57. portal_net: "{{ openshift_master_portal_net | default(None) }}"
  58. ha: "{{ openshift_master_ha | default(groups.oo_masters | length > 1) }}"
  59. master_count: "{{ openshift_master_count | default(groups.oo_masters | length) }}"
  60. - openshift_facts:
  61. role: hosted
  62. openshift_env:
  63. openshift_hosted_registry_storage_kind: 'nfs'
  64. 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
  65. - name: Check status of external etcd certificatees
  66. stat:
  67. path: "{{ openshift.common.config_base }}/master/{{ item }}"
  68. with_items:
  69. - master.etcd-client.crt
  70. - master.etcd-ca.crt
  71. register: g_external_etcd_cert_stat_result
  72. - set_fact:
  73. etcd_client_certs_missing: "{{ g_external_etcd_cert_stat_result.results
  74. | oo_collect(attribute='stat.exists')
  75. | list | intersect([false])}}"
  76. etcd_cert_subdir: openshift-master-{{ openshift.common.hostname }}
  77. etcd_cert_config_dir: "{{ openshift.common.config_base }}/master"
  78. etcd_cert_prefix: master.etcd-
  79. when: groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config
  80. - name: Create temp directory for syncing certs
  81. hosts: localhost
  82. connection: local
  83. become: no
  84. gather_facts: no
  85. tasks:
  86. - name: Create local temp directory for syncing certs
  87. local_action: command mktemp -d /tmp/openshift-ansible-XXXXXXX
  88. register: g_master_mktemp
  89. changed_when: False
  90. - name: Configure etcd certificates
  91. hosts: oo_first_etcd
  92. vars:
  93. etcd_generated_certs_dir: /etc/etcd/generated_certs
  94. etcd_needing_client_certs: "{{ hostvars
  95. | oo_select_keys(groups['oo_masters_to_config'])
  96. | default([])
  97. | oo_filter_list(filter_attr='etcd_client_certs_missing') }}"
  98. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  99. roles:
  100. - etcd_certificates
  101. post_tasks:
  102. - name: Create a tarball of the etcd certs
  103. command: >
  104. tar -czvf {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz
  105. -C {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }} .
  106. args:
  107. creates: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
  108. with_items: etcd_needing_client_certs
  109. - name: Retrieve the etcd cert tarballs
  110. fetch:
  111. src: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
  112. dest: "{{ sync_tmpdir }}/"
  113. flat: yes
  114. fail_on_missing: yes
  115. validate_checksum: yes
  116. with_items: etcd_needing_client_certs
  117. - name: Copy the external etcd certs to the masters
  118. hosts: oo_masters_to_config
  119. vars:
  120. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  121. tasks:
  122. - name: Ensure certificate directory exists
  123. file:
  124. path: "{{ openshift.common.config_base }}/master"
  125. state: directory
  126. when: etcd_client_certs_missing is defined and etcd_client_certs_missing
  127. - name: Unarchive the tarball on the master
  128. unarchive:
  129. src: "{{ sync_tmpdir }}/{{ etcd_cert_subdir }}.tgz"
  130. dest: "{{ etcd_cert_config_dir }}"
  131. when: etcd_client_certs_missing is defined and etcd_client_certs_missing
  132. - file:
  133. path: "{{ etcd_cert_config_dir }}/{{ item }}"
  134. owner: root
  135. group: root
  136. mode: 0600
  137. with_items:
  138. - master.etcd-client.crt
  139. - master.etcd-client.key
  140. - master.etcd-ca.crt
  141. when: etcd_client_certs_missing is defined and etcd_client_certs_missing
  142. - name: Determine if master certificates need to be generated
  143. hosts: oo_first_master:oo_masters_to_config
  144. tasks:
  145. - set_fact:
  146. openshift_master_certs_no_etcd:
  147. - admin.crt
  148. - master.kubelet-client.crt
  149. - "{{ 'master.proxy-client.crt' if openshift.common.version_gte_3_1_or_1_1 else omit }}"
  150. - master.server.crt
  151. - openshift-master.crt
  152. - openshift-registry.crt
  153. - openshift-router.crt
  154. - etcd.server.crt
  155. openshift_master_certs_etcd:
  156. - master.etcd-client.crt
  157. - set_fact:
  158. 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 }}"
  159. - name: Check status of master certificates
  160. stat:
  161. path: "{{ openshift.common.config_base }}/master/{{ item }}"
  162. with_items: openshift_master_certs
  163. register: g_master_cert_stat_result
  164. - set_fact:
  165. master_certs_missing: "{{ False in (g_master_cert_stat_result.results
  166. | oo_collect(attribute='stat.exists')
  167. | list ) }}"
  168. master_cert_subdir: master-{{ openshift.common.hostname }}
  169. master_cert_config_dir: "{{ openshift.common.config_base }}/master"
  170. - set_fact:
  171. openshift_infra_nodes: "{{ hostvars | oo_select_keys(groups['oo_nodes_to_config'])
  172. | oo_nodes_with_label('region', 'infra')
  173. | oo_collect('inventory_hostname') }}"
  174. when: openshift_infra_nodes is not defined and groups.oo_nodes_to_config | default([]) | length > 0
  175. - name: Configure master certificates
  176. hosts: oo_first_master
  177. vars:
  178. master_generated_certs_dir: "{{ openshift.common.config_base }}/generated-configs"
  179. masters_needing_certs: "{{ hostvars
  180. | oo_select_keys(groups['oo_masters_to_config'] | difference(groups['oo_first_master']))
  181. | oo_filter_list(filter_attr='master_certs_missing') }}"
  182. master_hostnames: "{{ hostvars
  183. | oo_select_keys(groups['oo_masters_to_config'])
  184. | oo_collect('openshift.common.all_hostnames')
  185. | oo_flatten | unique }}"
  186. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  187. roles:
  188. - openshift_master_certificates
  189. post_tasks:
  190. - name: Remove generated etcd client certs when using external etcd
  191. file:
  192. path: "{{ master_generated_certs_dir }}/{{ item.0.master_cert_subdir }}/{{ item.1 }}"
  193. state: absent
  194. when: groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config
  195. with_nested:
  196. - masters_needing_certs
  197. - - master.etcd-client.crt
  198. - master.etcd-client.key
  199. - name: Create a tarball of the master certs
  200. command: >
  201. tar -czvf {{ master_generated_certs_dir }}/{{ item.master_cert_subdir }}.tgz
  202. -C {{ master_generated_certs_dir }}/{{ item.master_cert_subdir }} .
  203. args:
  204. creates: "{{ master_generated_certs_dir }}/{{ item.master_cert_subdir }}.tgz"
  205. with_items: masters_needing_certs
  206. - name: Retrieve the master cert tarball from the master
  207. fetch:
  208. src: "{{ master_generated_certs_dir }}/{{ item.master_cert_subdir }}.tgz"
  209. dest: "{{ sync_tmpdir }}/"
  210. flat: yes
  211. fail_on_missing: yes
  212. validate_checksum: yes
  213. with_items: masters_needing_certs
  214. - name: Configure load balancers
  215. hosts: oo_lb_to_config
  216. vars:
  217. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  218. haproxy_limit_nofile: 100000
  219. haproxy_global_maxconn: 20000
  220. haproxy_default_maxconn: 20000
  221. haproxy_frontend_port: "{{ hostvars[groups.oo_first_master.0].openshift.master.api_port }}"
  222. haproxy_frontends:
  223. - name: atomic-openshift-api
  224. mode: tcp
  225. options:
  226. - tcplog
  227. binds:
  228. - "*:{{ hostvars[groups.oo_first_master.0].openshift.master.api_port }}"
  229. default_backend: atomic-openshift-api
  230. haproxy_backends:
  231. - name: atomic-openshift-api
  232. mode: tcp
  233. option: tcplog
  234. balance: source
  235. servers: "{{ hostvars | oo_select_keys(groups['oo_masters']) | oo_haproxy_backend_masters }}"
  236. roles:
  237. - role: openshift_facts
  238. - role: haproxy
  239. when: hostvars[groups.oo_first_master.0].openshift.master.ha | bool
  240. - name: Check for cached session secrets
  241. hosts: oo_first_master
  242. roles:
  243. - role: openshift_facts
  244. post_tasks:
  245. - openshift_facts:
  246. role: master
  247. local_facts:
  248. session_auth_secrets: "{{ openshift_master_session_auth_secrets | default(openshift.master.session_auth_secrets | default(None)) }}"
  249. session_encryption_secrets: "{{ openshift_master_session_encryption_secrets | default(openshift.master.session_encryption_secrets | default(None)) }}"
  250. - name: Generate master session secrets
  251. hosts: oo_first_master
  252. vars:
  253. g_session_secrets_present: "{{ (openshift.master.session_auth_secrets | default([]) and openshift.master.session_encryption_secrets | default([])) | length > 0 }}"
  254. g_session_auth_secrets: "{{ [ 24 | oo_generate_secret ] }}"
  255. g_session_encryption_secrets: "{{ [ 24 | oo_generate_secret ] }}"
  256. roles:
  257. - role: openshift_facts
  258. tasks:
  259. - openshift_facts:
  260. role: master
  261. local_facts:
  262. session_auth_secrets: "{{ g_session_auth_secrets }}"
  263. session_encryption_secrets: "{{ g_session_encryption_secrets }}"
  264. when: not g_session_secrets_present | bool
  265. - name: Parse named certificates
  266. hosts: localhost
  267. connection: local
  268. become: no
  269. vars:
  270. internal_hostnames: "{{ hostvars[groups.oo_first_master.0].openshift.common.internal_hostnames }}"
  271. named_certificates: "{{ hostvars[groups.oo_first_master.0].openshift_master_named_certificates | default([]) }}"
  272. named_certificates_dir: "{{ hostvars[groups.oo_first_master.0].master_cert_config_dir }}/named_certificates/"
  273. tasks:
  274. - set_fact:
  275. parsed_named_certificates: "{{ named_certificates | oo_parse_named_certificates(named_certificates_dir, internal_hostnames) }}"
  276. when: named_certificates | length > 0
  277. - name: Deploy named certificates
  278. hosts: oo_masters_to_config
  279. vars:
  280. named_certs_dir: "{{ master_cert_config_dir }}/named_certificates/"
  281. named_certs_specified: "{{ openshift_master_named_certificates is defined }}"
  282. overwrite_named_certs: "{{ openshift_master_overwrite_named_certificates | default(false) }}"
  283. roles:
  284. - role: openshift_facts
  285. post_tasks:
  286. - openshift_facts:
  287. role: master
  288. local_facts:
  289. named_certificates: "{{ hostvars.localhost.parsed_named_certificates | default([]) }}"
  290. additive_facts_to_overwrite:
  291. - "{{ 'master.named_certificates' if overwrite_named_certs | bool else omit }}"
  292. - name: Clear named certificates
  293. file:
  294. path: "{{ named_certs_dir }}"
  295. state: absent
  296. when: overwrite_named_certs | bool
  297. - name: Ensure named certificate directory exists
  298. file:
  299. path: "{{ named_certs_dir }}"
  300. state: directory
  301. mode: 0700
  302. when: named_certs_specified | bool
  303. - name: Land named certificates
  304. copy: src="{{ item.certfile }}" dest="{{ named_certs_dir }}"
  305. with_items: openshift_master_named_certificates
  306. when: named_certs_specified | bool
  307. - name: Land named certificate keys
  308. copy: src="{{ item.keyfile }}" dest="{{ named_certs_dir }}" mode=0600
  309. with_items: openshift_master_named_certificates
  310. when: named_certs_specified | bool
  311. - name: Configure master instances
  312. hosts: oo_masters_to_config
  313. any_errors_fatal: true
  314. serial: 1
  315. vars:
  316. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  317. openshift_master_ha: "{{ openshift.master.ha }}"
  318. openshift_master_count: "{{ openshift.master.master_count }}"
  319. openshift_master_session_auth_secrets: "{{ hostvars[groups.oo_first_master.0].openshift.master.session_auth_secrets }}"
  320. openshift_master_session_encryption_secrets: "{{ hostvars[groups.oo_first_master.0].openshift.master.session_encryption_secrets }}"
  321. pre_tasks:
  322. - name: Ensure certificate directory exists
  323. file:
  324. path: "{{ openshift.common.config_base }}/master"
  325. state: directory
  326. when: master_certs_missing | bool and 'oo_first_master' not in group_names
  327. - name: Unarchive the tarball on the master
  328. unarchive:
  329. src: "{{ sync_tmpdir }}/{{ master_cert_subdir }}.tgz"
  330. dest: "{{ master_cert_config_dir }}"
  331. when: master_certs_missing | bool and 'oo_first_master' not in group_names
  332. roles:
  333. - openshift_master
  334. - role: nickhammond.logrotate
  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. # Additional instance config for online deployments
  342. - name: Additional instance config
  343. hosts: oo_masters_deployment_type_online
  344. roles:
  345. - pods
  346. - os_env_extras
  347. - name: Delete temporary directory on localhost
  348. hosts: localhost
  349. connection: local
  350. become: no
  351. gather_facts: no
  352. tasks:
  353. - file: name={{ g_master_mktemp.stdout }} state=absent
  354. changed_when: False