将挂载存储在变量中并注释或禁用交换挂载

问题描述

新手提醒!!

这个想法是在 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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...