-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mount] Ability to temporarily mount a filesystem without altering /etc/fstab #84
Comments
An additional use case discussed in the issues and PRs opened previously (2571, 19820, 48134) over the last 5 years, and one I am currently facing, is the need to temporarily mount a filesystem that is already configured in fstab. Currently the mounted state requires that 'src' be provided, which is reasonable if updating fstab is required, but should be optional if a valid entry already exists in fstab. For example, if I need to add filesystems to a server and migrate existing content without changing the directory layout, I might have a playbook that creates the filesystems and mountpoints in their final desired state but does not actually mount them yet. Then I might have a playbook to mount them in a temporary location, migrate existing content to the new filesystems, and then unmount the temporaries and remount them in their new, permanent location. |
See #107. |
It would probably be clearer to separate configuration and running state, and split them into two module parameters, the same way it is done for Mounts could be managed the same way, with (at least one of these params required): state: mounted/unmounted/remounted
enabled: yes/no # configured in fstab, or not For me, the current choices for the So I agree that the module needs some boolean param to deal with fstab, but I think |
Don't really see why the previous issue was closed, looked like there was good discussion there. The ansible core team's argument that it means the "mount" module has too many options doesn't seem like a very convincing argument given modules like |
A part of the trouble with the
But when doing the same from This makes clear for me that there are two things to control separately: the current mount state, without worrying about fstab contents (as does On the other hand, moving to split an option into two options by keeping its name in the new set may be confusing too, and needs probably more work (deprecation step, etc). Anyway, it seems to be a better target. That would migrate this way:
other ideas ? |
I'd be fine with quidame's suggestion if it is the easiest non-breaking solution. For consistency with service/systemd, however, I would personally prefer to have the end goal of:
Something like this:
I admit I have not looked at the code and do not know if my suggestions would be onerous to implement. However, this would also cover my additional use case of ensuring that a previously configured mountpoint is actually mounted, without needing to know all of its details (i.e. If adding the additional |
Because Dev team couldn't update this feature, I use another workaround - name: "Mount ISO CentOS"
mount:
path: /mnt
src: "/tmp/centos.iso"
fstype: iso9660
opts: loop
state: mounted
fstab: /tmp/tmp.fstab - name: "Mount ISO CentOS"
mount:
path: /mnt
src: "/tmp/centos.iso"
fstype: iso9660
opts: loop
state: unmounted
fstab: /tmp/tmp.fstab Use a fake/temp fstab file. |
Hah, that's neat. So once done with the mount, is it ok to simply unmount and delete |
Yes :) |
If anyone needs another workaround for simply mounting a device: - name: Create mountpoint for new root partition
file:
path: /newroot
state: directory
- name: Mount new root partition
shell: |
(lsblk | grep /newroot) || mount /dev/mapper/cryptroot /newroot |
@saito-hideki Is there any ETA for #267 being merged? It looks like it has been approved in June of this year. |
Hello @MrSuicideParrot , |
Add ephemeral state to mount fs without altering fstab SUMMARY Add ephemeral possible value for state parameter. The ephemeral state allows end-users to mount a volume on a given path, without altering an fstab file or creating a dummy one. There have been debates about splitting this module into an fstab module and a mount module, but nothing has been done in 5 years. This is why I'd like to propose this feature. Downside: the way the posix.mount module handles mount options prevents it to be able to check exactly if the given opts perfectly match the mount options of an already mounted volume. To achieve this, the module would have to be aware of every mount default options, for all platforms. This is why state=ephemeral always return changed=yes. In other terms, a remount will always be triggered if the volume is already mounted, even if the options look to be the same. Using state=unmounted on a volume previously mounted with ephemeral behaves correctly. ISSUE TYPE Feature Pull Request Related issues: ansible/ansible#48134 #84 COMPONENT NAME mount ADDITIONAL INFORMATION Example use case Sometimes it is handy to be able to temporarily mount a volume. I've seen this in couple companies where Ansible is used to generate reports and put it on network shares. However, some admins don't look into mount options such as krb5 and multiuser for SMB shares. Being forced to use fstab-based mounts leads to clear text passwords being stored more or less temporarily on the host filesystem, requiring "manual" deletion (with the hassle of using blocks, rescues, always, etc.). This feature respond to this use case by providing a way to mount a volume without having to alter an fstab file. Description of changes Edit DOCUMENTATION section to add ephemeral state Edit EXAMPLES section to add ephemeral state example Add new function _set_ephemeral_args to use instead of _set_fstab_args when using ephemeral state Add new function _is_same_mount_src to determine if the mounted volume on the destination path has the same source than the one supplied to the module Add new function _get_mount_info to avoid redundant code between functions get_linux_mounts and _is_same_mount_src Modify get_linux_mount to use the new function _get_mount_info. Original behavior is preserved. Integrate ephemeral parameter treatment into mounted treatment, and add if statements to avoid IO from/to fstab Add ephemeral as a possible value for the state parameter in main() Add required_if dependencies for ephemeral state Reviewed-by: None <None> Reviewed-by: Hideki Saito <[email protected]> Reviewed-by: Abhijeet Kasurde <None>
TLDR; this is now fixed as |
SUMMARY
Migration of ansible/ansible#48134:
Ability to perform temporary mounts without altering
/etc/fstab
. Currently anything done with the mount module needs to manipulate/etc/fstab
.Additional parameter is needed to perform temporary mounts, such as with an ISO image that would be unmounted later in a play. Currently this can't be done with the mount module, as altering the
/etc/fstab
is required. Maybe call this additional parametermodify_fstab
of typebool
. Currently the only way to achieve this is via thecommand
module using direct mount/unmount commands.ISSUE TYPE
COMPONENT NAME
mount, fstab
ADDITIONAL INFORMATION
To mount an ISO image temporarily for pulling in data, but not make an entry in
/etc/fstab
.The text was updated successfully, but these errors were encountered: