config.yml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. ---
  2. - name: Set master facts and determine if external etcd certs need to be generated
  3. hosts: oo_masters_to_config
  4. pre_tasks:
  5. - name: Check for RPM generated config marker file .config_managed
  6. stat:
  7. path: /etc/origin/.config_managed
  8. register: rpmgenerated_config
  9. - name: Remove RPM generated config files if present
  10. file:
  11. path: "/etc/origin/{{ item }}"
  12. state: absent
  13. when: rpmgenerated_config.stat.exists == true and deployment_type in ['openshift-enterprise', 'atomic-enterprise']
  14. with_items:
  15. - master
  16. - node
  17. - .config_managed
  18. - set_fact:
  19. 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 }}"
  20. openshift_master_etcd_hosts: "{{ hostvars
  21. | oo_select_keys(groups['oo_etcd_to_config']
  22. | default([]))
  23. | oo_collect('openshift.common.hostname')
  24. | default(none, true) }}"
  25. roles:
  26. - openshift_facts
  27. post_tasks:
  28. - openshift_facts:
  29. role: "{{ item.role }}"
  30. local_facts: "{{ item.local_facts }}"
  31. with_items:
  32. - role: common
  33. local_facts:
  34. hostname: "{{ openshift_hostname | default(None) }}"
  35. ip: "{{ openshift_ip | default(None) }}"
  36. public_hostname: "{{ openshift_public_hostname | default(None) }}"
  37. public_ip: "{{ openshift_public_ip | default(None) }}"
  38. deployment_type: "{{ openshift_deployment_type }}"
  39. - role: master
  40. local_facts:
  41. api_port: "{{ openshift_master_api_port | default(None) }}"
  42. api_url: "{{ openshift_master_api_url | default(None) }}"
  43. api_use_ssl: "{{ openshift_master_api_use_ssl | default(None) }}"
  44. public_api_url: "{{ openshift_master_public_api_url | default(None) }}"
  45. cluster_hostname: "{{ openshift_master_cluster_hostname | default(None) }}"
  46. cluster_public_hostname: "{{ openshift_master_cluster_public_hostname | default(None) }}"
  47. console_path: "{{ openshift_master_console_path | default(None) }}"
  48. console_port: "{{ openshift_master_console_port | default(None) }}"
  49. console_url: "{{ openshift_master_console_url | default(None) }}"
  50. console_use_ssl: "{{ openshift_master_console_use_ssl | default(None) }}"
  51. public_console_url: "{{ openshift_master_public_console_url | default(None) }}"
  52. - name: Check status of external etcd certificatees
  53. stat:
  54. path: "{{ openshift.common.config_base }}/master/{{ item }}"
  55. with_items:
  56. - master.etcd-client.crt
  57. - master.etcd-ca.crt
  58. register: g_external_etcd_cert_stat_result
  59. - set_fact:
  60. etcd_client_certs_missing: "{{ g_external_etcd_cert_stat_result.results
  61. | oo_collect(attribute='stat.exists')
  62. | list | intersect([false])}}"
  63. etcd_cert_subdir: openshift-master-{{ openshift.common.hostname }}
  64. etcd_cert_config_dir: "{{ openshift.common.config_base }}/master"
  65. etcd_cert_prefix: master.etcd-
  66. when: groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config
  67. - name: Create temp directory for syncing certs
  68. hosts: localhost
  69. connection: local
  70. become: no
  71. gather_facts: no
  72. tasks:
  73. - name: Create local temp directory for syncing certs
  74. local_action: command mktemp -d /tmp/openshift-ansible-XXXXXXX
  75. register: g_master_mktemp
  76. changed_when: False
  77. - name: Configure etcd certificates
  78. hosts: oo_first_etcd
  79. vars:
  80. etcd_generated_certs_dir: /etc/etcd/generated_certs
  81. etcd_needing_client_certs: "{{ hostvars
  82. | oo_select_keys(groups['oo_masters_to_config'])
  83. | oo_filter_list(filter_attr='etcd_client_certs_missing') }}"
  84. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  85. roles:
  86. - etcd_certificates
  87. post_tasks:
  88. - name: Create a tarball of the etcd certs
  89. command: >
  90. tar -czvf {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz
  91. -C {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }} .
  92. args:
  93. creates: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
  94. with_items: etcd_needing_client_certs
  95. - name: Retrieve the etcd cert tarballs
  96. fetch:
  97. src: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
  98. dest: "{{ sync_tmpdir }}/"
  99. flat: yes
  100. fail_on_missing: yes
  101. validate_checksum: yes
  102. with_items: etcd_needing_client_certs
  103. - name: Copy the external etcd certs to the masters
  104. hosts: oo_masters_to_config
  105. vars:
  106. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  107. tasks:
  108. - name: Ensure certificate directory exists
  109. file:
  110. path: "{{ openshift.common.config_base }}/master"
  111. state: directory
  112. when: etcd_client_certs_missing is defined and etcd_client_certs_missing
  113. - name: Unarchive the tarball on the master
  114. unarchive:
  115. src: "{{ sync_tmpdir }}/{{ etcd_cert_subdir }}.tgz"
  116. dest: "{{ etcd_cert_config_dir }}"
  117. when: etcd_client_certs_missing is defined and etcd_client_certs_missing
  118. - file:
  119. path: "{{ etcd_cert_config_dir }}/{{ item }}"
  120. owner: root
  121. group: root
  122. mode: 0600
  123. with_items:
  124. - master.etcd-client.crt
  125. - master.etcd-client.key
  126. - master.etcd-ca.crt
  127. when: etcd_client_certs_missing is defined and etcd_client_certs_missing
  128. - name: Determine if master certificates need to be generated
  129. hosts: oo_masters_to_config
  130. tasks:
  131. - set_fact:
  132. openshift_master_certs_no_etcd:
  133. - admin.crt
  134. - master.kubelet-client.crt
  135. - "{{ 'master.proxy-client.crt' if openshift.common.version_greater_than_3_1_or_1_1 else omit }}"
  136. - master.server.crt
  137. - openshift-master.crt
  138. - openshift-registry.crt
  139. - openshift-router.crt
  140. - etcd.server.crt
  141. openshift_master_certs_etcd:
  142. - master.etcd-client.crt
  143. - set_fact:
  144. 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 }}"
  145. - name: Check status of master certificates
  146. stat:
  147. path: "{{ openshift.common.config_base }}/master/{{ item }}"
  148. with_items: openshift_master_certs
  149. register: g_master_cert_stat_result
  150. - set_fact:
  151. master_certs_missing: "{{ False in (g_master_cert_stat_result.results
  152. | oo_collect(attribute='stat.exists')
  153. | list ) }}"
  154. master_cert_subdir: master-{{ openshift.common.hostname }}
  155. master_cert_config_dir: "{{ openshift.common.config_base }}/master"
  156. - name: Configure master certificates
  157. hosts: oo_first_master
  158. vars:
  159. master_generated_certs_dir: "{{ openshift.common.config_base }}/generated-configs"
  160. masters_needing_certs: "{{ hostvars
  161. | oo_select_keys(groups['oo_masters_to_config'] | difference(groups['oo_first_master']))
  162. | oo_filter_list(filter_attr='master_certs_missing') }}"
  163. master_hostnames: "{{ hostvars
  164. | oo_select_keys(groups['oo_masters_to_config'])
  165. | oo_collect('openshift.common.all_hostnames')
  166. | oo_flatten | unique }}"
  167. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  168. roles:
  169. - openshift_master_certificates
  170. post_tasks:
  171. - name: Remove generated etcd client certs when using external etcd
  172. file:
  173. path: "{{ master_generated_certs_dir }}/{{ item.0.master_cert_subdir }}/{{ item.1 }}"
  174. state: absent
  175. when: groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config
  176. with_nested:
  177. - masters_needing_certs
  178. - - master.etcd-client.crt
  179. - master.etcd-client.key
  180. - name: Create a tarball of the master certs
  181. command: >
  182. tar -czvf {{ master_generated_certs_dir }}/{{ item.master_cert_subdir }}.tgz
  183. -C {{ master_generated_certs_dir }}/{{ item.master_cert_subdir }} .
  184. args:
  185. creates: "{{ master_generated_certs_dir }}/{{ item.master_cert_subdir }}.tgz"
  186. with_items: masters_needing_certs
  187. - name: Retrieve the master cert tarball from the master
  188. fetch:
  189. src: "{{ master_generated_certs_dir }}/{{ item.master_cert_subdir }}.tgz"
  190. dest: "{{ sync_tmpdir }}/"
  191. flat: yes
  192. fail_on_missing: yes
  193. validate_checksum: yes
  194. with_items: masters_needing_certs
  195. - name: Compute haproxy_backend_servers
  196. hosts: localhost
  197. connection: local
  198. become: no
  199. gather_facts: no
  200. tasks:
  201. - set_fact:
  202. haproxy_backend_servers: "{{ hostvars | oo_select_keys(groups['oo_masters_to_config']) | oo_haproxy_backend_masters }}"
  203. - name: Configure load balancers
  204. hosts: oo_lb_to_config
  205. vars:
  206. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  207. haproxy_frontends:
  208. - name: atomic-openshift-api
  209. mode: tcp
  210. options:
  211. - tcplog
  212. binds:
  213. - "*:{{ hostvars[groups.oo_first_master.0].openshift.master.api_port }}"
  214. default_backend: atomic-openshift-api
  215. haproxy_backends:
  216. - name: atomic-openshift-api
  217. mode: tcp
  218. option: tcplog
  219. balance: source
  220. servers: "{{ hostvars.localhost.haproxy_backend_servers }}"
  221. roles:
  222. - role: haproxy
  223. when: groups.oo_masters_to_config | length > 1
  224. - name: Generate master session keys
  225. hosts: oo_first_master
  226. tasks:
  227. - fail:
  228. msg: "Both openshift_master_session_auth_secrets and openshift_master_session_encryption_secrets must be provided if either variable is set"
  229. when: (openshift_master_session_auth_secrets is defined and openshift_master_session_encryption_secrets is not defined) or (openshift_master_session_encryption_secrets is defined and openshift_master_session_auth_secrets is not defined)
  230. - fail:
  231. msg: "openshift_master_session_auth_secrets and openshift_master_encryption_secrets must be equal length"
  232. when: (openshift_master_session_auth_secrets is defined and openshift_master_session_encryption_secrets is defined) and (openshift_master_session_auth_secrets | length != openshift_master_session_encryption_secrets | length)
  233. - name: Install OpenSSL package
  234. action: "{{ ansible_pkg_mgr }} name=openssl state=present"
  235. - name: Generate session authentication key
  236. command: /usr/bin/openssl rand -base64 24
  237. register: session_auth_output
  238. when: openshift_master_session_auth_secrets is undefined
  239. - name: Generate session encryption key
  240. command: /usr/bin/openssl rand -base64 24
  241. register: session_encryption_output
  242. when: openshift_master_session_encryption_secrets is undefined
  243. - set_fact:
  244. session_auth_secret: "{{ openshift_master_session_auth_secrets | default([session_auth_output.stdout]) }}"
  245. session_encryption_secret: "{{ openshift_master_session_encryption_secrets | default([session_encryption_output.stdout]) }}"
  246. - name: Parse named certificates
  247. hosts: localhost
  248. connection: local
  249. become: no
  250. vars:
  251. internal_hostnames: "{{ hostvars[groups.oo_first_master.0].openshift.common.internal_hostnames }}"
  252. named_certificates: "{{ hostvars[groups.oo_first_master.0].openshift_master_named_certificates | default([]) }}"
  253. named_certificates_dir: "{{ hostvars[groups.oo_first_master.0].master_cert_config_dir }}/named_certificates/"
  254. tasks:
  255. - set_fact:
  256. parsed_named_certificates: "{{ named_certificates | oo_parse_named_certificates(named_certificates_dir, internal_hostnames) }}"
  257. when: named_certificates | length > 0
  258. - name: Deploy named certificates
  259. hosts: oo_masters_to_config
  260. vars:
  261. named_certs_dir: "{{ master_cert_config_dir }}/named_certificates/"
  262. named_certs_specified: "{{ openshift_master_named_certificates is defined }}"
  263. overwrite_named_certs: "{{ openshift_master_overwrite_named_certificates | default(false) }}"
  264. roles:
  265. - role: openshift_facts
  266. post_tasks:
  267. - openshift_facts:
  268. role: master
  269. local_facts:
  270. named_certificates: "{{ hostvars.localhost.parsed_named_certificates | default([]) }}"
  271. additive_facts_to_overwrite:
  272. - "{{ 'master.named_certificates' if overwrite_named_certs | bool else omit }}"
  273. - name: Clear named certificates
  274. file:
  275. path: "{{ named_certs_dir }}"
  276. state: absent
  277. when: overwrite_named_certs | bool
  278. - name: Ensure named certificate directory exists
  279. file:
  280. path: "{{ named_certs_dir }}"
  281. state: directory
  282. when: named_certs_specified | bool
  283. - name: Land named certificates
  284. copy: src="{{ item.certfile }}" dest="{{ named_certs_dir }}"
  285. with_items: openshift_master_named_certificates
  286. when: named_certs_specified | bool
  287. - name: Land named certificate keys
  288. copy: src="{{ item.keyfile }}" dest="{{ named_certs_dir }}"
  289. with_items: openshift_master_named_certificates
  290. when: named_certs_specified | bool
  291. - name: Configure master instances
  292. hosts: oo_masters_to_config
  293. serial: 1
  294. vars:
  295. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  296. openshift_master_ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  297. openshift_master_count: "{{ groups.oo_masters_to_config | length }}"
  298. openshift_master_session_auth_secrets: "{{ hostvars[groups['oo_first_master'][0]]['session_auth_secret'] }}"
  299. openshift_master_session_encryption_secrets: "{{ hostvars[groups['oo_first_master'][0]]['session_encryption_secret'] }}"
  300. pre_tasks:
  301. - name: Ensure certificate directory exists
  302. file:
  303. path: "{{ openshift.common.config_base }}/master"
  304. state: directory
  305. when: master_certs_missing and 'oo_first_master' not in group_names
  306. - name: Unarchive the tarball on the master
  307. unarchive:
  308. src: "{{ sync_tmpdir }}/{{ master_cert_subdir }}.tgz"
  309. dest: "{{ master_cert_config_dir }}"
  310. when: master_certs_missing and 'oo_first_master' not in group_names
  311. roles:
  312. - openshift_master
  313. - role: nickhammond.logrotate
  314. when: not is_atomic
  315. - role: fluentd_master
  316. when: openshift.common.use_fluentd | bool
  317. post_tasks:
  318. - name: Create group for deployment type
  319. group_by: key=oo_masters_deployment_type_{{ openshift.common.deployment_type }}
  320. changed_when: False
  321. - name: Additional master configuration
  322. hosts: oo_first_master
  323. vars:
  324. openshift_master_ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  325. omc_cluster_hosts: "{{ groups.oo_masters_to_config | join(' ')}}"
  326. roles:
  327. - role: openshift_master_cluster
  328. when: openshift_master_ha | bool and openshift.master.cluster_method == "pacemaker"
  329. - role: openshift_examples
  330. when: openshift.common.install_examples | bool
  331. - role: openshift_cluster_metrics
  332. when: openshift.common.use_cluster_metrics | bool
  333. - role: openshift_manageiq
  334. when: openshift.common.use_manageiq | bool
  335. - name: Enable cockpit
  336. hosts: oo_first_master
  337. vars:
  338. cockpit_plugins: "{{ osm_cockpit_plugins | default(['cockpit-kubernetes']) }}"
  339. roles:
  340. - role: cockpit
  341. when: ( deployment_type in ['atomic-enterprise','openshift-enterprise'] ) and
  342. (osm_use_cockpit | bool or osm_use_cockpit is undefined )
  343. - name: Configure flannel
  344. hosts: oo_first_master
  345. vars:
  346. etcd_urls: "{{ openshift.master.etcd_urls }}"
  347. roles:
  348. - role: flannel_register
  349. when: openshift.common.use_flannel | bool
  350. # Additional instance config for online deployments
  351. - name: Additional instance config
  352. hosts: oo_masters_deployment_type_online
  353. roles:
  354. - pods
  355. - os_env_extras
  356. - name: Delete temporary directory on localhost
  357. hosts: localhost
  358. connection: local
  359. become: no
  360. gather_facts: no
  361. tasks:
  362. - file: name={{ g_master_mktemp.stdout }} state=absent
  363. changed_when: False
  364. - name: Configure service accounts
  365. hosts: oo_first_master
  366. vars:
  367. accounts: ["router", "registry"]
  368. roles:
  369. - openshift_serviceaccounts
  370. - name: Create services
  371. hosts: oo_first_master
  372. roles:
  373. - role: openshift_router
  374. when: openshift.master.infra_nodes is defined
  375. #- role: openshift_registry