config.yml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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(10) }}"
  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. - set_fact:
  178. openshift_infra_nodes: "{{ hostvars | oo_select_keys(groups['oo_nodes_to_config'])
  179. | oo_nodes_with_label('region', 'infra')
  180. | oo_collect('inventory_hostname') }}"
  181. when: openshift_infra_nodes is not defined and groups.oo_nodes_to_config | default([]) | length > 0
  182. - name: Configure master certificates
  183. hosts: oo_first_master
  184. vars:
  185. master_generated_certs_dir: "{{ openshift.common.config_base }}/generated-configs"
  186. masters_needing_certs: "{{ hostvars
  187. | oo_select_keys(groups['oo_masters_to_config'] | difference(groups['oo_first_master']))
  188. | oo_filter_list(filter_attr='master_certs_missing') }}"
  189. master_hostnames: "{{ hostvars
  190. | oo_select_keys(groups['oo_masters_to_config'])
  191. | oo_collect('openshift.common.all_hostnames')
  192. | oo_flatten | unique }}"
  193. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  194. openshift_docker_hosted_registry_network: "{{ hostvars[groups.oo_first_master.0].openshift.common.portal_net }}"
  195. roles:
  196. - openshift_master_certificates
  197. post_tasks:
  198. - name: Remove generated etcd client certs when using external etcd
  199. file:
  200. path: "{{ master_generated_certs_dir }}/{{ item.0.master_cert_subdir }}/{{ item.1 }}"
  201. state: absent
  202. when: groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config
  203. with_nested:
  204. - "{{ masters_needing_certs | default([]) }}"
  205. - - master.etcd-client.crt
  206. - master.etcd-client.key
  207. - name: Create a tarball of the master certs
  208. command: >
  209. tar -czvf {{ master_generated_certs_dir }}/{{ item.master_cert_subdir }}.tgz
  210. -C {{ master_generated_certs_dir }}/{{ item.master_cert_subdir }} .
  211. args:
  212. creates: "{{ master_generated_certs_dir }}/{{ item.master_cert_subdir }}.tgz"
  213. with_items: "{{ masters_needing_certs | default([]) }}"
  214. - name: Retrieve the master cert tarball from the master
  215. fetch:
  216. src: "{{ master_generated_certs_dir }}/{{ item.master_cert_subdir }}.tgz"
  217. dest: "{{ sync_tmpdir }}/"
  218. flat: yes
  219. fail_on_missing: yes
  220. validate_checksum: yes
  221. with_items: "{{ masters_needing_certs | default([]) }}"
  222. - name: Check for cached session secrets
  223. hosts: oo_first_master
  224. roles:
  225. - role: openshift_facts
  226. post_tasks:
  227. - openshift_facts:
  228. role: master
  229. local_facts:
  230. session_auth_secrets: "{{ openshift_master_session_auth_secrets | default(openshift.master.session_auth_secrets | default(None)) }}"
  231. session_encryption_secrets: "{{ openshift_master_session_encryption_secrets | default(openshift.master.session_encryption_secrets | default(None)) }}"
  232. - name: Generate master session secrets
  233. hosts: oo_first_master
  234. vars:
  235. g_session_secrets_present: "{{ (openshift.master.session_auth_secrets | default([]) and openshift.master.session_encryption_secrets | default([])) | length > 0 }}"
  236. g_session_auth_secrets: "{{ [ 24 | oo_generate_secret ] }}"
  237. g_session_encryption_secrets: "{{ [ 24 | oo_generate_secret ] }}"
  238. roles:
  239. - role: openshift_facts
  240. tasks:
  241. - openshift_facts:
  242. role: master
  243. local_facts:
  244. session_auth_secrets: "{{ g_session_auth_secrets }}"
  245. session_encryption_secrets: "{{ g_session_encryption_secrets }}"
  246. when: not g_session_secrets_present | bool
  247. - name: Parse named certificates
  248. hosts: localhost
  249. connection: local
  250. become: no
  251. vars:
  252. internal_hostnames: "{{ hostvars[groups.oo_first_master.0].openshift.common.internal_hostnames }}"
  253. named_certificates: "{{ hostvars[groups.oo_first_master.0].openshift_master_named_certificates | default([]) }}"
  254. named_certificates_dir: "{{ hostvars[groups.oo_first_master.0].master_cert_config_dir }}/named_certificates/"
  255. tasks:
  256. - set_fact:
  257. parsed_named_certificates: "{{ named_certificates | oo_parse_named_certificates(named_certificates_dir, internal_hostnames) }}"
  258. when: named_certificates | length > 0
  259. - name: Deploy named certificates
  260. hosts: oo_masters_to_config
  261. vars:
  262. named_certs_dir: "{{ master_cert_config_dir }}/named_certificates/"
  263. named_certs_specified: "{{ openshift_master_named_certificates is defined }}"
  264. overwrite_named_certs: "{{ openshift_master_overwrite_named_certificates | default(false) }}"
  265. roles:
  266. - role: openshift_facts
  267. post_tasks:
  268. - openshift_facts:
  269. role: master
  270. local_facts:
  271. named_certificates: "{{ hostvars.localhost.parsed_named_certificates | default([]) }}"
  272. additive_facts_to_overwrite:
  273. - "{{ 'master.named_certificates' if overwrite_named_certs | bool else omit }}"
  274. - name: Clear named certificates
  275. file:
  276. path: "{{ named_certs_dir }}"
  277. state: absent
  278. when: overwrite_named_certs | bool
  279. - name: Ensure named certificate directory exists
  280. file:
  281. path: "{{ named_certs_dir }}"
  282. state: directory
  283. mode: 0700
  284. when: named_certs_specified | bool
  285. - name: Land named certificates
  286. copy: src="{{ item.certfile }}" dest="{{ named_certs_dir }}"
  287. with_items: openshift_master_named_certificates
  288. when: named_certs_specified | bool
  289. - name: Land named certificate keys
  290. copy: src="{{ item.keyfile }}" dest="{{ named_certs_dir }}" mode=0600
  291. with_items: openshift_master_named_certificates
  292. when: named_certs_specified | bool
  293. - name: Configure masters
  294. hosts: oo_masters_to_config
  295. any_errors_fatal: true
  296. serial: 1
  297. vars:
  298. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  299. # Do not pass a version if this is first master. (openshift_version will sort it out)
  300. # For subsequent masters we pass either pre-existing version for the master (if already installed),
  301. # otherwise the first master version.
  302. openshift_version: "{{ openshift.common.version if openshift.common.version is defined else oo_first_master.openshift.common.version.split('-')[0] }}"
  303. when: inventory_hostname != groups.oo_first_master.0
  304. openshift_master_ha: "{{ openshift.master.ha }}"
  305. openshift_master_count: "{{ openshift.master.master_count }}"
  306. openshift_master_session_auth_secrets: "{{ hostvars[groups.oo_first_master.0].openshift.master.session_auth_secrets }}"
  307. openshift_master_session_encryption_secrets: "{{ hostvars[groups.oo_first_master.0].openshift.master.session_encryption_secrets }}"
  308. openshift_docker_hosted_registry_network: "{{ hostvars[groups.oo_first_master.0].openshift.common.portal_net }}"
  309. openshift_no_proxy_internal_hostnames: "{{ hostvars | oo_select_keys(groups['oo_nodes_to_config']
  310. | union(groups['oo_masters_to_config'])
  311. | union(groups['oo_etcd_to_config'] | default([])))
  312. | oo_collect('openshift.common.hostname') | default([]) | join (',')
  313. }}"
  314. when: "{{ (openshift_http_proxy is defined or openshift_https_proxy is defined) and
  315. openshift_generate_no_proxy_hosts | default(True) | bool }}"
  316. pre_tasks:
  317. - name: Ensure certificate directory exists
  318. file:
  319. path: "{{ openshift.common.config_base }}/master"
  320. state: directory
  321. when: master_certs_missing | bool and 'oo_first_master' not in group_names
  322. - name: Unarchive the tarball on the master
  323. unarchive:
  324. src: "{{ sync_tmpdir }}/{{ master_cert_subdir }}.tgz"
  325. dest: "{{ master_cert_config_dir }}"
  326. when: master_certs_missing | bool and 'oo_first_master' not in group_names
  327. roles:
  328. - openshift_master
  329. - role: nickhammond.logrotate
  330. - role: nuage_master
  331. when: openshift.common.use_nuage | bool
  332. post_tasks:
  333. - name: Create group for deployment type
  334. group_by: key=oo_masters_deployment_type_{{ openshift.common.deployment_type }}
  335. changed_when: False
  336. - name: Delete temporary directory on localhost
  337. hosts: localhost
  338. connection: local
  339. become: no
  340. gather_facts: no
  341. tasks:
  342. - file: name={{ g_master_mktemp.stdout }} state=absent
  343. changed_when: False