# 优化的取消交换分区
代码语言:javascript
复制- name: Remove swapfile from /etc/fstab
mount:
name: "{{ item }"
fstype: swap
state: absent
with_items:
- swap
- none
- name: check swap
command: /sbin/swapon -s
register: swapon
changed_when: no
- name: Disable swap
command: /sbin/swapoff -a
when:
- swapon.stdout
ignore_errors: yes
代码语言:javascript
复制- name: shutdown get the status of swap
shell: grep swap /etc/fstab l grep -c "#
register: swap
ignore errors: yes
tags: swap
- name: shutdown swapoff -a
shell: swapoff -a
when: swap.stdout == "0"
ignore errors: yes
tags: swap
- name: shutdown | 注释/etc/fstab/swap 那一行
replace: dest=/etc/fstab regexp='(.*) swap(s ) swap' replace='f swap2swap'
when: swap.stdout == "0"
ignore errors: yes
tags: swap