From 9b09acc549c4422a8c4e93216136b8f5379ebe47 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Fri, 18 Nov 2016 15:51:12 -0500 Subject: 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 --- system/mount.py | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/system/mount.py b/system/mount.py index ea76a0a9..0af2a5af 100644 --- a/system/mount.py +++ b/system/mount.py @@ -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: -- cgit v1.2.1