config.yml 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. ---
  2. - name: Gather and set facts for node hosts
  3. hosts: oo_nodes_to_config
  4. roles:
  5. - openshift_facts
  6. tasks:
  7. # Since the master is generating the node certificates before they are
  8. # configured, we need to make sure to set the node properties beforehand if
  9. # we do not want the defaults
  10. - openshift_facts:
  11. role: "{{ item.role }}"
  12. local_facts: "{{ item.local_facts }}"
  13. with_items:
  14. - role: common
  15. local_facts:
  16. hostname: "{{ openshift_hostname | default(None) }}"
  17. public_hostname: "{{ openshift_public_hostname | default(None) }}"
  18. deployment_type: "{{ openshift_deployment_type }}"
  19. - role: node
  20. local_facts:
  21. labels: "{{ openshift_node_labels | default(None) }}"
  22. annotations: "{{ openshift_node_annotations | default(None) }}"
  23. schedulable: "{{ openshift_schedulable | default(openshift_scheduleable) | default(None) }}"
  24. - name: Check status of node certificates
  25. stat:
  26. path: "{{ openshift.common.config_base }}/node/{{ item }}"
  27. with_items:
  28. - "system:node:{{ openshift.common.hostname }}.crt"
  29. - "system:node:{{ openshift.common.hostname }}.key"
  30. - "system:node:{{ openshift.common.hostname }}.kubeconfig"
  31. - ca.crt
  32. - server.key
  33. - server.crt
  34. register: stat_result
  35. - set_fact:
  36. certs_missing: "{{ stat_result.results | oo_collect(attribute='stat.exists')
  37. | list | intersect([false])}}"
  38. node_subdir: node-{{ openshift.common.hostname }}
  39. config_dir: "{{ openshift.common.config_base }}/generated-configs/node-{{ openshift.common.hostname }}"
  40. node_cert_dir: "{{ openshift.common.config_base }}/node"
  41. - name: Check status of flannel external etcd certificates
  42. stat:
  43. path: "{{ openshift.common.config_base }}/node/{{ item }}"
  44. with_items:
  45. - node.etcd-client.crt
  46. - node.etcd-ca.crt
  47. register: g_external_etcd_flannel_cert_stat_result
  48. when: groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config and (openshift.common.use_flannel | bool)
  49. - set_fact:
  50. etcd_client_flannel_certs_missing: "{{ g_external_etcd_flannel_cert_stat_result.results
  51. | oo_collect(attribute='stat.exists')
  52. | list | intersect([false])}}"
  53. etcd_cert_subdir: openshift-node-{{ openshift.common.hostname }}
  54. etcd_cert_config_dir: "{{ openshift.common.config_base }}/node"
  55. etcd_cert_prefix: node.etcd-
  56. when: groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config and (openshift.common.use_flannel | bool)
  57. - name: Create temp directory for syncing certs
  58. hosts: localhost
  59. connection: local
  60. become: no
  61. gather_facts: no
  62. tasks:
  63. - name: Create local temp directory for syncing certs
  64. local_action: command mktemp -d /tmp/openshift-ansible-XXXXXXX
  65. register: mktemp
  66. changed_when: False
  67. - name: Configure flannel etcd certificates
  68. hosts: oo_first_etcd
  69. vars:
  70. etcd_generated_certs_dir: /etc/etcd/generated_certs
  71. sync_tmpdir: "{{ hostvars.localhost.mktemp.stdout }}"
  72. pre_tasks:
  73. - set_fact:
  74. etcd_needing_client_certs: "{{ hostvars
  75. | oo_select_keys(groups['oo_nodes_to_config'])
  76. | oo_filter_list(filter_attr='etcd_client_flannel_certs_missing') | default([]) }}"
  77. when: etcd_client_flannel_certs_missing is defined and etcd_client_flannel_certs_missing
  78. roles:
  79. - role: etcd_certificates
  80. post_tasks:
  81. - name: Create a tarball of the etcd flannel certs
  82. command: >
  83. tar -czvf {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz
  84. -C {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }} .
  85. args:
  86. creates: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
  87. with_items: etcd_needing_client_certs
  88. when: etcd_client_flannel_certs_missing is defined and etcd_client_flannel_certs_missing
  89. - name: Retrieve the etcd cert tarballs
  90. fetch:
  91. src: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
  92. dest: "{{ sync_tmpdir }}/"
  93. flat: yes
  94. fail_on_missing: yes
  95. validate_checksum: yes
  96. with_items: etcd_needing_client_certs
  97. when: etcd_client_flannel_certs_missing is defined and etcd_client_flannel_certs_missing
  98. - name: Copy the external etcd flannel certs to the nodes
  99. hosts: oo_nodes_to_config
  100. vars:
  101. sync_tmpdir: "{{ hostvars.localhost.mktemp.stdout }}"
  102. tasks:
  103. - name: Ensure certificate directory exists
  104. file:
  105. path: "{{ openshift.common.config_base }}/node"
  106. state: directory
  107. when: etcd_client_flannel_certs_missing is defined and etcd_client_flannel_certs_missing
  108. - name: Unarchive the tarball on the master
  109. unarchive:
  110. src: "{{ sync_tmpdir }}/{{ etcd_cert_subdir }}.tgz"
  111. dest: "{{ etcd_cert_config_dir }}"
  112. when: etcd_client_flannel_certs_missing is defined and etcd_client_flannel_certs_missing
  113. - file:
  114. path: "{{ etcd_cert_config_dir }}/{{ item }}"
  115. owner: root
  116. group: root
  117. mode: 0600
  118. with_items:
  119. - node.etcd-client.crt
  120. - node.etcd-client.key
  121. - node.etcd-ca.crt
  122. when: etcd_client_flannel_certs_missing is defined and etcd_client_flannel_certs_missing
  123. - name: Create node certificates
  124. hosts: oo_first_master
  125. vars:
  126. nodes_needing_certs: "{{ hostvars
  127. | oo_select_keys(groups['oo_nodes_to_config']
  128. | default([]))
  129. | oo_filter_list(filter_attr='certs_missing') }}"
  130. sync_tmpdir: "{{ hostvars.localhost.mktemp.stdout }}"
  131. roles:
  132. - openshift_node_certificates
  133. post_tasks:
  134. - name: Create a tarball of the node config directories
  135. command: >
  136. tar -czvf {{ item.config_dir }}.tgz
  137. --transform 's|system:{{ item.node_subdir }}|node|'
  138. -C {{ item.config_dir }} .
  139. args:
  140. creates: "{{ item.config_dir }}.tgz"
  141. with_items: nodes_needing_certs
  142. - name: Retrieve the node config tarballs from the master
  143. fetch:
  144. src: "{{ item.config_dir }}.tgz"
  145. dest: "{{ sync_tmpdir }}/"
  146. flat: yes
  147. fail_on_missing: yes
  148. validate_checksum: yes
  149. with_items: nodes_needing_certs
  150. - name: Configure node instances
  151. hosts: oo_nodes_to_config
  152. vars:
  153. sync_tmpdir: "{{ hostvars.localhost.mktemp.stdout }}"
  154. openshift_node_master_api_url: "{{ hostvars[groups.oo_first_master.0].openshift.master.api_url }}"
  155. # TODO: Prefix flannel role variables.
  156. etcd_urls: "{{ hostvars[groups.oo_first_master.0].openshift.master.etcd_urls }}"
  157. embedded_etcd: "{{ hostvars[groups.oo_first_master.0].openshift.master.embedded_etcd }}"
  158. openshift_node_first_master_ip: "{{ hostvars[groups.oo_first_master.0].openshift.common.ip }}"
  159. pre_tasks:
  160. - name: Ensure certificate directory exists
  161. file:
  162. path: "{{ node_cert_dir }}"
  163. state: directory
  164. # TODO: notify restart node
  165. # possibly test service started time against certificate/config file
  166. # timestamps in node to trigger notify
  167. - name: Unarchive the tarball on the node
  168. unarchive:
  169. src: "{{ sync_tmpdir }}/{{ node_subdir }}.tgz"
  170. dest: "{{ node_cert_dir }}"
  171. when: certs_missing
  172. roles:
  173. - openshift_node
  174. - role: flannel
  175. when: openshift.common.use_flannel | bool
  176. - role: nickhammond.logrotate
  177. when: not openshift.common.is_containerized | bool
  178. - role: fluentd_node
  179. when: openshift.common.use_fluentd | bool
  180. tasks:
  181. - name: Create group for deployment type
  182. group_by: key=oo_nodes_deployment_type_{{ openshift.common.deployment_type }}
  183. changed_when: False
  184. - name: Delete temporary directory on localhost
  185. hosts: localhost
  186. connection: local
  187. become: no
  188. gather_facts: no
  189. tasks:
  190. - file: name={{ mktemp.stdout }} state=absent
  191. changed_when: False
  192. # Additional config for online type deployments
  193. - name: Additional instance config
  194. hosts: oo_nodes_deployment_type_online
  195. gather_facts: no
  196. roles:
  197. - os_env_extras
  198. - os_env_extras_node
  199. - name: Set schedulability
  200. hosts: oo_first_master
  201. vars:
  202. openshift_nodes: "{{ hostvars
  203. | oo_select_keys(groups['oo_nodes_to_config'])
  204. | oo_collect('openshift.common.hostname') }}"
  205. openshift_node_vars: "{{ hostvars | oo_select_keys(groups['oo_nodes_to_config']) }}"
  206. pre_tasks:
  207. roles:
  208. - openshift_manage_node