config.yml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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
  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
  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_sudo: "{{ 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. roles:
  113. - openshift_node
  114. - name: Configure node instances
  115. hosts: oo_nodes_to_config:!oo_containerized_master_nodes
  116. vars:
  117. openshift_node_master_api_url: "{{ hostvars[groups.oo_first_master.0].openshift.master.api_url }}"
  118. openshift_node_first_master_ip: "{{ hostvars[groups.oo_first_master.0].openshift.common.ip }}"
  119. roles:
  120. - openshift_node
  121. - name: Gather and set facts for flannel certificatess
  122. hosts: oo_nodes_to_config
  123. tasks:
  124. - name: Check status of flannel external etcd certificates
  125. stat:
  126. path: "{{ openshift.common.config_base }}/node/{{ item }}"
  127. with_items:
  128. - node.etcd-client.crt
  129. - node.etcd-ca.crt
  130. register: g_external_etcd_flannel_cert_stat_result
  131. when: groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config and (openshift.common.use_flannel | bool)
  132. - set_fact:
  133. etcd_client_flannel_certs_missing: "{{ g_external_etcd_flannel_cert_stat_result.results
  134. | oo_collect(attribute='stat.exists')
  135. | list | intersect([false])}}"
  136. etcd_cert_subdir: openshift-node-{{ openshift.common.hostname }}
  137. etcd_cert_config_dir: "{{ openshift.common.config_base }}/node"
  138. etcd_cert_prefix: node.etcd-
  139. when: groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config and (openshift.common.use_flannel | bool)
  140. - name: Configure flannel etcd certificates
  141. hosts: oo_first_etcd
  142. vars:
  143. etcd_generated_certs_dir: /etc/etcd/generated_certs
  144. sync_tmpdir: "{{ hostvars.localhost.mktemp.stdout }}"
  145. pre_tasks:
  146. - set_fact:
  147. etcd_needing_client_certs: "{{ hostvars
  148. | oo_select_keys(groups['oo_nodes_to_config'])
  149. | oo_filter_list(filter_attr='etcd_client_flannel_certs_missing') | default([]) }}"
  150. when: etcd_client_flannel_certs_missing is defined and etcd_client_flannel_certs_missing
  151. roles:
  152. - role: etcd_certificates
  153. when: openshift_use_flannel | default(false) | bool
  154. post_tasks:
  155. - name: Create a tarball of the etcd flannel certs
  156. command: >
  157. tar -czvf {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz
  158. -C {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }} .
  159. args:
  160. creates: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
  161. with_items: etcd_needing_client_certs
  162. when: etcd_client_flannel_certs_missing is defined and etcd_client_flannel_certs_missing
  163. - name: Retrieve the etcd cert tarballs
  164. fetch:
  165. src: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
  166. dest: "{{ sync_tmpdir }}/"
  167. flat: yes
  168. fail_on_missing: yes
  169. validate_checksum: yes
  170. with_items: etcd_needing_client_certs
  171. when: etcd_client_flannel_certs_missing is defined and etcd_client_flannel_certs_missing
  172. - name: Copy the external etcd flannel certs to the nodes
  173. hosts: oo_nodes_to_config
  174. vars:
  175. sync_tmpdir: "{{ hostvars.localhost.mktemp.stdout }}"
  176. tasks:
  177. - name: Ensure certificate directory exists
  178. file:
  179. path: "{{ openshift.common.config_base }}/node"
  180. state: directory
  181. when: etcd_client_flannel_certs_missing is defined and etcd_client_flannel_certs_missing
  182. - name: Unarchive the tarball on the master
  183. unarchive:
  184. src: "{{ sync_tmpdir }}/{{ etcd_cert_subdir }}.tgz"
  185. dest: "{{ etcd_cert_config_dir }}"
  186. when: etcd_client_flannel_certs_missing is defined and etcd_client_flannel_certs_missing
  187. - file:
  188. path: "{{ etcd_cert_config_dir }}/{{ item }}"
  189. owner: root
  190. group: root
  191. mode: 0600
  192. with_items:
  193. - node.etcd-client.crt
  194. - node.etcd-client.key
  195. - node.etcd-ca.crt
  196. when: etcd_client_flannel_certs_missing is defined and etcd_client_flannel_certs_missing
  197. - name: Additional node config
  198. hosts: oo_nodes_to_config
  199. vars:
  200. # TODO: Prefix flannel role variables.
  201. openshift_node_master_api_url: "{{ hostvars[groups.oo_first_master.0].openshift.master.api_url }}"
  202. etcd_urls: "{{ hostvars[groups.oo_first_master.0].openshift.master.etcd_urls }}"
  203. embedded_etcd: "{{ hostvars[groups.oo_first_master.0].openshift.master.embedded_etcd }}"
  204. roles:
  205. - role: flannel
  206. when: openshift.common.use_flannel | bool
  207. - role: nuage_node
  208. when: openshift.common.use_nuage | bool
  209. - role: nickhammond.logrotate
  210. tasks:
  211. - name: Create group for deployment type
  212. group_by: key=oo_nodes_deployment_type_{{ openshift.common.deployment_type }}
  213. changed_when: False
  214. - name: Delete temporary directory on localhost
  215. hosts: localhost
  216. connection: local
  217. become: no
  218. gather_facts: no
  219. tasks:
  220. - file: name={{ mktemp.stdout }} state=absent
  221. changed_when: False
  222. # Additional config for online type deployments
  223. - name: Additional instance config
  224. hosts: oo_nodes_deployment_type_online
  225. gather_facts: no
  226. roles:
  227. - os_env_extras
  228. - os_env_extras_node
  229. - name: Set schedulability
  230. hosts: oo_first_master
  231. vars:
  232. openshift_nodes: "{{ hostvars
  233. | oo_select_keys(groups['oo_nodes_to_config'])
  234. | oo_collect('openshift.common.hostname') }}"
  235. openshift_node_vars: "{{ hostvars | oo_select_keys(groups['oo_nodes_to_config']) }}"
  236. pre_tasks:
  237. # Necessary because when you're on a node that's also a master the master will be
  238. # restarted after the node restarts docker and it will take up to 60 seconds for
  239. # systemd to start the master again
  240. - name: Wait for master API to become available before proceeding
  241. # Using curl here since the uri module requires python-httplib2 and
  242. # wait_for port doesn't provide health information.
  243. command: >
  244. curl --silent --cacert {{ openshift.master.config_dir }}/master/ca.crt
  245. {{ openshift.master.api_url }}/healthz/ready
  246. register: api_available_output
  247. until: api_available_output.stdout == 'ok'
  248. retries: 120
  249. delay: 1
  250. changed_when: false
  251. when: openshift.common.is_containerized | bool
  252. roles:
  253. - openshift_manage_node