main.yml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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
  7. deployment_type in ['enterprise', 'online', 'atomic-enterprise', 'openshift-enterprise']
  8. - name: Set node facts
  9. openshift_facts:
  10. role: "{{ item.role }}"
  11. local_facts: "{{ item.local_facts }}"
  12. with_items:
  13. # Reset node labels to an empty dictionary.
  14. - role: node
  15. local_facts:
  16. labels: {}
  17. - role: node
  18. local_facts:
  19. annotations: "{{ openshift_node_annotations | default(none) }}"
  20. debug_level: "{{ openshift_node_debug_level | default(openshift.common.debug_level) }}"
  21. iptables_sync_period: "{{ openshift_node_iptables_sync_period | default(None) }}"
  22. kubelet_args: "{{ openshift_node_kubelet_args | default(None) }}"
  23. labels: "{{ lookup('oo_option', 'openshift_node_labels') | default( openshift_node_labels | default(none), true) }}"
  24. registry_url: "{{ oreg_url_node | default(oreg_url) | default(None) }}"
  25. schedulable: "{{ openshift_schedulable | default(openshift_scheduleable) | default(None) }}"
  26. sdn_mtu: "{{ openshift_node_sdn_mtu | default(None) }}"
  27. storage_plugin_deps: "{{ osn_storage_plugin_deps | default(None) }}"
  28. set_node_ip: "{{ openshift_set_node_ip | default(None) }}"
  29. node_image: "{{ osn_image | default(None) }}"
  30. ovs_image: "{{ osn_ovs_image | default(None) }}"
  31. proxy_mode: "{{ openshift_node_proxy_mode | default('iptables') }}"
  32. local_quota_per_fsgroup: "{{ openshift_node_local_quota_per_fsgroup | default(None) }}"
  33. dns_ip: "{{ openshift_dns_ip | default(none) | get_dns_ip(hostvars[inventory_hostname])}}"
  34. env_vars: "{{ openshift_node_env_vars | default(None) }}"
  35. # https://docs.openshift.com/container-platform/3.4/admin_guide/overcommit.html#disabling-swap-memory
  36. - name: Check for swap usage
  37. command: grep "^[^#].*swap" /etc/fstab
  38. # grep: match any lines which don't begin with '#' and contain 'swap'
  39. changed_when: false
  40. failed_when: false
  41. register: swap_result
  42. # Disable Swap Block
  43. - block:
  44. - name: Disable swap
  45. command: swapoff --all
  46. - name: Remove swap entries from /etc/fstab
  47. replace:
  48. dest: /etc/fstab
  49. regexp: '(^[^#].*swap.*)'
  50. replace: '# \1'
  51. backup: yes
  52. - name: Add notice about disabling swap
  53. lineinfile:
  54. dest: /etc/fstab
  55. line: '# OpenShift-Ansible Installer disabled swap per overcommit guidelines'
  56. state: present
  57. when:
  58. - swap_result.stdout_lines | length > 0
  59. - openshift_disable_swap | default(true) | bool
  60. # End Disable Swap Block
  61. # We have to add tuned-profiles in the same transaction otherwise we run into depsolving
  62. # problems because the rpms don't pin the version properly. This was fixed in 3.1 packaging.
  63. - name: Install Node package
  64. package:
  65. name: "{{ openshift.common.service_type }}-node{{ openshift_pkg_version | default('') | oo_image_tag_to_rpm_version(include_dash=True) }},tuned-profiles-{{ openshift.common.service_type }}-node{{ openshift_pkg_version | default('') | oo_image_tag_to_rpm_version(include_dash=True) }}"
  66. state: present
  67. when: not openshift.common.is_containerized | bool
  68. - name: Check for tuned package
  69. command: rpm -q tuned
  70. args:
  71. warn: no
  72. register: tuned_installed
  73. changed_when: false
  74. failed_when: false
  75. - name: Set atomic-guest tuned profile
  76. command: "tuned-adm profile atomic-guest"
  77. when: tuned_installed.rc == 0 and openshift.common.is_atomic | bool
  78. - name: Install sdn-ovs package
  79. package:
  80. name: "{{ openshift.common.service_type }}-sdn-ovs{{ openshift_pkg_version | oo_image_tag_to_rpm_version(include_dash=True) }}"
  81. state: present
  82. when:
  83. - openshift.common.use_openshift_sdn | default(true) | bool
  84. - not openshift.common.is_containerized | bool
  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: Configure AWS Cloud Provider Settings
  134. lineinfile:
  135. dest: /etc/sysconfig/{{ openshift.common.service_type }}-node
  136. regexp: "{{ item.regex }}"
  137. line: "{{ item.line }}"
  138. create: true
  139. with_items:
  140. - regex: '^AWS_ACCESS_KEY_ID='
  141. line: "AWS_ACCESS_KEY_ID={{ openshift_cloudprovider_aws_access_key | default('') }}"
  142. - regex: '^AWS_SECRET_ACCESS_KEY='
  143. line: "AWS_SECRET_ACCESS_KEY={{ openshift_cloudprovider_aws_secret_key | default('') }}"
  144. no_log: True
  145. 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
  146. notify:
  147. - restart node
  148. - name: Configure Node Environment Variables
  149. lineinfile:
  150. dest: /etc/sysconfig/{{ openshift.common.service_type }}-node
  151. regexp: "^{{ item.key }}="
  152. line: "{{ item.key }}={{ item.value }}"
  153. create: true
  154. with_dict: "{{ openshift.node.env_vars | default({}) }}"
  155. notify:
  156. - restart node
  157. - name: NFS storage plugin configuration
  158. include: storage_plugins/nfs.yml
  159. tags:
  160. - nfs
  161. - name: GlusterFS storage plugin configuration
  162. include: storage_plugins/glusterfs.yml
  163. when: "'glusterfs' in openshift.node.storage_plugin_deps"
  164. - name: Ceph storage plugin configuration
  165. include: storage_plugins/ceph.yml
  166. when: "'ceph' in openshift.node.storage_plugin_deps"
  167. - name: iSCSI storage plugin configuration
  168. include: storage_plugins/iscsi.yml
  169. when: "'iscsi' in openshift.node.storage_plugin_deps"
  170. # Necessary because when you're on a node that's also a master the master will be
  171. # restarted after the node restarts docker and it will take up to 60 seconds for
  172. # systemd to start the master again
  173. - name: Wait for master API to become available before proceeding
  174. # Using curl here since the uri module requires python-httplib2 and
  175. # wait_for port doesn't provide health information.
  176. command: >
  177. curl --silent --tlsv1.2 --cacert {{ openshift.common.config_base }}/node/ca.crt
  178. {{ openshift_node_master_api_url }}/healthz/ready
  179. args:
  180. # Disables the following warning:
  181. # Consider using get_url or uri module rather than running curl
  182. warn: no
  183. register: api_available_output
  184. until: api_available_output.stdout == 'ok'
  185. retries: 120
  186. delay: 1
  187. changed_when: false
  188. when: openshift.common.is_containerized | bool
  189. - name: Start and enable node dep
  190. systemd:
  191. daemon_reload: yes
  192. name: "{{ openshift.common.service_type }}-node-dep"
  193. enabled: yes
  194. state: started
  195. when: openshift.common.is_containerized | bool
  196. - name: Start and enable node
  197. systemd:
  198. name: "{{ openshift.common.service_type }}-node"
  199. enabled: yes
  200. state: started
  201. daemon_reload: yes
  202. register: node_start_result
  203. until: not node_start_result | failed
  204. retries: 1
  205. delay: 30
  206. ignore_errors: true
  207. - name: Dump logs from node service if it failed
  208. command: journalctl --no-pager -n 100 -u {{ openshift.common.service_type }}-node
  209. when: node_start_result | failed
  210. - name: Abort if node failed to start
  211. fail:
  212. msg: Node failed to start please inspect the logs and try again
  213. when: node_start_result | failed
  214. - set_fact:
  215. node_service_status_changed: "{{ node_start_result | changed }}"