Hi all!
I just spent a few hours trying to get mount to work like I wanted it to. I am not mounting anything special, I just want to add the “acl” option to whatever disk is mounted at “/”. This means that I do not know what the source is.
I got some help in ansible on how to get the source. With a little help, I expanded that to being able to extract pass, dump, and options as well. It turns out I need all of these otherwise the mount module will use the defaults.
For example, if I want to set passno to 1 and dump was previously set to 2 it will be reset dump to the default value of 0. This is not very ideal.
My full final solution was:
-
shell: “grep ’ / ’ /etc/mtab | awk ‘{print $1}’”
register: root_device -
shell: “grep ’ / ’ /etc/mtab | awk ‘{print $3}’”
register: root_fstype -
shell: “OPTS=$(grep ’ / ’ /etc/mtab | awk ‘{print $4}’); if ! $( echo "$OPTS" | tr ‘,’ "\n" | grep -qx ‘acl’ ); then OPTS=$OPTS,acl; fi; echo $OPTS”
register: root_options -
shell: “grep ’ / ’ /etc/mtab | awk ‘{print $5}’”
register: root_dump -
shell: “grep ’ / ’ /etc/mtab | awk ‘{print $6}’”
register: root_pass -
mount: name=/ src={{ root_device.stdout }} fstype={{ root_fstype.stdout }} state=mounted opts={{ root_options.stdout }} dump={{ root_dump.stdout }} passno={{ root_pass.stdout }}
This works well but I end up getting a bunch of change/update requests every time since the shell tasks always have to run even if nothing actually changes.
Here are my questions:
-
Could mount be updated to read in existing values and populate defaults based on those rather than the current hardcoded defaults?
-
Could mount be smart enough to accept either a name or a source and guess the rest based on that? Ideally I want to just update the information for whatever is mounted at “/” since I might not know what the source was if I have several machines.
-
Is there an easier way to do what I’m doing without making any other changes? Seems like this is something that should be doable already so maybe I’m just missing something.
-
If I wanted to try and implement this, would it be better to try and implement it as another module? I’m thinking maybe “mount_option: name=/ state=present value=acl” to add an option or “mount_option: source=/dev/sdb2 state=missing value=rw” to remove an option.
Thanks!