config.yml 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. - set_fact:
  6. 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 }}"
  7. openshift_master_etcd_hosts: "{{ hostvars
  8. | oo_select_keys(groups['oo_etcd_to_config']
  9. | default([]))
  10. | oo_collect('openshift.common.hostname')
  11. | default(none, true) }}"
  12. roles:
  13. - openshift_facts
  14. post_tasks:
  15. - openshift_facts:
  16. role: "{{ item.role }}"
  17. local_facts: "{{ item.local_facts }}"
  18. with_items:
  19. - role: common
  20. local_facts:
  21. hostname: "{{ openshift_hostname | default(None) }}"
  22. public_hostname: "{{ openshift_public_hostname | default(None) }}"
  23. deployment_type: "{{ openshift_deployment_type }}"
  24. - role: master
  25. local_facts:
  26. api_port: "{{ openshift_master_api_port | default(None) }}"
  27. api_url: "{{ openshift_master_api_url | default(None) }}"
  28. api_use_ssl: "{{ openshift_master_api_use_ssl | default(None) }}"
  29. public_api_url: "{{ openshift_master_public_api_url | default(None) }}"
  30. cluster_hostname: "{{ openshift_master_cluster_hostname | default(None) }}"
  31. cluster_public_hostname: "{{ openshift_master_cluster_public_hostname | default(None) }}"
  32. cluster_defer_ha: "{{ openshift_master_cluster_defer_ha | default(None) }}"
  33. console_path: "{{ openshift_master_console_path | default(None) }}"
  34. console_port: "{{ openshift_master_console_port | default(None) }}"
  35. console_url: "{{ openshift_master_console_url | default(None) }}"
  36. console_use_ssl: "{{ openshift_master_console_use_ssl | default(None) }}"
  37. public_console_url: "{{ openshift_master_public_console_url | default(None) }}"
  38. - name: Check status of external etcd certificatees
  39. stat:
  40. path: "/etc/openshift/master/{{ item }}"
  41. with_items:
  42. - master.etcd-client.crt
  43. - master.etcd-ca.crt
  44. register: g_external_etcd_cert_stat_result
  45. - set_fact:
  46. etcd_client_certs_missing: "{{ g_external_etcd_cert_stat_result.results
  47. | map(attribute='stat.exists')
  48. | list | intersect([false])}}"
  49. etcd_cert_subdir: openshift-master-{{ openshift.common.hostname }}
  50. etcd_cert_config_dir: /etc/openshift/master
  51. etcd_cert_prefix: master.etcd-
  52. when: groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config
  53. - name: Create temp directory for syncing certs
  54. hosts: localhost
  55. connection: local
  56. sudo: false
  57. gather_facts: no
  58. tasks:
  59. - name: Create local temp directory for syncing certs
  60. local_action: command mktemp -d /tmp/openshift-ansible-XXXXXXX
  61. register: g_master_mktemp
  62. changed_when: False
  63. - name: Configure etcd certificates
  64. hosts: oo_first_etcd
  65. vars:
  66. etcd_generated_certs_dir: /etc/etcd/generated_certs
  67. etcd_needing_client_certs: "{{ hostvars
  68. | oo_select_keys(groups['oo_masters_to_config'])
  69. | oo_filter_list(filter_attr='etcd_client_certs_missing') }}"
  70. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  71. roles:
  72. - etcd_certificates
  73. post_tasks:
  74. - name: Create a tarball of the etcd certs
  75. command: >
  76. tar -czvf {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz
  77. -C {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }} .
  78. args:
  79. creates: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
  80. with_items: etcd_needing_client_certs
  81. - name: Retrieve the etcd cert tarballs
  82. fetch:
  83. src: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
  84. dest: "{{ sync_tmpdir }}/"
  85. flat: yes
  86. fail_on_missing: yes
  87. validate_checksum: yes
  88. with_items: etcd_needing_client_certs
  89. - name: Copy the external etcd certs to the masters
  90. hosts: oo_masters_to_config
  91. vars:
  92. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  93. tasks:
  94. - name: Ensure certificate directory exists
  95. file:
  96. path: /etc/openshift/master
  97. state: directory
  98. when: etcd_client_certs_missing is defined and etcd_client_certs_missing
  99. - name: Unarchive the tarball on the master
  100. unarchive:
  101. src: "{{ sync_tmpdir }}/{{ etcd_cert_subdir }}.tgz"
  102. dest: "{{ etcd_cert_config_dir }}"
  103. when: etcd_client_certs_missing is defined and etcd_client_certs_missing
  104. - file:
  105. path: "{{ etcd_cert_config_dir }}/{{ item }}"
  106. owner: root
  107. group: root
  108. mode: 0600
  109. with_items:
  110. - master.etcd-client.crt
  111. - master.etcd-client.key
  112. - master.etcd-ca.crt
  113. when: etcd_client_certs_missing is defined and etcd_client_certs_missing
  114. - name: Determine if master certificates need to be generated
  115. hosts: oo_masters_to_config
  116. tasks:
  117. - set_fact:
  118. openshift_master_certs_no_etcd:
  119. - admin.crt
  120. - master.kubelet-client.crt
  121. - master.server.crt
  122. - openshift-master.crt
  123. - openshift-registry.crt
  124. - openshift-router.crt
  125. - etcd.server.crt
  126. openshift_master_certs_etcd:
  127. - master.etcd-client.crt
  128. - set_fact:
  129. 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 }}"
  130. - name: Check status of master certificates
  131. stat:
  132. path: "/etc/openshift/master/{{ item }}"
  133. with_items: openshift_master_certs
  134. register: g_master_cert_stat_result
  135. - set_fact:
  136. master_certs_missing: "{{ g_master_cert_stat_result.results
  137. | map(attribute='stat.exists')
  138. | list | intersect([false])}}"
  139. master_cert_subdir: master-{{ openshift.common.hostname }}
  140. master_cert_config_dir: /etc/openshift/master
  141. - name: Configure master certificates
  142. hosts: oo_first_master
  143. vars:
  144. master_generated_certs_dir: /etc/openshift/generated-configs
  145. masters_needing_certs: "{{ hostvars
  146. | oo_select_keys(groups['oo_masters_to_config'] | difference(groups['oo_first_master']))
  147. | oo_filter_list(filter_attr='master_certs_missing') }}"
  148. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  149. roles:
  150. - openshift_master_certificates
  151. post_tasks:
  152. - name: Remove generated etcd client certs when using external etcd
  153. file:
  154. path: "{{ master_generated_certs_dir }}/{{ item.0.master_cert_subdir }}/{{ item.1 }}"
  155. state: absent
  156. when: groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config
  157. with_nested:
  158. - masters_needing_certs
  159. - - master.etcd-client.crt
  160. - master.etcd-client.key
  161. - name: Create a tarball of the master certs
  162. command: >
  163. tar -czvf {{ master_generated_certs_dir }}/{{ item.master_cert_subdir }}.tgz
  164. -C {{ master_generated_certs_dir }}/{{ item.master_cert_subdir }} .
  165. args:
  166. creates: "{{ master_generated_certs_dir }}/{{ item.master_cert_subdir }}.tgz"
  167. with_items: masters_needing_certs
  168. - name: Retrieve the master cert tarball from the master
  169. fetch:
  170. src: "{{ master_generated_certs_dir }}/{{ item.master_cert_subdir }}.tgz"
  171. dest: "{{ sync_tmpdir }}/"
  172. flat: yes
  173. fail_on_missing: yes
  174. validate_checksum: yes
  175. with_items: masters_needing_certs
  176. - name: Configure master instances
  177. hosts: oo_masters_to_config
  178. vars:
  179. sync_tmpdir: "{{ hostvars.localhost.g_master_mktemp.stdout }}"
  180. openshift_master_ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  181. pre_tasks:
  182. - name: Ensure certificate directory exists
  183. file:
  184. path: /etc/openshift/master
  185. state: directory
  186. when: master_certs_missing and 'oo_first_master' not in group_names
  187. - name: Unarchive the tarball on the master
  188. unarchive:
  189. src: "{{ sync_tmpdir }}/{{ master_cert_subdir }}.tgz"
  190. dest: "{{ master_cert_config_dir }}"
  191. when: master_certs_missing and 'oo_first_master' not in group_names
  192. roles:
  193. - openshift_master
  194. - role: nickhammond.logrotate
  195. - role: fluentd_master
  196. when: openshift.common.use_fluentd | bool
  197. post_tasks:
  198. - name: Create group for deployment type
  199. group_by: key=oo_masters_deployment_type_{{ openshift.common.deployment_type }}
  200. changed_when: False
  201. - name: Additional master configuration
  202. hosts: oo_first_master
  203. vars:
  204. openshift_master_ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  205. omc_cluster_hosts: "{{ groups.oo_masters_to_config | join(' ')}}"
  206. roles:
  207. - role: openshift_master_cluster
  208. when: openshift_master_ha | bool
  209. - openshift_examples
  210. - role: openshift_cluster_metrics
  211. when: openshift.common.use_cluster_metrics | bool
  212. # Additional instance config for online deployments
  213. - name: Additional instance config
  214. hosts: oo_masters_deployment_type_online
  215. roles:
  216. - pods
  217. - os_env_extras
  218. - name: Delete temporary directory on localhost
  219. hosts: localhost
  220. connection: local
  221. sudo: false
  222. gather_facts: no
  223. tasks:
  224. - file: name={{ g_master_mktemp.stdout }} state=absent
  225. changed_when: False