mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
try remount but fallback to unmount + mount (#2445)
* allow mount to try remount falls back to unmount/mount * fixed fstab handling and switched to ismount custom function deals with bind mounts unlike built in * un ** args * last ** args
This commit is contained in:
parent
c77f7af765
commit
1d8be78963
1 changed files with 36 additions and 8 deletions
|
@ -308,6 +308,15 @@ def unset_mount(module, args):
|
|||
|
||||
return (args['name'], changed)
|
||||
|
||||
def _set_fstab_args(args):
|
||||
result = []
|
||||
if 'fstab' in args and args['fstab'] != '/etc/fstab':
|
||||
if get_platform().lower().endswith('bsd'):
|
||||
result.append('-F')
|
||||
else:
|
||||
result.append('-T')
|
||||
result.append(args['fstab'])
|
||||
return result
|
||||
|
||||
def mount(module, args):
|
||||
"""Mount up a path or remount if needed."""
|
||||
|
@ -317,13 +326,9 @@ def mount(module, args):
|
|||
cmd = [mount_bin]
|
||||
|
||||
if ismount(name):
|
||||
cmd += ['-o', 'remount']
|
||||
return remount(module, mount_bin, args)
|
||||
|
||||
if args['fstab'] != '/etc/fstab':
|
||||
if get_platform() == 'FreeBSD':
|
||||
cmd += ['-F', args['fstab']]
|
||||
elif get_platform() == 'Linux':
|
||||
cmd += ['-T', args['fstab']]
|
||||
cmd += _set_fstab_args(args)
|
||||
|
||||
cmd += [name]
|
||||
|
||||
|
@ -348,6 +353,30 @@ def umount(module, dest):
|
|||
else:
|
||||
return rc, out+err
|
||||
|
||||
def remount(module, mount_bin, args):
|
||||
''' will try to use -o remount first and fallback to unmount/mount if unsupported'''
|
||||
msg = ''
|
||||
cmd = [mount_bin]
|
||||
|
||||
# multiplatform remount opts
|
||||
if get_platform().lower().endswith('bsd'):
|
||||
cmd += ['-u']
|
||||
else:
|
||||
cmd += ['-o', 'remount' ]
|
||||
|
||||
cmd += _set_fstab_args(args)
|
||||
cmd += [ args['name'], ]
|
||||
try:
|
||||
rc, out, err = module.run_command(cmd)
|
||||
except:
|
||||
rc = 1
|
||||
if rc != 0:
|
||||
msg = out+err
|
||||
if ismount(args['name']):
|
||||
rc,msg = umount(module, args)
|
||||
if rc == 0:
|
||||
rc,msg = mount(module, args)
|
||||
return rc, msg
|
||||
|
||||
# Note if we wanted to put this into module_utils we'd have to get permission
|
||||
# from @jupeter -- https://github.com/ansible/ansible-modules-core/pull/2923
|
||||
|
@ -650,8 +679,7 @@ def main():
|
|||
elif 'bind' in args.get('opts', []):
|
||||
changed = True
|
||||
|
||||
if is_bind_mounted(
|
||||
module, linux_mounts, name, args['src'], args['fstype']):
|
||||
if is_bind_mounted( module, linux_mounts, name, args['src'], args['fstype']):
|
||||
changed = False
|
||||
|
||||
if changed and not module.check_mode:
|
||||
|
|
Loading…
Reference in a new issue