config.yml 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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: Create temp directory for syncing certs
  23. hosts: localhost
  24. connection: local
  25. become: no
  26. gather_facts: no
  27. tasks:
  28. - name: Create local temp directory for syncing certs
  29. local_action: command mktemp -d /tmp/openshift-ansible-XXXXXXX
  30. register: mktemp
  31. changed_when: False
  32. - name: Evaluate node groups
  33. hosts: localhost
  34. become: no
  35. connection: local
  36. tasks:
  37. - name: Evaluate oo_containerized_master_nodes
  38. add_host:
  39. name: "{{ item }}"
  40. groups: oo_containerized_master_nodes
  41. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  42. ansible_become: "{{ g_sudo | default(omit) }}"
  43. with_items: "{{ groups.oo_nodes_to_config | default([]) }}"
  44. when: hostvars[item].openshift.common.is_containerized | bool and (item in groups.oo_nodes_to_config and item in groups.oo_masters_to_config)
  45. - name: Determine openshift_version to install on nodes
  46. hosts: oo_nodes_to_config
  47. any_errors_fatal: true
  48. tasks:
  49. - debug: var=hostvars[groups.oo_first_master.0].openshift.common.version
  50. - debug: var=openshift.common.version
  51. - name: Set openshift_version to match first master for new node
  52. set_fact:
  53. openshift_version: "{{ hostvars[groups.oo_first_master.0].openshift.common.version }}"
  54. when: openshift.common.version is not defined
  55. - name: Set openshift_version to currently installed version
  56. set_fact:
  57. openshift_version: "{{ openshift.common.version }}"
  58. when: openshift.common.version is defined
  59. - debug: var=openshift_version
  60. - name: Configure node instances
  61. hosts: oo_containerized_master_nodes
  62. serial: 1
  63. vars:
  64. openshift_node_master_api_url: "{{ hostvars[groups.oo_first_master.0].openshift.master.api_url }}"
  65. openshift_node_first_master_ip: "{{ hostvars[groups.oo_first_master.0].openshift.common.ip }}"
  66. openshift_docker_hosted_registry_network: "{{ hostvars[groups.oo_first_master.0].openshift.common.portal_net }}"
  67. openshift_no_proxy_internal_hostnames: "{{ hostvars | oo_select_keys(groups['oo_nodes_to_config']
  68. | union(groups['oo_masters_to_config'])
  69. | union(groups['oo_etcd_to_config'] | default([])))
  70. | oo_collect('openshift.common.hostname') | default([]) | join (',')
  71. }}"
  72. when: "{{ (openshift_http_proxy is defined or openshift_https_proxy is defined) and
  73. openshift_generate_no_proxy_hosts | default(True) | bool }}"
  74. roles:
  75. - role: openshift_node
  76. openshift_ca_host: "{{ groups.oo_first_master.0 }}"
  77. - name: Configure node instances
  78. hosts: oo_nodes_to_config:!oo_containerized_master_nodes
  79. vars:
  80. openshift_node_master_api_url: "{{ hostvars[groups.oo_first_master.0].openshift.master.api_url }}"
  81. openshift_node_first_master_ip: "{{ hostvars[groups.oo_first_master.0].openshift.common.ip }}"
  82. openshift_docker_hosted_registry_network: "{{ hostvars[groups.oo_first_master.0].openshift.common.portal_net }}"
  83. openshift_no_proxy_internal_hostnames: "{{ hostvars | oo_select_keys(groups['oo_nodes_to_config']
  84. | union(groups['oo_masters_to_config'])
  85. | union(groups['oo_etcd_to_config'] | default([])))
  86. | oo_collect('openshift.common.hostname') | default([]) | join (',')
  87. }}"
  88. when: "{{ (openshift_http_proxy is defined or openshift_https_proxy is defined) and
  89. openshift_generate_no_proxy_hosts | default(True) | bool }}"
  90. roles:
  91. - role: openshift_node
  92. openshift_ca_host: "{{ groups.oo_first_master.0 }}"
  93. - name: Gather and set facts for flannel certificatess
  94. hosts: oo_nodes_to_config
  95. tasks:
  96. - name: Check status of flannel external etcd certificates
  97. stat:
  98. path: "{{ openshift.common.config_base }}/node/{{ item }}"
  99. with_items:
  100. - node.etcd-client.crt
  101. - node.etcd-ca.crt
  102. register: g_external_etcd_flannel_cert_stat_result
  103. when: groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config and (openshift.common.use_flannel | bool)
  104. - set_fact:
  105. etcd_client_flannel_certs_missing: "{{ False in g_external_etcd_flannel_cert_stat_result.results
  106. | oo_collect(attribute='stat.exists')
  107. | list }}"
  108. etcd_cert_subdir: openshift-node-{{ openshift.common.hostname }}
  109. etcd_cert_config_dir: "{{ openshift.common.config_base }}/node"
  110. etcd_cert_prefix: node.etcd-
  111. etcd_hostname: "{{ openshift.common.hostname }}"
  112. etcd_ip: "{{ openshift.common.ip }}"
  113. when: groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config | length > 0 and (openshift.common.use_flannel | bool)
  114. - name: Configure flannel etcd certificates
  115. hosts: oo_first_etcd
  116. vars:
  117. etcd_generated_certs_dir: /etc/etcd/generated_certs
  118. sync_tmpdir: "{{ hostvars.localhost.mktemp.stdout }}"
  119. pre_tasks:
  120. - set_fact:
  121. etcd_needing_client_certs: "{{ hostvars
  122. | oo_select_keys(groups['oo_nodes_to_config'])
  123. | oo_filter_list('etcd_client_flannel_certs_missing') | default([]) }}"
  124. roles:
  125. - role: openshift_etcd_certificates
  126. when: openshift_use_flannel | default(false) | bool
  127. post_tasks:
  128. - name: Create a tarball of the etcd flannel certs
  129. command: >
  130. tar -czvf {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz
  131. -C {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }} .
  132. args:
  133. creates: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
  134. with_items: etcd_needing_client_certs | default([])
  135. - name: Retrieve the etcd cert tarballs
  136. fetch:
  137. src: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
  138. dest: "{{ sync_tmpdir }}/"
  139. flat: yes
  140. fail_on_missing: yes
  141. validate_checksum: yes
  142. with_items: etcd_needing_client_certs | default([])
  143. - name: Copy the external etcd flannel certs to the nodes
  144. hosts: oo_nodes_to_config
  145. vars:
  146. sync_tmpdir: "{{ hostvars.localhost.mktemp.stdout }}"
  147. tasks:
  148. - name: Ensure certificate directory exists
  149. file:
  150. path: "{{ openshift.common.config_base }}/node"
  151. state: directory
  152. when: etcd_client_flannel_certs_missing | default(false) | bool
  153. - name: Unarchive the tarball on the master
  154. unarchive:
  155. src: "{{ sync_tmpdir }}/{{ etcd_cert_subdir }}.tgz"
  156. dest: "{{ etcd_cert_config_dir }}"
  157. when: etcd_client_flannel_certs_missing | default(false) | bool
  158. - file:
  159. path: "{{ etcd_cert_config_dir }}/{{ item }}"
  160. owner: root
  161. group: root
  162. mode: 0600
  163. with_items:
  164. - node.etcd-client.crt
  165. - node.etcd-client.key
  166. - node.etcd-ca.crt
  167. when: etcd_client_flannel_certs_missing | default(false) | bool
  168. - name: Additional node config
  169. hosts: oo_nodes_to_config
  170. vars:
  171. # TODO: Prefix flannel role variables.
  172. openshift_node_master_api_url: "{{ hostvars[groups.oo_first_master.0].openshift.master.api_url }}"
  173. etcd_urls: "{{ hostvars[groups.oo_first_master.0].openshift.master.etcd_urls }}"
  174. embedded_etcd: "{{ hostvars[groups.oo_first_master.0].openshift.master.embedded_etcd }}"
  175. roles:
  176. - role: flannel
  177. when: openshift.common.use_flannel | bool
  178. - role: nuage_node
  179. when: openshift.common.use_nuage | bool
  180. - role: nickhammond.logrotate
  181. tasks:
  182. - name: Create group for deployment type
  183. group_by: key=oo_nodes_deployment_type_{{ openshift.common.deployment_type }}
  184. changed_when: False
  185. - name: Delete temporary directory on localhost
  186. hosts: localhost
  187. connection: local
  188. become: no
  189. gather_facts: no
  190. tasks:
  191. - file: name={{ mktemp.stdout }} state=absent
  192. changed_when: False
  193. - name: Set schedulability
  194. hosts: oo_first_master
  195. vars:
  196. openshift_nodes: "{{ hostvars
  197. | oo_select_keys(groups['oo_nodes_to_config'])
  198. | oo_collect('openshift.common.hostname') }}"
  199. openshift_node_vars: "{{ hostvars | oo_select_keys(groups['oo_nodes_to_config']) }}"
  200. pre_tasks:
  201. # Necessary because when you're on a node that's also a master the master will be
  202. # restarted after the node restarts docker and it will take up to 60 seconds for
  203. # systemd to start the master again
  204. - name: Wait for master API to become available before proceeding
  205. # Using curl here since the uri module requires python-httplib2 and
  206. # wait_for port doesn't provide health information.
  207. command: >
  208. curl --silent --cacert {{ openshift.common.config_base }}/master/ca.crt
  209. {{ openshift.master.api_url }}/healthz/ready
  210. register: api_available_output
  211. until: api_available_output.stdout == 'ok'
  212. retries: 120
  213. delay: 1
  214. changed_when: false
  215. when: openshift.common.is_containerized | bool
  216. roles:
  217. - openshift_manage_node