config.yml 10 KB

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