config.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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: master
  38. local_facts:
  39. api_port: "{{ openshift_master_api_port | default(None) }}"
  40. api_url: "{{ openshift_master_api_url | default(None) }}"
  41. api_use_ssl: "{{ openshift_master_api_use_ssl | default(None) }}"
  42. controllers_port: "{{ openshift_master_controllers_port | default(None) }}"
  43. public_api_url: "{{ openshift_master_public_api_url | default(None) }}"
  44. cluster_hostname: "{{ openshift_master_cluster_hostname | default(None) }}"
  45. cluster_public_hostname: "{{ openshift_master_cluster_public_hostname | default(None) }}"
  46. console_path: "{{ openshift_master_console_path | default(None) }}"
  47. console_port: "{{ openshift_master_console_port | default(None) }}"
  48. console_url: "{{ openshift_master_console_url | default(None) }}"
  49. console_use_ssl: "{{ openshift_master_console_use_ssl | default(None) }}"
  50. public_console_url: "{{ openshift_master_public_console_url | default(None) }}"
  51. portal_net: "{{ openshift_master_portal_net | default(None) }}"
  52. ha: "{{ openshift_master_ha | default(groups.oo_masters | length > 1) }}"
  53. master_count: "{{ openshift_master_count | default(groups.oo_masters | length) }}"
  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_first_master: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_gte_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['oo_nodes_to_config'])
  166. | oo_nodes_with_label('region', 'infra')
  167. | oo_collect('inventory_hostname') }}"
  168. when: openshift_infra_nodes is not defined and groups.oo_nodes_to_config | default([]) | length > 0
  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: Configure load balancers
  209. hosts: oo_lb_to_config
  210. vars:
  211. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  212. haproxy_limit_nofile: 100000
  213. haproxy_global_maxconn: 20000
  214. haproxy_default_maxconn: 20000
  215. haproxy_frontend_port: "{{ hostvars[groups.oo_first_master.0].openshift.master.api_port }}"
  216. haproxy_frontends:
  217. - name: atomic-openshift-api
  218. mode: tcp
  219. options:
  220. - tcplog
  221. binds:
  222. - "*:{{ hostvars[groups.oo_first_master.0].openshift.master.api_port }}"
  223. default_backend: atomic-openshift-api
  224. haproxy_backends:
  225. - name: atomic-openshift-api
  226. mode: tcp
  227. option: tcplog
  228. balance: source
  229. servers: "{{ hostvars | oo_select_keys(groups['oo_masters']) | oo_haproxy_backend_masters }}"
  230. roles:
  231. - role: openshift_facts
  232. - role: haproxy
  233. when: hostvars[groups.oo_first_master.0].openshift.master.ha | bool
  234. - name: Check for cached session secrets
  235. hosts: oo_first_master
  236. roles:
  237. - role: openshift_facts
  238. post_tasks:
  239. - openshift_facts:
  240. role: master
  241. local_facts:
  242. session_auth_secrets: "{{ openshift_master_session_auth_secrets | default(openshift.master.session_auth_secrets | default(None)) }}"
  243. session_encryption_secrets: "{{ openshift_master_session_encryption_secrets | default(openshift.master.session_encryption_secrets | default(None)) }}"
  244. - name: Generate master session secrets
  245. hosts: oo_first_master
  246. vars:
  247. g_session_secrets_present: "{{ (openshift.master.session_auth_secrets | default([]) and openshift.master.session_encryption_secrets | default([])) | length > 0 }}"
  248. g_session_auth_secrets: "{{ [ 24 | oo_generate_secret ] }}"
  249. g_session_encryption_secrets: "{{ [ 24 | oo_generate_secret ] }}"
  250. roles:
  251. - role: openshift_facts
  252. tasks:
  253. - openshift_facts:
  254. role: master
  255. local_facts:
  256. session_auth_secrets: "{{ g_session_auth_secrets }}"
  257. session_encryption_secrets: "{{ g_session_encryption_secrets }}"
  258. when: not g_session_secrets_present | bool
  259. - name: Parse named certificates
  260. hosts: localhost
  261. connection: local
  262. become: no
  263. vars:
  264. internal_hostnames: "{{ hostvars[groups.oo_first_master.0].openshift.common.internal_hostnames }}"
  265. named_certificates: "{{ hostvars[groups.oo_first_master.0].openshift_master_named_certificates | default([]) }}"
  266. named_certificates_dir: "{{ hostvars[groups.oo_first_master.0].master_cert_config_dir }}/named_certificates/"
  267. tasks:
  268. - set_fact:
  269. parsed_named_certificates: "{{ named_certificates | oo_parse_named_certificates(named_certificates_dir, internal_hostnames) }}"
  270. when: named_certificates | length > 0
  271. - name: Deploy named certificates
  272. hosts: oo_masters_to_config
  273. vars:
  274. named_certs_dir: "{{ master_cert_config_dir }}/named_certificates/"
  275. named_certs_specified: "{{ openshift_master_named_certificates is defined }}"
  276. overwrite_named_certs: "{{ openshift_master_overwrite_named_certificates | default(false) }}"
  277. roles:
  278. - role: openshift_facts
  279. post_tasks:
  280. - openshift_facts:
  281. role: master
  282. local_facts:
  283. named_certificates: "{{ hostvars.localhost.parsed_named_certificates | default([]) }}"
  284. additive_facts_to_overwrite:
  285. - "{{ 'master.named_certificates' if overwrite_named_certs | bool else omit }}"
  286. - name: Clear named certificates
  287. file:
  288. path: "{{ named_certs_dir }}"
  289. state: absent
  290. when: overwrite_named_certs | bool
  291. - name: Ensure named certificate directory exists
  292. file:
  293. path: "{{ named_certs_dir }}"
  294. state: directory
  295. when: named_certs_specified | bool
  296. - name: Land named certificates
  297. copy: src="{{ item.certfile }}" dest="{{ named_certs_dir }}"
  298. with_items: openshift_master_named_certificates
  299. when: named_certs_specified | bool
  300. - name: Land named certificate keys
  301. copy: src="{{ item.keyfile }}" dest="{{ named_certs_dir }}"
  302. with_items: openshift_master_named_certificates
  303. when: named_certs_specified | bool
  304. - name: Configure master instances
  305. hosts: oo_masters_to_config
  306. any_errors_fatal: true
  307. serial: 1
  308. vars:
  309. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  310. openshift_master_ha: "{{ openshift.master.ha }}"
  311. openshift_master_count: "{{ openshift.master.master_count }}"
  312. openshift_master_session_auth_secrets: "{{ hostvars[groups.oo_first_master.0].openshift.master.session_auth_secrets }}"
  313. openshift_master_session_encryption_secrets: "{{ hostvars[groups.oo_first_master.0].openshift.master.session_encryption_secrets }}"
  314. pre_tasks:
  315. - name: Ensure certificate directory exists
  316. file:
  317. path: "{{ openshift.common.config_base }}/master"
  318. state: directory
  319. when: master_certs_missing | bool and 'oo_first_master' not in group_names
  320. - name: Unarchive the tarball on the master
  321. unarchive:
  322. src: "{{ sync_tmpdir }}/{{ master_cert_subdir }}.tgz"
  323. dest: "{{ master_cert_config_dir }}"
  324. when: master_certs_missing | bool and 'oo_first_master' not in group_names
  325. roles:
  326. - openshift_master
  327. - role: nickhammond.logrotate
  328. - role: nuage_master
  329. when: openshift.common.use_nuage | bool
  330. post_tasks:
  331. - name: Create group for deployment type
  332. group_by: key=oo_masters_deployment_type_{{ openshift.common.deployment_type }}
  333. changed_when: False
  334. # Additional instance config for online deployments
  335. - name: Additional instance config
  336. hosts: oo_masters_deployment_type_online
  337. roles:
  338. - pods
  339. - os_env_extras
  340. - name: Delete temporary directory on localhost
  341. hosts: localhost
  342. connection: local
  343. become: no
  344. gather_facts: no
  345. tasks:
  346. - file: name={{ g_master_mktemp.stdout }} state=absent
  347. changed_when: False