config.yml 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. ---
  2. - name: Gather and set facts for node hosts
  3. hosts: oo_nodes_to_config
  4. vars:
  5. t_oo_option_node_debug_level: "{{ lookup('oo_option', 'openshift_node_debug_level') }}"
  6. pre_tasks:
  7. - set_fact:
  8. openshift_node_debug_level: "{{ t_oo_option_node_debug_level }}"
  9. when: openshift_node_debug_level is not defined and t_oo_option_node_debug_level != ""
  10. roles:
  11. - openshift_facts
  12. tasks:
  13. # Since the master is generating the node certificates before they are
  14. # configured, we need to make sure to set the node properties beforehand if
  15. # we do not want the defaults
  16. - openshift_facts:
  17. role: node
  18. local_facts:
  19. labels: "{{ openshift_node_labels | default(None) }}"
  20. annotations: "{{ openshift_node_annotations | default(None) }}"
  21. schedulable: "{{ openshift_schedulable | default(openshift_scheduleable) | default(None) }}"
  22. - name: Check status of node certificates
  23. stat:
  24. path: "{{ openshift.common.config_base }}/node/{{ item }}"
  25. with_items:
  26. - "system:node:{{ openshift.common.hostname }}.crt"
  27. - "system:node:{{ openshift.common.hostname }}.key"
  28. - "system:node:{{ openshift.common.hostname }}.kubeconfig"
  29. - ca.crt
  30. - server.key
  31. - server.crt
  32. register: stat_result
  33. - set_fact:
  34. certs_missing: "{{ stat_result.results | oo_collect(attribute='stat.exists')
  35. | list | intersect([false])}}"
  36. node_subdir: node-{{ openshift.common.hostname }}
  37. config_dir: "{{ openshift.common.config_base }}/generated-configs/node-{{ openshift.common.hostname }}"
  38. node_cert_dir: "{{ openshift.common.config_base }}/node"
  39. - name: Create temp directory for syncing certs
  40. hosts: localhost
  41. connection: local
  42. become: no
  43. gather_facts: no
  44. tasks:
  45. - name: Create local temp directory for syncing certs
  46. local_action: command mktemp -d /tmp/openshift-ansible-XXXXXXX
  47. register: mktemp
  48. changed_when: False
  49. - name: Create node certificates
  50. hosts: oo_first_master
  51. vars:
  52. nodes_needing_certs: "{{ hostvars
  53. | oo_select_keys(groups['oo_nodes_to_config']
  54. | default([]))
  55. | oo_filter_list(filter_attr='certs_missing') }}"
  56. sync_tmpdir: "{{ hostvars.localhost.mktemp.stdout }}"
  57. roles:
  58. - openshift_node_certificates
  59. post_tasks:
  60. - name: Create a tarball of the node config directories
  61. command: >
  62. tar -czvf {{ item.config_dir }}.tgz
  63. --transform 's|system:{{ item.node_subdir }}|node|'
  64. -C {{ item.config_dir }} .
  65. args:
  66. creates: "{{ item.config_dir }}.tgz"
  67. with_items: "{{ nodes_needing_certs | default([]) }}"
  68. - name: Retrieve the node config tarballs from the master
  69. fetch:
  70. src: "{{ item.config_dir }}.tgz"
  71. dest: "{{ sync_tmpdir }}/"
  72. flat: yes
  73. fail_on_missing: yes
  74. validate_checksum: yes
  75. with_items: "{{ nodes_needing_certs | default([]) }}"
  76. - name: Deploy node certificates
  77. hosts: oo_nodes_to_config
  78. vars:
  79. sync_tmpdir: "{{ hostvars.localhost.mktemp.stdout }}"
  80. tasks:
  81. - name: Ensure certificate directory exists
  82. file:
  83. path: "{{ node_cert_dir }}"
  84. state: directory
  85. # TODO: notify restart node
  86. # possibly test service started time against certificate/config file
  87. # timestamps in node to trigger notify
  88. - name: Unarchive the tarball on the node
  89. unarchive:
  90. src: "{{ sync_tmpdir }}/{{ node_subdir }}.tgz"
  91. dest: "{{ node_cert_dir }}"
  92. when: certs_missing
  93. - name: Evaluate node groups
  94. hosts: localhost
  95. become: no
  96. connection: local
  97. tasks:
  98. - name: Evaluate oo_containerized_master_nodes
  99. add_host:
  100. name: "{{ item }}"
  101. groups: oo_containerized_master_nodes
  102. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  103. ansible_become: "{{ g_sudo | default(omit) }}"
  104. with_items: "{{ groups.oo_nodes_to_config | default([]) }}"
  105. when: hostvars[item].openshift.common.is_containerized | bool and (item in groups.oo_nodes_to_config and item in groups.oo_masters_to_config)
  106. - name: Configure node instances
  107. hosts: oo_containerized_master_nodes
  108. serial: 1
  109. vars:
  110. openshift_node_master_api_url: "{{ hostvars[groups.oo_first_master.0].openshift.master.api_url }}"
  111. openshift_node_first_master_ip: "{{ hostvars[groups.oo_first_master.0].openshift.common.ip }}"
  112. openshift_docker_hosted_registry_network: "{{ hostvars[groups.oo_first_master.0].openshift.common.portal_net }}"
  113. roles:
  114. - openshift_node
  115. - name: Configure node instances
  116. hosts: oo_nodes_to_config:!oo_containerized_master_nodes
  117. vars:
  118. openshift_node_master_api_url: "{{ hostvars[groups.oo_first_master.0].openshift.master.api_url }}"
  119. openshift_node_first_master_ip: "{{ hostvars[groups.oo_first_master.0].openshift.common.ip }}"
  120. openshift_docker_hosted_registry_network: "{{ hostvars[groups.oo_first_master.0].openshift.common.portal_net }}"
  121. roles:
  122. - openshift_node
  123. - name: Gather and set facts for flannel certificatess
  124. hosts: oo_nodes_to_config
  125. tasks:
  126. - name: Check status of flannel external etcd certificates
  127. stat:
  128. path: "{{ openshift.common.config_base }}/node/{{ item }}"
  129. with_items:
  130. - node.etcd-client.crt
  131. - node.etcd-ca.crt
  132. register: g_external_etcd_flannel_cert_stat_result
  133. when: groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config and (openshift.common.use_flannel | bool)
  134. - set_fact:
  135. etcd_client_flannel_certs_missing: "{{ False in g_external_etcd_flannel_cert_stat_result.results
  136. | oo_collect(attribute='stat.exists')
  137. | list }}"
  138. etcd_cert_subdir: openshift-node-{{ openshift.common.hostname }}
  139. etcd_cert_config_dir: "{{ openshift.common.config_base }}/node"
  140. etcd_cert_prefix: node.etcd-
  141. etcd_hostname: "{{ openshift.common.hostname }}"
  142. etcd_ip: "{{ openshift.common.ip }}"
  143. when: groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config | length > 0 and (openshift.common.use_flannel | bool)
  144. - name: Configure flannel etcd certificates
  145. hosts: oo_first_etcd
  146. vars:
  147. etcd_generated_certs_dir: /etc/etcd/generated_certs
  148. sync_tmpdir: "{{ hostvars.localhost.mktemp.stdout }}"
  149. pre_tasks:
  150. - set_fact:
  151. etcd_needing_client_certs: "{{ hostvars
  152. | oo_select_keys(groups['oo_nodes_to_config'])
  153. | oo_filter_list('etcd_client_flannel_certs_missing') | default([]) }}"
  154. roles:
  155. - role: openshift_etcd_certificates
  156. when: openshift_use_flannel | default(false) | bool
  157. post_tasks:
  158. - name: Create a tarball of the etcd flannel certs
  159. command: >
  160. tar -czvf {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz
  161. -C {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }} .
  162. args:
  163. creates: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
  164. with_items: etcd_needing_client_certs | default([])
  165. - name: Retrieve the etcd cert tarballs
  166. fetch:
  167. src: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
  168. dest: "{{ sync_tmpdir }}/"
  169. flat: yes
  170. fail_on_missing: yes
  171. validate_checksum: yes
  172. with_items: etcd_needing_client_certs | default([])
  173. - name: Copy the external etcd flannel certs to the nodes
  174. hosts: oo_nodes_to_config
  175. vars:
  176. sync_tmpdir: "{{ hostvars.localhost.mktemp.stdout }}"
  177. tasks:
  178. - name: Ensure certificate directory exists
  179. file:
  180. path: "{{ openshift.common.config_base }}/node"
  181. state: directory
  182. when: etcd_client_flannel_certs_missing | default(false) | bool
  183. - name: Unarchive the tarball on the master
  184. unarchive:
  185. src: "{{ sync_tmpdir }}/{{ etcd_cert_subdir }}.tgz"
  186. dest: "{{ etcd_cert_config_dir }}"
  187. when: etcd_client_flannel_certs_missing | default(false) | bool
  188. - file:
  189. path: "{{ etcd_cert_config_dir }}/{{ item }}"
  190. owner: root
  191. group: root
  192. mode: 0600
  193. with_items:
  194. - node.etcd-client.crt
  195. - node.etcd-client.key
  196. - node.etcd-ca.crt
  197. when: etcd_client_flannel_certs_missing | default(false) | bool
  198. - name: Additional node config
  199. hosts: oo_nodes_to_config
  200. vars:
  201. # TODO: Prefix flannel role variables.
  202. openshift_node_master_api_url: "{{ hostvars[groups.oo_first_master.0].openshift.master.api_url }}"
  203. etcd_urls: "{{ hostvars[groups.oo_first_master.0].openshift.master.etcd_urls }}"
  204. embedded_etcd: "{{ hostvars[groups.oo_first_master.0].openshift.master.embedded_etcd }}"
  205. roles:
  206. - role: flannel
  207. when: openshift.common.use_flannel | bool
  208. - role: nuage_node
  209. when: openshift.common.use_nuage | bool
  210. - role: nickhammond.logrotate
  211. tasks:
  212. - name: Create group for deployment type
  213. group_by: key=oo_nodes_deployment_type_{{ openshift.common.deployment_type }}
  214. changed_when: False
  215. - name: Delete temporary directory on localhost
  216. hosts: localhost
  217. connection: local
  218. become: no
  219. gather_facts: no
  220. tasks:
  221. - file: name={{ mktemp.stdout }} state=absent
  222. changed_when: False
  223. - name: Set schedulability
  224. hosts: oo_first_master
  225. vars:
  226. openshift_nodes: "{{ hostvars
  227. | oo_select_keys(groups['oo_nodes_to_config'])
  228. | oo_collect('openshift.common.hostname') }}"
  229. openshift_node_vars: "{{ hostvars | oo_select_keys(groups['oo_nodes_to_config']) }}"
  230. pre_tasks:
  231. # Necessary because when you're on a node that's also a master the master will be
  232. # restarted after the node restarts docker and it will take up to 60 seconds for
  233. # systemd to start the master again
  234. - name: Wait for master API to become available before proceeding
  235. # Using curl here since the uri module requires python-httplib2 and
  236. # wait_for port doesn't provide health information.
  237. command: >
  238. curl --silent --cacert {{ openshift.common.config_base }}/master/ca.crt
  239. {{ openshift.master.api_url }}/healthz/ready
  240. register: api_available_output
  241. until: api_available_output.stdout == 'ok'
  242. retries: 120
  243. delay: 1
  244. changed_when: false
  245. when: openshift.common.is_containerized | bool
  246. roles:
  247. - openshift_manage_node