本文介绍了挂载模块在 Ansible 中是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mount 模块到底做了什么?

我在shell中有以下两个步骤:

I have the following two steps in shell:

vi /etc/fstab
#edit an already existing entry in the file. The path of this entry is: /

mount -o remount /

我想在多台机器上执行这些任务,因此我想使用 Ansible 来完成这项工作.但是我不确定 Ansible 会执行第二步.根据他的文档,mount 模块更像是一个 fstab 编辑器.还是我错了?

I would like to perform these tasks on numerous machines thus I would like to use Ansible for the job. However I'm not sure Ansible performs the second step. Based on he documentation the mount module is rather an fstab editor. Or am I wrong?

在测试时,我看到 Ansible 实际上按照我的意愿编辑了 fstab,但我不确定它是否执行了 remount 以激活"更改.Ansible 代码:

While testing I saw that Ansible in fact edited fstab as I wanted, but I'm not sure if it did a remount to "activate" the changes. Ansible code:

  - name: Add userquota to fstab
    mount:
      path: /
      state: present
      opts: errors=remount-ro,usrquota,grpquota
      fstype: ext4
      src: LABEL=cloudimg-rootfs

这本身就足够了,还是我还需要执行以下步骤?或者他上一步是否包含此命令?是否多余?

Is it enough in it self or do I need to perform he following step, too? Or does he previous step contains this command? Is it redundant or not?

  - name: Remount root filesystem
    shell: mount -o remount /

推荐答案

A:引用自 mount.参数状态:

A: Quoting from mount. Parameter state:

  • mounted:设备将被主动安装并在 fstab 中进行适当配置...
  • unmounted:将在不更改 fstab 的情况下卸载设备.
  • present:设备将在 fstab 中配置,不会触发或需要挂载.
  • absent:设备挂载的条目将从 fstab 中删除,并且还将卸载设备......
  • mounted: The device will be actively mounted and appropriately configured in fstab...
  • unmounted: The device will be unmounted without changing fstab.
  • present: The device is to be configured in fstab and does not trigger or require a mount.
  • absent: The device mount's entry will be removed from fstab and will also unmount the device ...

问:根据文档,挂载模块更像是一个 fstab 编辑器.还是我错了?"

答:是的.你错了.

问:Ansible 实际上按照我的意愿编辑了 fstab,但我不确定它是否重新安装以激活"更改.我是否需要执行 shell: mount -o remount/?或者上一步有没有这个命令?是不是多余的?

答:是的.这是多余的.不需要.您不必重新安装该条目.当 state:mounted 时,条目已经被挂载,并且 fstab 条目没有改变,则没有理由重新挂载该条目.如果条目尚未安装,则 state:mounted 将安装它.

A: Yes. It is redundant. No. You don't have to remount the entry. When state: mounted, the entry has already been mounted, and the fstab entry hasn't changed then there is no reason to remount the entry. If the entry hasn't been mounted yet then state: mounted will mount it.

这篇关于挂载模块在 Ansible 中是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 04:13