config.yml 16 KB

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