config.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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('10s', true) }}"
  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. - name: Determine if master certificates need to be generated
  150. hosts: oo_first_master:oo_masters_to_config
  151. tasks:
  152. - set_fact:
  153. openshift_master_certs_no_etcd:
  154. - admin.crt
  155. - master.kubelet-client.crt
  156. - "{{ 'master.proxy-client.crt' if openshift.common.version_gte_3_1_or_1_1 else omit }}"
  157. - master.server.crt
  158. - openshift-master.crt
  159. - openshift-registry.crt
  160. - openshift-router.crt
  161. - etcd.server.crt
  162. openshift_master_certs_etcd:
  163. - master.etcd-client.crt
  164. - set_fact:
  165. 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 }}"
  166. - name: Check status of master certificates
  167. stat:
  168. path: "{{ openshift.common.config_base }}/master/{{ item }}"
  169. with_items: "{{ openshift_master_certs }}"
  170. register: g_master_cert_stat_result
  171. - set_fact:
  172. master_certs_missing: "{{ False in (g_master_cert_stat_result.results
  173. | oo_collect(attribute='stat.exists')
  174. | list ) }}"
  175. master_cert_subdir: master-{{ openshift.common.hostname }}
  176. master_cert_config_dir: "{{ openshift.common.config_base }}/master"
  177. - name: Configure master certificates
  178. hosts: oo_first_master
  179. vars:
  180. master_generated_certs_dir: "{{ openshift.common.config_base }}/generated-configs"
  181. masters_needing_certs: "{{ hostvars
  182. | oo_select_keys(groups['oo_masters_to_config'] | difference(groups['oo_first_master']))
  183. | oo_filter_list(filter_attr='master_certs_missing') }}"
  184. master_hostnames: "{{ hostvars
  185. | oo_select_keys(groups['oo_masters_to_config'])
  186. | oo_collect('openshift.common.all_hostnames')
  187. | oo_flatten | unique }}"
  188. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  189. openshift_docker_hosted_registry_network: "{{ hostvars[groups.oo_first_master.0].openshift.common.portal_net }}"
  190. roles:
  191. - openshift_master_certificates
  192. post_tasks:
  193. - name: Remove generated etcd client certs when using external etcd
  194. file:
  195. path: "{{ master_generated_certs_dir }}/{{ item.0.master_cert_subdir }}/{{ item.1 }}"
  196. state: absent
  197. when: groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config
  198. with_nested:
  199. - "{{ masters_needing_certs | default([]) }}"
  200. - - master.etcd-client.crt
  201. - master.etcd-client.key
  202. - name: Create a tarball of the master certs
  203. command: >
  204. tar -czvf {{ master_generated_certs_dir }}/{{ item.master_cert_subdir }}.tgz
  205. -C {{ master_generated_certs_dir }}/{{ item.master_cert_subdir }} .
  206. args:
  207. creates: "{{ master_generated_certs_dir }}/{{ item.master_cert_subdir }}.tgz"
  208. with_items: "{{ masters_needing_certs | default([]) }}"
  209. - name: Retrieve the master cert tarball from the master
  210. fetch:
  211. src: "{{ master_generated_certs_dir }}/{{ item.master_cert_subdir }}.tgz"
  212. dest: "{{ sync_tmpdir }}/"
  213. flat: yes
  214. fail_on_missing: yes
  215. validate_checksum: yes
  216. with_items: "{{ masters_needing_certs | default([]) }}"
  217. - name: Check for cached session secrets
  218. hosts: oo_first_master
  219. roles:
  220. - role: openshift_facts
  221. post_tasks:
  222. - openshift_facts:
  223. role: master
  224. local_facts:
  225. session_auth_secrets: "{{ openshift_master_session_auth_secrets | default(openshift.master.session_auth_secrets | default(None)) }}"
  226. session_encryption_secrets: "{{ openshift_master_session_encryption_secrets | default(openshift.master.session_encryption_secrets | default(None)) }}"
  227. - name: Generate master session secrets
  228. hosts: oo_first_master
  229. vars:
  230. g_session_secrets_present: "{{ (openshift.master.session_auth_secrets | default([]) and openshift.master.session_encryption_secrets | default([])) | length > 0 }}"
  231. g_session_auth_secrets: "{{ [ 24 | oo_generate_secret ] }}"
  232. g_session_encryption_secrets: "{{ [ 24 | oo_generate_secret ] }}"
  233. roles:
  234. - role: openshift_facts
  235. tasks:
  236. - openshift_facts:
  237. role: master
  238. local_facts:
  239. session_auth_secrets: "{{ g_session_auth_secrets }}"
  240. session_encryption_secrets: "{{ g_session_encryption_secrets }}"
  241. when: not g_session_secrets_present | bool
  242. - name: Parse named certificates
  243. hosts: localhost
  244. connection: local
  245. become: no
  246. vars:
  247. internal_hostnames: "{{ hostvars[groups.oo_first_master.0].openshift.common.internal_hostnames }}"
  248. named_certificates: "{{ hostvars[groups.oo_first_master.0].openshift_master_named_certificates | default([]) }}"
  249. named_certificates_dir: "{{ hostvars[groups.oo_first_master.0].master_cert_config_dir }}/named_certificates/"
  250. tasks:
  251. - set_fact:
  252. parsed_named_certificates: "{{ named_certificates | oo_parse_named_certificates(named_certificates_dir, internal_hostnames) }}"
  253. when: named_certificates | length > 0
  254. - name: Deploy named certificates
  255. hosts: oo_masters_to_config
  256. vars:
  257. named_certs_dir: "{{ master_cert_config_dir }}/named_certificates/"
  258. named_certs_specified: "{{ openshift_master_named_certificates is defined }}"
  259. overwrite_named_certs: "{{ openshift_master_overwrite_named_certificates | default(false) }}"
  260. roles:
  261. - role: openshift_facts
  262. post_tasks:
  263. - openshift_facts:
  264. role: master
  265. local_facts:
  266. named_certificates: "{{ hostvars.localhost.parsed_named_certificates | default([]) }}"
  267. additive_facts_to_overwrite:
  268. - "{{ 'master.named_certificates' if overwrite_named_certs | bool else omit }}"
  269. - name: Clear named certificates
  270. file:
  271. path: "{{ named_certs_dir }}"
  272. state: absent
  273. when: overwrite_named_certs | bool
  274. - name: Ensure named certificate directory exists
  275. file:
  276. path: "{{ named_certs_dir }}"
  277. state: directory
  278. mode: 0700
  279. when: named_certs_specified | bool
  280. - name: Land named certificates
  281. copy: src="{{ item.certfile }}" dest="{{ named_certs_dir }}"
  282. with_items: openshift_master_named_certificates
  283. when: named_certs_specified | bool
  284. - name: Land named certificate keys
  285. copy: src="{{ item.keyfile }}" dest="{{ named_certs_dir }}" mode=0600
  286. with_items: openshift_master_named_certificates
  287. when: named_certs_specified | bool
  288. - name: Configure master instances
  289. hosts: oo_masters_to_config
  290. any_errors_fatal: true
  291. serial: 1
  292. vars:
  293. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  294. openshift_master_ha: "{{ openshift.master.ha }}"
  295. openshift_master_count: "{{ openshift.master.master_count }}"
  296. openshift_master_session_auth_secrets: "{{ hostvars[groups.oo_first_master.0].openshift.master.session_auth_secrets }}"
  297. openshift_master_session_encryption_secrets: "{{ hostvars[groups.oo_first_master.0].openshift.master.session_encryption_secrets }}"
  298. openshift_docker_hosted_registry_network: "{{ hostvars[groups.oo_first_master.0].openshift.common.portal_net }}"
  299. openshift_no_proxy_internal_hostnames: "{{ hostvars | oo_select_keys(groups['oo_nodes_to_config']
  300. | union(groups['oo_masters_to_config'])
  301. | union(groups['oo_etcd_to_config'] | default([])))
  302. | oo_collect('openshift.common.hostname') | default([]) | join (',')
  303. }}"
  304. when: "{{ (openshift_http_proxy is defined or openshift_https_proxy is defined) and
  305. openshift_generate_no_proxy_hosts | default(True) | bool }}"
  306. pre_tasks:
  307. - name: Ensure certificate directory exists
  308. file:
  309. path: "{{ openshift.common.config_base }}/master"
  310. state: directory
  311. when: master_certs_missing | bool and 'oo_first_master' not in group_names
  312. - name: Unarchive the tarball on the master
  313. unarchive:
  314. src: "{{ sync_tmpdir }}/{{ master_cert_subdir }}.tgz"
  315. dest: "{{ master_cert_config_dir }}"
  316. when: master_certs_missing | bool and 'oo_first_master' not in group_names
  317. roles:
  318. - openshift_master
  319. - role: nickhammond.logrotate
  320. - role: nuage_master
  321. when: openshift.common.use_nuage | bool
  322. post_tasks:
  323. - name: Create group for deployment type
  324. group_by: key=oo_masters_deployment_type_{{ openshift.common.deployment_type }}
  325. changed_when: False
  326. - name: Delete temporary directory on localhost
  327. hosts: localhost
  328. connection: local
  329. become: no
  330. gather_facts: no
  331. tasks:
  332. - file: name={{ g_master_mktemp.stdout }} state=absent
  333. changed_when: False