问题描述
新手提醒!!
这个想法是在 fstab 中列出包含单词 swap 的挂载并将它们存储在一个变量中,然后禁用或注释它。 我可以使用正则表达式轻松禁用它:
- name: Force quit swap
command: swapoff {{ swap.stdout }}
- name: Disabling swap
shell: "swapoff --all"
become: true
- name: Disable swap permanently,persist reboots
replace:
path: /etc/fstab
regexp: '^([^#].*?\sswap\s+sw\s+.*)$'
replace: '# \1'
backup: yes
但我被要求改用 ansible_mount。 你能帮忙吗?
解决方法
请查看 mount 文档并使用状态 absent
。
- name: Unmount swap
mount:
name: swap
fstype: swap
state: absent