main.yml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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_docker_use_crio | default(false)
  8. # https://docs.openshift.com/container-platform/3.4/admin_guide/overcommit.html#disabling-swap-memory
  9. - name: Check for swap usage
  10. command: grep "^[^#].*swap" /etc/fstab
  11. # grep: match any lines which don't begin with '#' and contain 'swap'
  12. changed_when: false
  13. failed_when: false
  14. register: swap_result
  15. # Disable Swap Block
  16. - block:
  17. - name: Disable swap
  18. command: swapoff --all
  19. - name: Remove swap entries from /etc/fstab
  20. replace:
  21. dest: /etc/fstab
  22. regexp: '(^[^#].*swap.*)'
  23. replace: '# \1'
  24. backup: yes
  25. - name: Add notice about disabling swap
  26. lineinfile:
  27. dest: /etc/fstab
  28. line: '# OpenShift-Ansible Installer disabled swap per overcommit guidelines'
  29. state: present
  30. when:
  31. - swap_result.stdout_lines | length > 0
  32. - openshift_disable_swap | default(true) | bool
  33. # End Disable Swap Block
  34. # We have to add tuned-profiles in the same transaction otherwise we run into depsolving
  35. # problems because the rpms don't pin the version properly. This was fixed in 3.1 packaging.
  36. - name: Install Node package
  37. package:
  38. 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) }}"
  39. state: present
  40. when: not openshift.common.is_containerized | bool
  41. - name: Check for tuned package
  42. command: rpm -q tuned
  43. args:
  44. warn: no
  45. register: tuned_installed
  46. changed_when: false
  47. failed_when: false
  48. - name: Set atomic-guest tuned profile
  49. command: "tuned-adm profile atomic-guest"
  50. when: tuned_installed.rc == 0 and openshift.common.is_atomic | bool
  51. - name: Install sdn-ovs package
  52. package:
  53. name: "{{ openshift.common.service_type }}-sdn-ovs{{ openshift_pkg_version | oo_image_tag_to_rpm_version(include_dash=True) }}"
  54. state: present
  55. when:
  56. - openshift.common.use_openshift_sdn | default(true) | bool
  57. - not openshift.common.is_containerized | bool
  58. - name: Restart cri-o
  59. systemd:
  60. name: cri-o
  61. enabled: yes
  62. state: restarted
  63. when: openshift_docker_use_crio | default(false)
  64. - name: Install conntrack-tools package
  65. package:
  66. name: "conntrack-tools"
  67. state: present
  68. when: not openshift.common.is_containerized | bool
  69. - name: Install the systemd units
  70. include: systemd_units.yml
  71. # The atomic-openshift-node service will set this parameter on
  72. # startup, but if the network service is restarted this setting is
  73. # lost. Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1372388
  74. #
  75. # Use lineinfile w/ a handler for this task until
  76. # https://github.com/ansible/ansible/pull/24277 is included in an
  77. # ansible release and we can use the sysctl module.
  78. - name: Persist net.ipv4.ip_forward sysctl entry
  79. lineinfile: dest=/etc/sysctl.conf regexp='^net.ipv4.ip_forward' line='net.ipv4.ip_forward=1'
  80. notify:
  81. - reload sysctl.conf
  82. - name: Start and enable openvswitch service
  83. systemd:
  84. name: openvswitch.service
  85. enabled: yes
  86. state: started
  87. daemon_reload: yes
  88. when:
  89. - openshift.common.is_containerized | bool
  90. - openshift.common.use_openshift_sdn | default(true) | bool
  91. register: ovs_start_result
  92. until: not ovs_start_result | failed
  93. retries: 3
  94. delay: 30
  95. - set_fact:
  96. ovs_service_status_changed: "{{ ovs_start_result | changed }}"
  97. - file:
  98. dest: "{{ (openshift_node_kubelet_args|default({'config':None})).config}}"
  99. state: directory
  100. when: openshift_node_kubelet_args is defined and 'config' in openshift_node_kubelet_args
  101. # TODO: add the validate parameter when there is a validation command to run
  102. - name: Create the Node config
  103. template:
  104. dest: "{{ openshift.common.config_base }}/node/node-config.yaml"
  105. src: node.yaml.v1.j2
  106. backup: true
  107. owner: root
  108. group: root
  109. mode: 0600
  110. notify:
  111. - restart node
  112. - name: Configure AWS Cloud Provider Settings
  113. lineinfile:
  114. dest: /etc/sysconfig/{{ openshift.common.service_type }}-node
  115. regexp: "{{ item.regex }}"
  116. line: "{{ item.line }}"
  117. create: true
  118. with_items:
  119. - regex: '^AWS_ACCESS_KEY_ID='
  120. line: "AWS_ACCESS_KEY_ID={{ openshift_cloudprovider_aws_access_key | default('') }}"
  121. - regex: '^AWS_SECRET_ACCESS_KEY='
  122. line: "AWS_SECRET_ACCESS_KEY={{ openshift_cloudprovider_aws_secret_key | default('') }}"
  123. no_log: True
  124. 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
  125. notify:
  126. - restart node
  127. - name: Configure Node Environment Variables
  128. lineinfile:
  129. dest: /etc/sysconfig/{{ openshift.common.service_type }}-node
  130. regexp: "^{{ item.key }}="
  131. line: "{{ item.key }}={{ item.value }}"
  132. create: true
  133. with_dict: "{{ openshift.node.env_vars | default({}) }}"
  134. notify:
  135. - restart node
  136. - name: NFS storage plugin configuration
  137. include: storage_plugins/nfs.yml
  138. tags:
  139. - nfs
  140. - name: GlusterFS storage plugin configuration
  141. include: storage_plugins/glusterfs.yml
  142. when: "'glusterfs' in openshift.node.storage_plugin_deps"
  143. - name: Ceph storage plugin configuration
  144. include: storage_plugins/ceph.yml
  145. when: "'ceph' in openshift.node.storage_plugin_deps"
  146. - name: iSCSI storage plugin configuration
  147. include: storage_plugins/iscsi.yml
  148. when: "'iscsi' in openshift.node.storage_plugin_deps"
  149. # Necessary because when you're on a node that's also a master the master will be
  150. # restarted after the node restarts docker and it will take up to 60 seconds for
  151. # systemd to start the master again
  152. - name: Wait for master API to become available before proceeding
  153. # Using curl here since the uri module requires python-httplib2 and
  154. # wait_for port doesn't provide health information.
  155. command: >
  156. curl --silent --tlsv1.2 --cacert {{ openshift.common.config_base }}/node/ca.crt
  157. {{ openshift_node_master_api_url }}/healthz/ready
  158. args:
  159. # Disables the following warning:
  160. # Consider using get_url or uri module rather than running curl
  161. warn: no
  162. register: api_available_output
  163. until: api_available_output.stdout == 'ok'
  164. retries: 120
  165. delay: 1
  166. changed_when: false
  167. when: openshift.common.is_containerized | bool
  168. - name: Start and enable node dep
  169. systemd:
  170. daemon_reload: yes
  171. name: "{{ openshift.common.service_type }}-node-dep"
  172. enabled: yes
  173. state: started
  174. when: openshift.common.is_containerized | bool
  175. - name: Start and enable node
  176. systemd:
  177. name: "{{ openshift.common.service_type }}-node"
  178. enabled: yes
  179. state: started
  180. daemon_reload: yes
  181. register: node_start_result
  182. until: not node_start_result | failed
  183. retries: 1
  184. delay: 30
  185. ignore_errors: true
  186. - name: Dump logs from node service if it failed
  187. command: journalctl --no-pager -n 100 -u {{ openshift.common.service_type }}-node
  188. when: node_start_result | failed
  189. - name: Abort if node failed to start
  190. fail:
  191. msg: Node failed to start please inspect the logs and try again
  192. when: node_start_result | failed
  193. - set_fact:
  194. node_service_status_changed: "{{ node_start_result | changed }}"