main.yml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. ---
  2. # TODO: allow for overriding default ports where possible
  3. - fail:
  4. msg: "SELinux is disabled, This deployment type requires that SELinux is enabled."
  5. when:
  6. - (not ansible_selinux or ansible_selinux.status != 'enabled') and deployment_type in ['enterprise', 'online', 'atomic-enterprise', 'openshift-enterprise']
  7. - not openshift_use_crio | default(false)
  8. - name: setup firewall
  9. include: firewall.yml
  10. static: yes
  11. - name: Set node facts
  12. openshift_facts:
  13. role: "{{ item.role }}"
  14. local_facts: "{{ item.local_facts }}"
  15. with_items:
  16. # Reset node labels to an empty dictionary.
  17. - role: node
  18. local_facts:
  19. labels: {}
  20. - role: node
  21. local_facts:
  22. annotations: "{{ openshift_node_annotations | default(none) }}"
  23. debug_level: "{{ openshift_node_debug_level | default(openshift.common.debug_level) }}"
  24. iptables_sync_period: "{{ openshift_node_iptables_sync_period | default(None) }}"
  25. kubelet_args: "{{ openshift_node_kubelet_args | default(None) }}"
  26. labels: "{{ lookup('oo_option', 'openshift_node_labels') | default( openshift_node_labels | default(none), true) }}"
  27. registry_url: "{{ oreg_url_node | default(oreg_url) | default(None) }}"
  28. schedulable: "{{ openshift_schedulable | default(openshift_scheduleable) | default(None) }}"
  29. sdn_mtu: "{{ openshift_node_sdn_mtu | default(None) }}"
  30. storage_plugin_deps: "{{ osn_storage_plugin_deps | default(None) }}"
  31. set_node_ip: "{{ openshift_set_node_ip | default(None) }}"
  32. node_image: "{{ osn_image | default(None) }}"
  33. ovs_image: "{{ osn_ovs_image | default(None) }}"
  34. proxy_mode: "{{ openshift_node_proxy_mode | default('iptables') }}"
  35. local_quota_per_fsgroup: "{{ openshift_node_local_quota_per_fsgroup | default(None) }}"
  36. dns_ip: "{{ openshift_dns_ip | default(none) | get_dns_ip(hostvars[inventory_hostname])}}"
  37. env_vars: "{{ openshift_node_env_vars | default(None) }}"
  38. # https://docs.openshift.com/container-platform/3.4/admin_guide/overcommit.html#disabling-swap-memory
  39. - name: Check for swap usage
  40. command: grep "^[^#].*swap" /etc/fstab
  41. # grep: match any lines which don't begin with '#' and contain 'swap'
  42. changed_when: false
  43. failed_when: false
  44. register: swap_result
  45. # Disable Swap Block
  46. - block:
  47. - name: Disable swap
  48. command: swapoff --all
  49. - name: Remove swap entries from /etc/fstab
  50. replace:
  51. dest: /etc/fstab
  52. regexp: '(^[^#].*swap.*)'
  53. replace: '# \1'
  54. backup: yes
  55. - name: Add notice about disabling swap
  56. lineinfile:
  57. dest: /etc/fstab
  58. line: '# OpenShift-Ansible Installer disabled swap per overcommit guidelines'
  59. state: present
  60. when:
  61. - swap_result.stdout_lines | length > 0
  62. - openshift_disable_swap | default(true) | bool
  63. # End Disable Swap Block
  64. - name: Install Node package
  65. package:
  66. name: "{{ openshift.common.service_type }}-node{{ openshift_pkg_version | default('') | oo_image_tag_to_rpm_version(include_dash=True) }}"
  67. state: present
  68. when: not openshift.common.is_containerized | bool
  69. - name: setup tuned
  70. include: tuned.yml
  71. static: yes
  72. - name: Install sdn-ovs package
  73. package:
  74. name: "{{ openshift.common.service_type }}-sdn-ovs{{ openshift_pkg_version | oo_image_tag_to_rpm_version(include_dash=True) }}"
  75. state: present
  76. when:
  77. - openshift.common.use_openshift_sdn | default(true) | bool
  78. - not openshift.common.is_containerized | bool
  79. - name: Restart cri-o
  80. systemd:
  81. name: cri-o
  82. enabled: yes
  83. state: restarted
  84. when: openshift_use_crio | default(false)
  85. - name: Install conntrack-tools package
  86. package:
  87. name: "conntrack-tools"
  88. state: present
  89. when: not openshift.common.is_containerized | bool
  90. - name: Install the systemd units
  91. include: systemd_units.yml
  92. # The atomic-openshift-node service will set this parameter on
  93. # startup, but if the network service is restarted this setting is
  94. # lost. Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1372388
  95. #
  96. # Use lineinfile w/ a handler for this task until
  97. # https://github.com/ansible/ansible/pull/24277 is included in an
  98. # ansible release and we can use the sysctl module.
  99. - name: Persist net.ipv4.ip_forward sysctl entry
  100. lineinfile: dest=/etc/sysctl.conf regexp='^net.ipv4.ip_forward' line='net.ipv4.ip_forward=1'
  101. notify:
  102. - reload sysctl.conf
  103. - name: Start and enable openvswitch service
  104. systemd:
  105. name: openvswitch.service
  106. enabled: yes
  107. state: started
  108. daemon_reload: yes
  109. when:
  110. - openshift.common.is_containerized | bool
  111. - openshift.common.use_openshift_sdn | default(true) | bool
  112. register: ovs_start_result
  113. until: not ovs_start_result | failed
  114. retries: 3
  115. delay: 30
  116. - set_fact:
  117. ovs_service_status_changed: "{{ ovs_start_result | changed }}"
  118. - file:
  119. dest: "{{ (openshift_node_kubelet_args|default({'config':None})).config}}"
  120. state: directory
  121. when: openshift_node_kubelet_args is defined and 'config' in openshift_node_kubelet_args
  122. # TODO: add the validate parameter when there is a validation command to run
  123. - name: Create the Node config
  124. template:
  125. dest: "{{ openshift.common.config_base }}/node/node-config.yaml"
  126. src: node.yaml.v1.j2
  127. backup: true
  128. owner: root
  129. group: root
  130. mode: 0600
  131. notify:
  132. - restart node
  133. - name: Check for credentials file for registry auth
  134. stat:
  135. path: "{{oreg_auth_credentials_path }}"
  136. when:
  137. - oreg_auth_user is defined
  138. register: node_oreg_auth_credentials_stat
  139. - name: Create credentials for registry auth
  140. command: "docker --config={{ oreg_auth_credentials_path }} login -u {{ oreg_auth_user }} -p {{ oreg_auth_password }} {{ oreg_host }}"
  141. when:
  142. - oreg_auth_user is defined
  143. - (not node_oreg_auth_credentials_stat.stat.exists or oreg_auth_credentials_replace) | bool
  144. notify:
  145. - restart node
  146. - name: Configure AWS Cloud Provider Settings
  147. lineinfile:
  148. dest: /etc/sysconfig/{{ openshift.common.service_type }}-node
  149. regexp: "{{ item.regex }}"
  150. line: "{{ item.line }}"
  151. create: true
  152. with_items:
  153. - regex: '^AWS_ACCESS_KEY_ID='
  154. line: "AWS_ACCESS_KEY_ID={{ openshift_cloudprovider_aws_access_key | default('') }}"
  155. - regex: '^AWS_SECRET_ACCESS_KEY='
  156. line: "AWS_SECRET_ACCESS_KEY={{ openshift_cloudprovider_aws_secret_key | default('') }}"
  157. no_log: True
  158. when: openshift_cloudprovider_kind is defined and openshift_cloudprovider_kind == 'aws' and openshift_cloudprovider_aws_access_key is defined and openshift_cloudprovider_aws_secret_key is defined
  159. notify:
  160. - restart node
  161. - name: Configure Node Environment Variables
  162. lineinfile:
  163. dest: /etc/sysconfig/{{ openshift.common.service_type }}-node
  164. regexp: "^{{ item.key }}="
  165. line: "{{ item.key }}={{ item.value }}"
  166. create: true
  167. with_dict: "{{ openshift.node.env_vars | default({}) }}"
  168. notify:
  169. - restart node
  170. - name: NFS storage plugin configuration
  171. include: storage_plugins/nfs.yml
  172. tags:
  173. - nfs
  174. - name: GlusterFS storage plugin configuration
  175. include: storage_plugins/glusterfs.yml
  176. when: "'glusterfs' in openshift.node.storage_plugin_deps"
  177. - name: Ceph storage plugin configuration
  178. include: storage_plugins/ceph.yml
  179. when: "'ceph' in openshift.node.storage_plugin_deps"
  180. - name: iSCSI storage plugin configuration
  181. include: storage_plugins/iscsi.yml
  182. when: "'iscsi' in openshift.node.storage_plugin_deps"
  183. # Necessary because when you're on a node that's also a master the master will be
  184. # restarted after the node restarts docker and it will take up to 60 seconds for
  185. # systemd to start the master again
  186. - name: Wait for master API to become available before proceeding
  187. # Using curl here since the uri module requires python-httplib2 and
  188. # wait_for port doesn't provide health information.
  189. command: >
  190. curl --silent --tlsv1.2 --cacert {{ openshift.common.config_base }}/node/ca.crt
  191. {{ openshift_node_master_api_url }}/healthz/ready
  192. args:
  193. # Disables the following warning:
  194. # Consider using get_url or uri module rather than running curl
  195. warn: no
  196. register: api_available_output
  197. until: api_available_output.stdout == 'ok'
  198. retries: 120
  199. delay: 1
  200. changed_when: false
  201. when: openshift.common.is_containerized | bool
  202. - name: Start and enable node dep
  203. systemd:
  204. daemon_reload: yes
  205. name: "{{ openshift.common.service_type }}-node-dep"
  206. enabled: yes
  207. state: started
  208. when: openshift.common.is_containerized | bool
  209. - name: Start and enable node
  210. systemd:
  211. name: "{{ openshift.common.service_type }}-node"
  212. enabled: yes
  213. state: started
  214. daemon_reload: yes
  215. register: node_start_result
  216. until: not node_start_result | failed
  217. retries: 1
  218. delay: 30
  219. ignore_errors: true
  220. - name: Dump logs from node service if it failed
  221. command: journalctl --no-pager -n 100 -u {{ openshift.common.service_type }}-node
  222. when: node_start_result | failed
  223. - name: Abort if node failed to start
  224. fail:
  225. msg: Node failed to start please inspect the logs and try again
  226. when: node_start_result | failed
  227. - set_fact:
  228. node_service_status_changed: "{{ node_start_result | changed }}"