Letokteren
Letokteren

Reputation: 809

How does the mount module work in Ansible?

What does the mount module do exactly?

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 /

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?

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 /

Upvotes: 2

Views: 14483

Answers (2)

wirelessben
wirelessben

Reputation: 47

Just change "state: present" to "state: mounted" and modify the name:

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

Upvotes: 1

Vladimir Botka
Vladimir Botka

Reputation: 68024

Q: "What does the mount module do exactly?"

A: Quoting from mount. Parameter state:

  • 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 ...

Q: "Based on the documentation the mount module is rather an fstab editor. Or am I wrong?"

A: Yes. You're wrong.

Q: "Ansible in fact edited fstab as I wanted, but I'm not sure if it did a remount to "activate" the changes. Do I need to perform shell: mount -o remount /? Or does the previous step contains this command? Is it redundant or not?

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.

Upvotes: 5

Related Questions