Hi all!
I’ve been digging Ansible on the first few days I’ve been trying to play with it. I ran into some complications with mount, though. My use case is that I want to add the “acl” option to the “/” mount. If I want to try and have the mount module just add that option (or just set the options) I have a whole bunch of other values I need to know (source and fstype) and if I don’t specify some others (dump and passno) then they get set to default values.
Ideally what I’d like to see is something where I can just set the options for a given mount point without having to know anything else. Bonus points for just adding or removing specific options rather than having to set the whole lot.
I’ve finally landed on the following solution but it is less than idea. My questions are 1) is there a better way to do this that i’ve missed so far? 2) would it make sense to make mount smarter so that it can default to existing values if only a name or source are passed (basically run the logic from this playbook internally)? 3) would it make more sense to create something like “mount_option” that would be its own thing (“mount_option: name=/ value=acl state=present”, “mount_option: source=/dev/sda1 value=rw state=missing”)?
-
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 }}
An unexpected and not really desired byproduct of this is that I end up with several “changed” values in my recap because it ends up running all of these shell commands every time.