|
|
|
|
@ -149,8 +149,9 @@ EXAMPLES = r'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import platform
|
|
|
|
|
|
|
|
|
|
from ansible.module_utils.basic import AnsibleModule, get_platform
|
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
|
from ansible.module_utils.ismount import ismount
|
|
|
|
|
from ansible.module_utils.six import iteritems
|
|
|
|
|
from ansible.module_utils._text import to_native
|
|
|
|
|
@ -196,7 +197,7 @@ def set_mount(module, args):
|
|
|
|
|
escaped_args = dict([(k, _escape_fstab(v)) for k, v in iteritems(args)])
|
|
|
|
|
new_line = '%(src)s %(name)s %(fstype)s %(opts)s %(dump)s %(passno)s\n'
|
|
|
|
|
|
|
|
|
|
if get_platform() == 'SunOS':
|
|
|
|
|
if platform.system() == 'SunOS':
|
|
|
|
|
new_line = (
|
|
|
|
|
'%(src)s - %(name)s %(fstype)s %(passno)s %(boot)s %(opts)s\n')
|
|
|
|
|
|
|
|
|
|
@ -216,16 +217,16 @@ def set_mount(module, args):
|
|
|
|
|
# Check if we got a valid line for splitting
|
|
|
|
|
# (on Linux the 5th and the 6th field is optional)
|
|
|
|
|
if (
|
|
|
|
|
get_platform() == 'SunOS' and len(fields) != 7 or
|
|
|
|
|
get_platform() == 'Linux' and len(fields) not in [4, 5, 6] or
|
|
|
|
|
get_platform() not in ['SunOS', 'Linux'] and len(fields) != 6):
|
|
|
|
|
platform.system() == 'SunOS' and len(fields) != 7 or
|
|
|
|
|
platform.system() == 'Linux' and len(fields) not in [4, 5, 6] or
|
|
|
|
|
platform.system() not in ['SunOS', 'Linux'] and len(fields) != 6):
|
|
|
|
|
to_write.append(line)
|
|
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
ld = {}
|
|
|
|
|
|
|
|
|
|
if get_platform() == 'SunOS':
|
|
|
|
|
if platform.system() == 'SunOS':
|
|
|
|
|
(
|
|
|
|
|
ld['src'],
|
|
|
|
|
dash,
|
|
|
|
|
@ -263,7 +264,7 @@ def set_mount(module, args):
|
|
|
|
|
exists = True
|
|
|
|
|
args_to_check = ('src', 'fstype', 'opts', 'dump', 'passno')
|
|
|
|
|
|
|
|
|
|
if get_platform() == 'SunOS':
|
|
|
|
|
if platform.system() == 'SunOS':
|
|
|
|
|
args_to_check = ('src', 'fstype', 'passno', 'boot', 'opts')
|
|
|
|
|
|
|
|
|
|
for t in args_to_check:
|
|
|
|
|
@ -306,15 +307,15 @@ def unset_mount(module, args):
|
|
|
|
|
|
|
|
|
|
# Check if we got a valid line for splitting
|
|
|
|
|
if (
|
|
|
|
|
get_platform() == 'SunOS' and len(line.split()) != 7 or
|
|
|
|
|
get_platform() != 'SunOS' and len(line.split()) != 6):
|
|
|
|
|
platform.system() == 'SunOS' and len(line.split()) != 7 or
|
|
|
|
|
platform.system() != 'SunOS' and len(line.split()) != 6):
|
|
|
|
|
to_write.append(line)
|
|
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
ld = {}
|
|
|
|
|
|
|
|
|
|
if get_platform() == 'SunOS':
|
|
|
|
|
if platform.system() == 'SunOS':
|
|
|
|
|
(
|
|
|
|
|
ld['src'],
|
|
|
|
|
dash,
|
|
|
|
|
@ -360,8 +361,8 @@ def _set_fstab_args(fstab_file):
|
|
|
|
|
if (
|
|
|
|
|
fstab_file and
|
|
|
|
|
fstab_file != '/etc/fstab' and
|
|
|
|
|
get_platform().lower() != 'sunos'):
|
|
|
|
|
if get_platform().lower().endswith('bsd'):
|
|
|
|
|
platform.system().lower() != 'sunos'):
|
|
|
|
|
if platform.system().lower().endswith('bsd'):
|
|
|
|
|
result.append('-F')
|
|
|
|
|
else:
|
|
|
|
|
result.append('-T')
|
|
|
|
|
@ -378,7 +379,7 @@ def mount(module, args):
|
|
|
|
|
name = args['name']
|
|
|
|
|
cmd = [mount_bin]
|
|
|
|
|
|
|
|
|
|
if get_platform().lower() == 'openbsd':
|
|
|
|
|
if platform.system().lower() == 'openbsd':
|
|
|
|
|
# Use module.params['fstab'] here as args['fstab'] has been set to the
|
|
|
|
|
# default value.
|
|
|
|
|
if module.params['fstab'] is not None:
|
|
|
|
|
@ -419,12 +420,12 @@ def remount(module, args):
|
|
|
|
|
cmd = [mount_bin]
|
|
|
|
|
|
|
|
|
|
# Multiplatform remount opts
|
|
|
|
|
if get_platform().lower().endswith('bsd'):
|
|
|
|
|
if platform.system().lower().endswith('bsd'):
|
|
|
|
|
cmd += ['-u']
|
|
|
|
|
else:
|
|
|
|
|
cmd += ['-o', 'remount']
|
|
|
|
|
|
|
|
|
|
if get_platform().lower() == 'openbsd':
|
|
|
|
|
if platform.system().lower() == 'openbsd':
|
|
|
|
|
# Use module.params['fstab'] here as args['fstab'] has been set to the
|
|
|
|
|
# default value.
|
|
|
|
|
if module.params['fstab'] is not None:
|
|
|
|
|
@ -439,7 +440,7 @@ def remount(module, args):
|
|
|
|
|
out = err = ''
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
if get_platform().lower().endswith('bsd'):
|
|
|
|
|
if platform.system().lower().endswith('bsd'):
|
|
|
|
|
# Note: Forcing BSDs to do umount/mount due to BSD remount not
|
|
|
|
|
# working as expected (suspect bug in the BSD mount command)
|
|
|
|
|
# Interested contributor could rework this to use mount options on
|
|
|
|
|
@ -483,7 +484,7 @@ def is_bind_mounted(module, linux_mounts, dest, src=None, fstype=None):
|
|
|
|
|
|
|
|
|
|
is_mounted = False
|
|
|
|
|
|
|
|
|
|
if get_platform() == 'Linux' and linux_mounts is not None:
|
|
|
|
|
if platform.system() == 'Linux' and linux_mounts is not None:
|
|
|
|
|
if src is None:
|
|
|
|
|
# That's for unmounted/absent
|
|
|
|
|
if dest in linux_mounts:
|
|
|
|
|
@ -615,7 +616,7 @@ def main():
|
|
|
|
|
# name, src, fstype, opts, dump, passno, state, fstab=/etc/fstab
|
|
|
|
|
# Note: Do not modify module.params['fstab'] as we need to know if the user
|
|
|
|
|
# explicitly specified it in mount() and remount()
|
|
|
|
|
if get_platform().lower() == 'sunos':
|
|
|
|
|
if platform.system().lower() == 'sunos':
|
|
|
|
|
args = dict(
|
|
|
|
|
name=module.params['path'],
|
|
|
|
|
opts='-',
|
|
|
|
|
@ -637,14 +638,14 @@ def main():
|
|
|
|
|
args['fstab'] = '/etc/fstab'
|
|
|
|
|
|
|
|
|
|
# FreeBSD doesn't have any 'default' so set 'rw' instead
|
|
|
|
|
if get_platform() == 'FreeBSD':
|
|
|
|
|
if platform.system() == 'FreeBSD':
|
|
|
|
|
args['opts'] = 'rw'
|
|
|
|
|
|
|
|
|
|
linux_mounts = []
|
|
|
|
|
|
|
|
|
|
# Cache all mounts here in order we have consistent results if we need to
|
|
|
|
|
# call is_bind_mounted() multiple times
|
|
|
|
|
if get_platform() == 'Linux':
|
|
|
|
|
if platform.system() == 'Linux':
|
|
|
|
|
linux_mounts = get_linux_mounts(module)
|
|
|
|
|
|
|
|
|
|
if linux_mounts is None:
|
|
|
|
|
|