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