config.yml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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. sudo: false
  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. sudo: false
  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}} pkg=openssl state=present"
  235. - name: Generate session authentication key
  236. command: /usr/bin/openssl rand -base64 24
  237. register: session_auth_output
  238. with_sequence: count=1
  239. when: openshift_master_session_auth_secrets is undefined
  240. - name: Generate session encryption key
  241. command: /usr/bin/openssl rand -base64 24
  242. register: session_encryption_output
  243. with_sequence: count=1
  244. when: openshift_master_session_encryption_secrets is undefined
  245. - set_fact:
  246. session_auth_secret: "{{ openshift_master_session_auth_secrets
  247. | default(session_auth_output.results
  248. | oo_collect(attribute='stdout')
  249. | list) }}"
  250. session_encryption_secret: "{{ openshift_master_session_encryption_secrets
  251. | default(session_encryption_output.results
  252. | oo_collect(attribute='stdout')
  253. | list) }}"
  254. - name: Parse named certificates
  255. hosts: localhost
  256. vars:
  257. internal_hostnames: "{{ hostvars[groups.oo_first_master.0].openshift.common.internal_hostnames }}"
  258. named_certificates: "{{ hostvars[groups.oo_first_master.0].openshift_master_named_certificates | default([]) }}"
  259. named_certificates_dir: "{{ hostvars[groups.oo_first_master.0].master_cert_config_dir }}/named_certificates/"
  260. tasks:
  261. - set_fact:
  262. parsed_named_certificates: "{{ named_certificates | oo_parse_named_certificates(named_certificates_dir, internal_hostnames) }}"
  263. when: named_certificates | length > 0
  264. - name: Deploy named certificates
  265. hosts: oo_masters_to_config
  266. vars:
  267. named_certs_dir: "{{ master_cert_config_dir }}/named_certificates/"
  268. named_certs_specified: "{{ openshift_master_named_certificates is defined }}"
  269. overwrite_named_certs: "{{ openshift_master_overwrite_named_certificates | default(false) }}"
  270. roles:
  271. - role: openshift_facts
  272. post_tasks:
  273. - openshift_facts:
  274. role: master
  275. local_facts:
  276. named_certificates: "{{ hostvars.localhost.parsed_named_certificates | default([]) }}"
  277. additive_facts_to_overwrite:
  278. - "{{ 'master.named_certificates' if overwrite_named_certs | bool else omit }}"
  279. - name: Clear named certificates
  280. file:
  281. path: "{{ named_certs_dir }}"
  282. state: absent
  283. when: overwrite_named_certs | bool
  284. - name: Ensure named certificate directory exists
  285. file:
  286. path: "{{ named_certs_dir }}"
  287. state: directory
  288. when: named_certs_specified | bool
  289. - name: Land named certificates
  290. copy: src="{{ item.certfile }}" dest="{{ named_certs_dir }}"
  291. with_items: openshift_master_named_certificates
  292. when: named_certs_specified | bool
  293. - name: Land named certificate keys
  294. copy: src="{{ item.keyfile }}" dest="{{ named_certs_dir }}"
  295. with_items: openshift_master_named_certificates
  296. when: named_certs_specified | bool
  297. - name: Configure master instances
  298. hosts: oo_masters_to_config
  299. serial: 1
  300. vars:
  301. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  302. openshift_master_ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  303. openshift_master_count: "{{ groups.oo_masters_to_config | length }}"
  304. openshift_master_session_auth_secrets: "{{ hostvars[groups['oo_first_master'][0]]['session_auth_secret'] }}"
  305. openshift_master_session_encryption_secrets: "{{ hostvars[groups['oo_first_master'][0]]['session_encryption_secret'] }}"
  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 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 and 'oo_first_master' not in group_names
  317. roles:
  318. - openshift_master
  319. - role: nickhammond.logrotate
  320. - role: fluentd_master
  321. when: openshift.common.use_fluentd | bool
  322. - role: nuage_master
  323. when: openshift.common.use_nuage | bool
  324. post_tasks:
  325. - name: Create group for deployment type
  326. group_by: key=oo_masters_deployment_type_{{ openshift.common.deployment_type }}
  327. changed_when: False
  328. - name: Additional master configuration
  329. hosts: oo_first_master
  330. vars:
  331. openshift_master_ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  332. omc_cluster_hosts: "{{ groups.oo_masters_to_config | join(' ')}}"
  333. roles:
  334. - role: openshift_master_cluster
  335. when: openshift_master_ha | bool and openshift.master.cluster_method == "pacemaker"
  336. - openshift_examples
  337. - role: openshift_cluster_metrics
  338. when: openshift.common.use_cluster_metrics | bool
  339. - role: openshift_manageiq
  340. when: openshift.common.use_manageiq | bool
  341. - name: Enable cockpit
  342. hosts: oo_first_master
  343. vars:
  344. cockpit_plugins: "{{ osm_cockpit_plugins | default(['cockpit-kubernetes']) }}"
  345. roles:
  346. - role: cockpit
  347. when: ( deployment_type in ['atomic-enterprise','openshift-enterprise'] ) and
  348. (osm_use_cockpit | bool or osm_use_cockpit is undefined )
  349. - name: Configure flannel
  350. hosts: oo_first_master
  351. vars:
  352. etcd_urls: "{{ openshift.master.etcd_urls }}"
  353. roles:
  354. - role: flannel_register
  355. when: openshift.common.use_flannel | bool
  356. # Additional instance config for online deployments
  357. - name: Additional instance config
  358. hosts: oo_masters_deployment_type_online
  359. roles:
  360. - pods
  361. - os_env_extras
  362. - name: Delete temporary directory on localhost
  363. hosts: localhost
  364. connection: local
  365. sudo: false
  366. gather_facts: no
  367. tasks:
  368. - file: name={{ g_master_mktemp.stdout }} state=absent
  369. changed_when: False
  370. - name: Configure service accounts
  371. hosts: oo_first_master
  372. vars:
  373. accounts: ["router", "registry"]
  374. roles:
  375. - openshift_serviceaccounts
  376. - name: Create services
  377. hosts: oo_first_master
  378. roles:
  379. - role: openshift_router
  380. when: openshift.master.infra_nodes is defined
  381. #- role: openshift_registry