config.yml 12 KB

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