Use systemd for disabling swap when it's used (#10587)
* Mask systemd swap.target do disable swap This is a more generic way to disable swap, since it pulls .swap units in systemd distributions; fstab is only one way to generate .swap units. * Unconditionally disable swap We only care to disable it (the "swapon" registered variable is not used anywhere else. This allows to get rid of the ignore_errors, since this was added because swapon.stdout does not exist in check_mode (see issue #6642). * Don't explicitly disable swapOnZram We're already masking the swap.target, which would pull the zram unit, hence no need to handle zram-generator specifically.pull/10699/head
parent
85f15900a4
commit
2c3ea84e6f
|
@ -1,28 +1,8 @@
|
|||
---
|
||||
- name: Remove swapfile from /etc/fstab
|
||||
ansible.posix.mount:
|
||||
name: "{{ item }}"
|
||||
fstype: swap
|
||||
state: absent
|
||||
loop:
|
||||
- swap
|
||||
- none
|
||||
|
||||
# kubelet fails even if ansible_swaptotal_mb = 0
|
||||
- name: Check swap
|
||||
command: /sbin/swapon -s
|
||||
register: swapon
|
||||
changed_when: no
|
||||
- name: Mask swap.target (persist swapoff)
|
||||
ansible.builtin.systemd_service:
|
||||
name: swap.target
|
||||
masked: true
|
||||
|
||||
- name: Disable swap
|
||||
command: /sbin/swapoff -a
|
||||
when:
|
||||
- swapon.stdout
|
||||
ignore_errors: "{{ ansible_check_mode }}" # noqa ignore-errors
|
||||
|
||||
- name: Disable swapOnZram for Fedora
|
||||
command: touch /etc/systemd/zram-generator.conf
|
||||
when:
|
||||
- swapon.stdout
|
||||
- ansible_distribution in ['Fedora']
|
||||
ignore_errors: "{{ ansible_check_mode }}" # noqa ignore-errors
|
||||
|
|
Loading…
Reference in New Issue