summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Coca <bcoca@users.noreply.github.com>2016-11-18 15:51:12 -0500
committerToshio Kuratomi <a.badger@gmail.com>2016-11-18 13:35:29 -0800
commit5dd78d71be187ab87edc663e0ab4104ef77cc211 (patch)
treed275cc5b0c5bd9401a7317f0f371189b59b88370
parentf01504529df668db0fe4a95231e54c9d5b872987 (diff)
downloadansible-modules-core-5dd78d71be187ab87edc663e0ab4104ef77cc211.tar.gz
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 (cherry picked from commit 9b09acc549c4422a8c4e93216136b8f5379ebe47)
-rw-r--r--system/mount.py44
1 files 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: