main.yml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 | 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. # command: swapon --summary
  40. # Alternate option, however if swap entries are in fstab, swap will be
  41. # enabled at boot. Grepping fstab should catch a condition when swap was
  42. # disabled, but the fstab entries were not removed.
  43. changed_when: false
  44. failed_when: false
  45. register: swap_result
  46. # Disable Swap Block
  47. - block:
  48. - name: Disable swap
  49. command: swapoff --all
  50. - name: Remove swap entries from /etc/fstab
  51. lineinfile:
  52. dest: /etc/fstab
  53. regexp: 'swap'
  54. state: absent
  55. when: swap_result.stdout_lines | length > 0
  56. # End Disable Swap Block
  57. # We have to add tuned-profiles in the same transaction otherwise we run into depsolving
  58. # problems because the rpms don't pin the version properly. This was fixed in 3.1 packaging.
  59. - name: Install Node package
  60. package:
  61. 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) }}"
  62. state: present
  63. when: not openshift.common.is_containerized | bool
  64. - name: Check for tuned package
  65. command: rpm -q tuned
  66. args:
  67. warn: no
  68. register: tuned_installed
  69. changed_when: false
  70. failed_when: false
  71. - name: Set atomic-guest tuned profile
  72. command: "tuned-adm profile atomic-guest"
  73. when: tuned_installed.rc == 0 and openshift.common.is_atomic | bool
  74. - name: Install sdn-ovs package
  75. package:
  76. name: "{{ openshift.common.service_type }}-sdn-ovs{{ openshift_pkg_version | oo_image_tag_to_rpm_version(include_dash=True) }}"
  77. state: present
  78. when: openshift.common.use_openshift_sdn and not openshift.common.is_containerized | bool
  79. - name: Install conntrack-tools package
  80. package:
  81. name: "conntrack-tools"
  82. state: present
  83. when: not openshift.common.is_containerized | bool
  84. - name: Install the systemd units
  85. include: systemd_units.yml
  86. # The atomic-openshift-node service will set this parameter on
  87. # startup, but if the network service is restarted this setting is
  88. # lost. Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1372388
  89. - name: Persist net.ipv4.ip_forward sysctl entry
  90. sysctl: name="net.ipv4.ip_forward" value=1 sysctl_set=yes state=present reload=yes
  91. - name: Start and enable openvswitch service
  92. systemd:
  93. name: openvswitch.service
  94. enabled: yes
  95. state: started
  96. when: openshift.common.is_containerized | bool and openshift.common.use_openshift_sdn | bool
  97. register: ovs_start_result
  98. - set_fact:
  99. ovs_service_status_changed: "{{ ovs_start_result | changed }}"
  100. - file:
  101. dest: "{{ (openshift_node_kubelet_args|default({'config':None})).config}}"
  102. state: directory
  103. when: openshift_node_kubelet_args is defined and 'config' in openshift_node_kubelet_args
  104. # TODO: add the validate parameter when there is a validation command to run
  105. - name: Create the Node config
  106. template:
  107. dest: "{{ openshift.common.config_base }}/node/node-config.yaml"
  108. src: node.yaml.v1.j2
  109. backup: true
  110. owner: root
  111. group: root
  112. mode: 0600
  113. notify:
  114. - restart node
  115. - name: Configure AWS Cloud Provider Settings
  116. lineinfile:
  117. dest: /etc/sysconfig/{{ openshift.common.service_type }}-node
  118. regexp: "{{ item.regex }}"
  119. line: "{{ item.line }}"
  120. create: true
  121. with_items:
  122. - regex: '^AWS_ACCESS_KEY_ID='
  123. line: "AWS_ACCESS_KEY_ID={{ openshift_cloudprovider_aws_access_key | default('') }}"
  124. - regex: '^AWS_SECRET_ACCESS_KEY='
  125. line: "AWS_SECRET_ACCESS_KEY={{ openshift_cloudprovider_aws_secret_key | default('') }}"
  126. no_log: True
  127. 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"
  128. notify:
  129. - restart node
  130. - name: Configure Node Environment Variables
  131. lineinfile:
  132. dest: /etc/sysconfig/{{ openshift.common.service_type }}-node
  133. regexp: "^{{ item.key }}="
  134. line: "{{ item.key }}={{ item.value }}"
  135. create: true
  136. with_dict: "{{ openshift.node.env_vars | default({}) }}"
  137. notify:
  138. - restart node
  139. - name: NFS storage plugin configuration
  140. include: storage_plugins/nfs.yml
  141. tags:
  142. - nfs
  143. - name: GlusterFS storage plugin configuration
  144. include: storage_plugins/glusterfs.yml
  145. when: "'glusterfs' in openshift.node.storage_plugin_deps"
  146. - name: Ceph storage plugin configuration
  147. include: storage_plugins/ceph.yml
  148. when: "'ceph' in openshift.node.storage_plugin_deps"
  149. - name: iSCSI storage plugin configuration
  150. include: storage_plugins/iscsi.yml
  151. when: "'iscsi' in openshift.node.storage_plugin_deps"
  152. # Necessary because when you're on a node that's also a master the master will be
  153. # restarted after the node restarts docker and it will take up to 60 seconds for
  154. # systemd to start the master again
  155. - name: Wait for master API to become available before proceeding
  156. # Using curl here since the uri module requires python-httplib2 and
  157. # wait_for port doesn't provide health information.
  158. command: >
  159. curl --silent --tlsv1.2 --cacert {{ openshift.common.config_base }}/node/ca.crt
  160. {{ openshift_node_master_api_url }}/healthz/ready
  161. args:
  162. # Disables the following warning:
  163. # Consider using get_url or uri module rather than running curl
  164. warn: no
  165. register: api_available_output
  166. until: api_available_output.stdout == 'ok'
  167. retries: 120
  168. delay: 1
  169. changed_when: false
  170. when: openshift.common.is_containerized | bool
  171. - name: Start and enable node dep
  172. systemd:
  173. name: "{{ openshift.common.service_type }}-node-dep"
  174. enabled: yes
  175. state: started
  176. when: openshift.common.is_containerized | bool
  177. - name: Start and enable node
  178. systemd:
  179. name: "{{ openshift.common.service_type }}-node"
  180. enabled: yes
  181. state: started
  182. register: node_start_result
  183. until: not node_start_result | failed
  184. retries: 1
  185. delay: 30
  186. - set_fact:
  187. node_service_status_changed: "{{ node_start_result | changed }}"