main.yml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. # 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: Install conntrack-tools package
  59. package:
  60. name: "conntrack-tools"
  61. state: present
  62. when: not openshift.common.is_containerized | bool
  63. - name: Install the systemd units
  64. include: systemd_units.yml
  65. # The atomic-openshift-node service will set this parameter on
  66. # startup, but if the network service is restarted this setting is
  67. # lost. Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1372388
  68. #
  69. # Use lineinfile w/ a handler for this task until
  70. # https://github.com/ansible/ansible/pull/24277 is included in an
  71. # ansible release and we can use the sysctl module.
  72. - name: Persist net.ipv4.ip_forward sysctl entry
  73. lineinfile: dest=/etc/sysctl.conf regexp='^net.ipv4.ip_forward' line='net.ipv4.ip_forward=1'
  74. notify:
  75. - reload sysctl.conf
  76. - name: Start and enable openvswitch service
  77. systemd:
  78. name: openvswitch.service
  79. enabled: yes
  80. state: started
  81. daemon_reload: yes
  82. when:
  83. - openshift.common.is_containerized | bool
  84. - openshift.common.use_openshift_sdn | default(true) | bool
  85. register: ovs_start_result
  86. until: not ovs_start_result | failed
  87. retries: 3
  88. delay: 30
  89. - set_fact:
  90. ovs_service_status_changed: "{{ ovs_start_result | changed }}"
  91. - file:
  92. dest: "{{ (openshift_node_kubelet_args|default({'config':None})).config}}"
  93. state: directory
  94. when: openshift_node_kubelet_args is defined and 'config' in openshift_node_kubelet_args
  95. # TODO: add the validate parameter when there is a validation command to run
  96. - name: Create the Node config
  97. template:
  98. dest: "{{ openshift.common.config_base }}/node/node-config.yaml"
  99. src: node.yaml.v1.j2
  100. backup: true
  101. owner: root
  102. group: root
  103. mode: 0600
  104. notify:
  105. - restart node
  106. - name: Configure AWS Cloud Provider Settings
  107. lineinfile:
  108. dest: /etc/sysconfig/{{ openshift.common.service_type }}-node
  109. regexp: "{{ item.regex }}"
  110. line: "{{ item.line }}"
  111. create: true
  112. with_items:
  113. - regex: '^AWS_ACCESS_KEY_ID='
  114. line: "AWS_ACCESS_KEY_ID={{ openshift_cloudprovider_aws_access_key | default('') }}"
  115. - regex: '^AWS_SECRET_ACCESS_KEY='
  116. line: "AWS_SECRET_ACCESS_KEY={{ openshift_cloudprovider_aws_secret_key | default('') }}"
  117. no_log: True
  118. 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
  119. notify:
  120. - restart node
  121. - name: Configure Node Environment Variables
  122. lineinfile:
  123. dest: /etc/sysconfig/{{ openshift.common.service_type }}-node
  124. regexp: "^{{ item.key }}="
  125. line: "{{ item.key }}={{ item.value }}"
  126. create: true
  127. with_dict: "{{ openshift.node.env_vars | default({}) }}"
  128. notify:
  129. - restart node
  130. - name: NFS storage plugin configuration
  131. include: storage_plugins/nfs.yml
  132. tags:
  133. - nfs
  134. - name: GlusterFS storage plugin configuration
  135. include: storage_plugins/glusterfs.yml
  136. when: "'glusterfs' in openshift.node.storage_plugin_deps"
  137. - name: Ceph storage plugin configuration
  138. include: storage_plugins/ceph.yml
  139. when: "'ceph' in openshift.node.storage_plugin_deps"
  140. - name: iSCSI storage plugin configuration
  141. include: storage_plugins/iscsi.yml
  142. when: "'iscsi' in openshift.node.storage_plugin_deps"
  143. # Necessary because when you're on a node that's also a master the master will be
  144. # restarted after the node restarts docker and it will take up to 60 seconds for
  145. # systemd to start the master again
  146. - name: Wait for master API to become available before proceeding
  147. # Using curl here since the uri module requires python-httplib2 and
  148. # wait_for port doesn't provide health information.
  149. command: >
  150. curl --silent --tlsv1.2 --cacert {{ openshift.common.config_base }}/node/ca.crt
  151. {{ openshift_node_master_api_url }}/healthz/ready
  152. args:
  153. # Disables the following warning:
  154. # Consider using get_url or uri module rather than running curl
  155. warn: no
  156. register: api_available_output
  157. until: api_available_output.stdout == 'ok'
  158. retries: 120
  159. delay: 1
  160. changed_when: false
  161. when: openshift.common.is_containerized | bool
  162. - name: Start and enable node dep
  163. systemd:
  164. daemon_reload: yes
  165. name: "{{ openshift.common.service_type }}-node-dep"
  166. enabled: yes
  167. state: started
  168. when: openshift.common.is_containerized | bool
  169. - name: Start and enable node
  170. systemd:
  171. name: "{{ openshift.common.service_type }}-node"
  172. enabled: yes
  173. state: started
  174. daemon_reload: yes
  175. register: node_start_result
  176. until: not node_start_result | failed
  177. retries: 1
  178. delay: 30
  179. ignore_errors: true
  180. - name: Dump logs from node service if it failed
  181. command: journalctl --no-pager -n 100 -u {{ openshift.common.service_type }}-node
  182. when: node_start_result | failed
  183. - name: Abort if node failed to start
  184. fail:
  185. msg: Node failed to start please inspect the logs and try again
  186. when: node_start_result | failed
  187. - set_fact:
  188. node_service_status_changed: "{{ node_start_result | changed }}"