Skip to content

Commit 38e0c9c

Browse files
committed
Disable swap space on nodes at install and upgrade
1 parent 2942b03 commit 38e0c9c

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

roles/openshift_node/tasks/main.yml

+27
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,33 @@
3434
dns_ip: "{{ openshift_dns_ip | default(none) | get_dns_ip(hostvars[inventory_hostname])}}"
3535
env_vars: "{{ openshift_node_env_vars | default(None) }}"
3636

37+
# https://docs.openshift.com/container-platform/3.4/admin_guide/overcommit.html#disabling-swap-memory
38+
- name: Check for swap usage
39+
command: grep "^[^#].*swap" /etc/fstab
40+
# grep: match any lines which don't begin with '#' and contain 'swap'
41+
# command: swapon --summary
42+
# Alternate option, however if swap entries are in fstab, swap will be
43+
# enabled at boot. Grepping fstab should catch a condition when swap was
44+
# disabled, but the fstab entries were not removed.
45+
changed_when: false
46+
failed_when: false
47+
register: swap_result
48+
49+
# Disable Swap Block
50+
- block:
51+
52+
- name: Disable swap
53+
command: swapoff --all
54+
55+
- name: Remove swap entries from /etc/fstab
56+
lineinfile:
57+
dest: /etc/fstab
58+
regexp: 'swap'
59+
state: absent
60+
61+
when: swap_result.stdout_lines | length > 0
62+
# End Disable Swap Block
63+
3764
# We have to add tuned-profiles in the same transaction otherwise we run into depsolving
3865
# problems because the rpms don't pin the version properly. This was fixed in 3.1 packaging.
3966
- name: Install Node package

roles/openshift_node_upgrade/tasks/main.yml

+27
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,33 @@
8484
value: "{{ oreg_url }}"
8585
when: oreg_url is defined
8686

87+
# https://docs.openshift.com/container-platform/3.4/admin_guide/overcommit.html#disabling-swap-memory
88+
- name: Check for swap usage
89+
command: grep "^[^#].*swap" /etc/fstab
90+
# grep: match any lines which don't begin with '#' and contain 'swap'
91+
# command: swapon --summary
92+
# Alternate option, however if swap entries are in fstab, swap will be
93+
# enabled at boot. Grepping fstab should catch a condition when swap was
94+
# disabled, but the fstab entries were not removed.
95+
changed_when: false
96+
failed_when: false
97+
register: swap_result
98+
99+
# Disable Swap Block
100+
- block:
101+
102+
- name: Disable swap
103+
command: swapoff --all
104+
105+
- name: Remove swap entries from /etc/fstab
106+
lineinfile:
107+
dest: /etc/fstab
108+
regexp: 'swap'
109+
state: absent
110+
111+
when: swap_result.stdout_lines | length > 0
112+
# End Disable Swap Block
113+
87114
- name: Restart rpm node service
88115
service:
89116
name: "{{ openshift.common.service_type }}-node"

0 commit comments

Comments
 (0)