config.yml 8.2 KB

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