2012-07-15 20:38:40 +02:00
|
|
|
#!/usr/bin/python
|
2012-08-03 03:29:10 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-07-15 20:38:40 +02:00
|
|
|
|
|
|
|
# (c) 2012, Red Hat, inc
|
|
|
|
# Written by Seth Vidal
|
|
|
|
# based on the mount modules from salt and puppet
|
|
|
|
#
|
|
|
|
# This file is part of Ansible
|
|
|
|
#
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2012-09-30 12:21:35 +02:00
|
|
|
DOCUMENTATION = '''
|
|
|
|
---
|
|
|
|
module: mount
|
|
|
|
short_description: Control active and configured mount points
|
|
|
|
description:
|
|
|
|
- This module controls active and configured mount points in C(/etc/fstab).
|
|
|
|
version_added: "0.6"
|
|
|
|
options:
|
|
|
|
name:
|
|
|
|
description:
|
|
|
|
- "path to the mount point, eg: C(/mnt/files)"
|
|
|
|
required: true
|
|
|
|
src:
|
|
|
|
description:
|
|
|
|
- device to be mounted on I(name).
|
|
|
|
required: true
|
|
|
|
fstype:
|
|
|
|
description:
|
|
|
|
- file-system type
|
|
|
|
required: true
|
|
|
|
opts:
|
|
|
|
description:
|
2016-03-09 16:05:41 +01:00
|
|
|
- mount options (see fstab(5))
|
2012-09-30 12:21:35 +02:00
|
|
|
required: false
|
|
|
|
default: null
|
|
|
|
dump:
|
|
|
|
description:
|
2016-03-09 16:05:41 +01:00
|
|
|
- "dump (see fstab(5)), Note that if nulled, C(state=present) will cease to work and duplicate entries will be made with subsequent runs."
|
2012-09-30 12:21:35 +02:00
|
|
|
required: false
|
2015-03-12 02:36:44 +01:00
|
|
|
default: 0
|
2012-09-30 12:21:35 +02:00
|
|
|
passno:
|
|
|
|
description:
|
2016-03-09 16:05:41 +01:00
|
|
|
- "passno (see fstab(5)), Note that if nulled, C(state=present) will cease to work and duplicate entries will be made with subsequent runs."
|
2012-09-30 12:21:35 +02:00
|
|
|
required: false
|
2015-03-12 02:36:44 +01:00
|
|
|
default: 0
|
2012-09-30 12:21:35 +02:00
|
|
|
state:
|
|
|
|
description:
|
2016-03-09 16:05:41 +01:00
|
|
|
- If C(mounted) or C(unmounted), the device will be actively mounted or unmounted as needed and appropriately configured in I(fstab).
|
|
|
|
- C(absent) and C(present) only deal with I(fstab) but will not affect current mounting.
|
|
|
|
- If specifying C(mounted) and the mount point is not present, the mount point will be created. Similarly.
|
|
|
|
- Specifying C(absent) will remove the mount point directory.
|
2012-09-30 12:21:35 +02:00
|
|
|
required: true
|
|
|
|
choices: [ "present", "absent", "mounted", "unmounted" ]
|
2014-07-21 18:30:59 +02:00
|
|
|
fstab:
|
|
|
|
description:
|
|
|
|
- file to use instead of C(/etc/fstab). You shouldn't use that option
|
|
|
|
unless you really know what you are doing. This might be useful if
|
|
|
|
you need to configure mountpoints in a chroot environment.
|
|
|
|
required: false
|
|
|
|
default: /etc/fstab
|
|
|
|
|
2016-03-09 16:05:41 +01:00
|
|
|
author:
|
2015-06-15 21:53:30 +02:00
|
|
|
- Ansible Core Team
|
|
|
|
- Seth Vidal
|
2012-09-30 12:21:35 +02:00
|
|
|
'''
|
2013-06-14 11:53:43 +02:00
|
|
|
EXAMPLES = '''
|
|
|
|
# Mount DVD read-only
|
|
|
|
- mount: name=/mnt/dvd src=/dev/sr0 fstype=iso9660 opts=ro state=present
|
|
|
|
|
|
|
|
# Mount up device by label
|
2014-07-24 08:46:49 +02:00
|
|
|
- mount: name=/srv/disk src='LABEL=SOME_LABEL' fstype=ext4 state=present
|
2013-06-14 11:53:43 +02:00
|
|
|
|
|
|
|
# Mount up device by UUID
|
2014-07-24 08:46:49 +02:00
|
|
|
- mount: name=/home src='UUID=b3e48f45-f933-4c8e-a700-22a159ec9077' fstype=xfs opts=noatime state=present
|
2013-06-14 11:53:43 +02:00
|
|
|
'''
|
2012-09-30 12:21:35 +02:00
|
|
|
|
2012-07-15 20:38:40 +02:00
|
|
|
|
|
|
|
def write_fstab(lines, dest):
|
|
|
|
|
|
|
|
fs_w = open(dest, 'w')
|
|
|
|
for l in lines:
|
|
|
|
fs_w.write(l)
|
|
|
|
|
|
|
|
fs_w.flush()
|
|
|
|
fs_w.close()
|
|
|
|
|
2015-06-02 15:14:07 +02:00
|
|
|
def _escape_fstab(v):
|
|
|
|
""" escape space (040), ampersand (046) and backslash (134) which are invalid in fstab fields """
|
|
|
|
return v.replace('\\', '\\134').replace(' ', '\\040').replace('&', '\\046')
|
|
|
|
|
2014-10-17 18:23:25 +02:00
|
|
|
def set_mount(module, **kwargs):
|
2012-07-31 03:50:32 +02:00
|
|
|
""" set/change a mount point location in fstab """
|
|
|
|
|
2012-07-15 20:38:40 +02:00
|
|
|
# kwargs: name, src, fstype, opts, dump, passno, state, fstab=/etc/fstab
|
2012-07-31 03:50:32 +02:00
|
|
|
args = dict(
|
|
|
|
opts = 'defaults',
|
|
|
|
dump = '0',
|
|
|
|
passno = '0',
|
|
|
|
fstab = '/etc/fstab'
|
|
|
|
)
|
2012-07-15 20:38:40 +02:00
|
|
|
args.update(kwargs)
|
|
|
|
|
2014-12-28 02:08:25 +01:00
|
|
|
# save the mount name before space replacement
|
|
|
|
origname = args['name']
|
|
|
|
# replace any space in mount name with '\040' to make it fstab compatible (man fstab)
|
|
|
|
args['name'] = args['name'].replace(' ', r'\040')
|
|
|
|
|
2012-08-07 02:07:02 +02:00
|
|
|
new_line = '%(src)s %(name)s %(fstype)s %(opts)s %(dump)s %(passno)s\n'
|
2012-07-15 20:38:40 +02:00
|
|
|
|
|
|
|
to_write = []
|
|
|
|
exists = False
|
|
|
|
changed = False
|
2015-06-02 15:14:07 +02:00
|
|
|
escaped_args = dict([(k, _escape_fstab(v)) for k, v in args.iteritems()])
|
2012-07-15 20:38:40 +02:00
|
|
|
for line in open(args['fstab'], 'r').readlines():
|
|
|
|
if not line.strip():
|
2012-08-11 18:35:58 +02:00
|
|
|
to_write.append(line)
|
|
|
|
continue
|
2012-07-15 20:38:40 +02:00
|
|
|
if line.strip().startswith('#'):
|
|
|
|
to_write.append(line)
|
|
|
|
continue
|
|
|
|
if len(line.split()) != 6:
|
|
|
|
# not sure what this is or why it is here
|
|
|
|
# but it is not our fault so leave it be
|
|
|
|
to_write.append(line)
|
|
|
|
continue
|
2012-08-07 02:07:02 +02:00
|
|
|
|
2012-07-15 20:38:40 +02:00
|
|
|
ld = {}
|
|
|
|
ld['src'], ld['name'], ld['fstype'], ld['opts'], ld['dump'], ld['passno'] = line.split()
|
|
|
|
|
2015-06-02 15:14:07 +02:00
|
|
|
if ld['name'] != escaped_args['name']:
|
2012-07-15 20:38:40 +02:00
|
|
|
to_write.append(line)
|
|
|
|
continue
|
|
|
|
|
|
|
|
# it exists - now see if what we have is different
|
|
|
|
exists = True
|
|
|
|
for t in ('src', 'fstype','opts', 'dump', 'passno'):
|
2015-06-02 15:14:07 +02:00
|
|
|
if ld[t] != escaped_args[t]:
|
2012-07-15 20:38:40 +02:00
|
|
|
changed = True
|
2015-06-02 15:14:07 +02:00
|
|
|
ld[t] = escaped_args[t]
|
2012-07-15 20:38:40 +02:00
|
|
|
|
|
|
|
if changed:
|
2012-08-11 18:35:58 +02:00
|
|
|
to_write.append(new_line % ld)
|
2012-07-15 20:38:40 +02:00
|
|
|
else:
|
2012-08-11 18:35:58 +02:00
|
|
|
to_write.append(line)
|
2012-08-07 02:07:02 +02:00
|
|
|
|
2012-07-15 20:38:40 +02:00
|
|
|
if not exists:
|
|
|
|
to_write.append(new_line % args)
|
|
|
|
changed = True
|
2012-08-07 02:07:02 +02:00
|
|
|
|
2014-10-17 18:23:25 +02:00
|
|
|
if changed and not module.check_mode:
|
2012-07-15 20:38:40 +02:00
|
|
|
write_fstab(to_write, args['fstab'])
|
|
|
|
|
2014-12-28 02:08:25 +01:00
|
|
|
# mount function needs origname
|
|
|
|
return (origname, changed)
|
2012-08-07 02:07:02 +02:00
|
|
|
|
2012-07-15 20:38:40 +02:00
|
|
|
|
2014-10-17 18:23:25 +02:00
|
|
|
def unset_mount(module, **kwargs):
|
2012-07-31 03:50:32 +02:00
|
|
|
""" remove a mount point from fstab """
|
|
|
|
|
2012-07-15 20:38:40 +02:00
|
|
|
# kwargs: name, src, fstype, opts, dump, passno, state, fstab=/etc/fstab
|
2012-07-31 03:50:32 +02:00
|
|
|
args = dict(
|
|
|
|
opts = 'default',
|
|
|
|
dump = '0',
|
|
|
|
passno = '0',
|
|
|
|
fstab = '/etc/fstab'
|
|
|
|
)
|
2012-07-15 20:38:40 +02:00
|
|
|
args.update(kwargs)
|
|
|
|
|
2014-12-28 02:08:25 +01:00
|
|
|
# save the mount name before space replacement
|
|
|
|
origname = args['name']
|
|
|
|
# replace any space in mount name with '\040' to make it fstab compatible (man fstab)
|
|
|
|
args['name'] = args['name'].replace(' ', r'\040')
|
|
|
|
|
2012-07-15 20:38:40 +02:00
|
|
|
to_write = []
|
|
|
|
changed = False
|
2015-06-02 15:14:07 +02:00
|
|
|
escaped_name = _escape_fstab(args['name'])
|
2012-07-15 20:38:40 +02:00
|
|
|
for line in open(args['fstab'], 'r').readlines():
|
|
|
|
if not line.strip():
|
2012-08-11 18:35:58 +02:00
|
|
|
to_write.append(line)
|
|
|
|
continue
|
2012-07-15 20:38:40 +02:00
|
|
|
if line.strip().startswith('#'):
|
|
|
|
to_write.append(line)
|
|
|
|
continue
|
|
|
|
if len(line.split()) != 6:
|
|
|
|
# not sure what this is or why it is here
|
|
|
|
# but it is not our fault so leave it be
|
|
|
|
to_write.append(line)
|
|
|
|
continue
|
2012-08-07 02:07:02 +02:00
|
|
|
|
2012-07-15 20:38:40 +02:00
|
|
|
ld = {}
|
|
|
|
ld['src'], ld['name'], ld['fstype'], ld['opts'], ld['dump'], ld['passno'] = line.split()
|
|
|
|
|
2015-06-02 15:14:07 +02:00
|
|
|
if ld['name'] != escaped_name:
|
2012-07-15 20:38:40 +02:00
|
|
|
to_write.append(line)
|
|
|
|
continue
|
|
|
|
|
|
|
|
# if we got here we found a match - continue and mark changed
|
|
|
|
changed = True
|
|
|
|
|
2014-10-17 18:23:25 +02:00
|
|
|
if changed and not module.check_mode:
|
2012-07-15 20:38:40 +02:00
|
|
|
write_fstab(to_write, args['fstab'])
|
|
|
|
|
2014-12-28 02:08:25 +01:00
|
|
|
# umount needs origname
|
|
|
|
return (origname, changed)
|
2012-07-15 20:38:40 +02:00
|
|
|
|
2012-08-07 02:07:02 +02:00
|
|
|
|
Update modules to use run_command in module_common.py
This updates apt, apt_repository, command, cron, easy_install, facter,
fireball, git, group, mount, ohai, pip, service, setup, subversion,
supervisorctl, svr4pkg, user, and yum to take advantage of run_command
in module_common.py.
2013-01-12 07:10:21 +01:00
|
|
|
def mount(module, **kwargs):
|
2012-07-31 03:50:32 +02:00
|
|
|
""" mount up a path or remount if needed """
|
2015-05-08 11:22:37 +02:00
|
|
|
|
|
|
|
# kwargs: name, src, fstype, opts, dump, passno, state, fstab=/etc/fstab
|
|
|
|
args = dict(
|
|
|
|
opts = 'default',
|
|
|
|
dump = '0',
|
|
|
|
passno = '0',
|
|
|
|
fstab = '/etc/fstab'
|
|
|
|
)
|
|
|
|
args.update(kwargs)
|
|
|
|
|
2013-06-17 23:01:35 +02:00
|
|
|
mount_bin = module.get_bin_path('mount')
|
2012-07-31 03:50:32 +02:00
|
|
|
|
2012-07-15 20:38:40 +02:00
|
|
|
name = kwargs['name']
|
2016-04-12 17:48:42 +02:00
|
|
|
|
2015-05-08 11:22:37 +02:00
|
|
|
cmd = [ mount_bin, ]
|
2016-04-12 17:48:42 +02:00
|
|
|
|
|
|
|
if ismount(name):
|
2015-05-08 11:22:37 +02:00
|
|
|
cmd += [ '-o', 'remount', ]
|
|
|
|
|
|
|
|
if get_platform().lower() == 'freebsd':
|
|
|
|
cmd += [ '-F', args['fstab'], ]
|
|
|
|
|
|
|
|
cmd += [ name, ]
|
2012-07-15 20:38:40 +02:00
|
|
|
|
Update modules to use run_command in module_common.py
This updates apt, apt_repository, command, cron, easy_install, facter,
fireball, git, group, mount, ohai, pip, service, setup, subversion,
supervisorctl, svr4pkg, user, and yum to take advantage of run_command
in module_common.py.
2013-01-12 07:10:21 +01:00
|
|
|
rc, out, err = module.run_command(cmd)
|
|
|
|
if rc == 0:
|
2012-07-15 20:38:40 +02:00
|
|
|
return 0, ''
|
|
|
|
else:
|
Update modules to use run_command in module_common.py
This updates apt, apt_repository, command, cron, easy_install, facter,
fireball, git, group, mount, ohai, pip, service, setup, subversion,
supervisorctl, svr4pkg, user, and yum to take advantage of run_command
in module_common.py.
2013-01-12 07:10:21 +01:00
|
|
|
return rc, out+err
|
2012-07-15 20:38:40 +02:00
|
|
|
|
Update modules to use run_command in module_common.py
This updates apt, apt_repository, command, cron, easy_install, facter,
fireball, git, group, mount, ohai, pip, service, setup, subversion,
supervisorctl, svr4pkg, user, and yum to take advantage of run_command
in module_common.py.
2013-01-12 07:10:21 +01:00
|
|
|
def umount(module, **kwargs):
|
2012-07-31 03:50:32 +02:00
|
|
|
""" unmount a path """
|
|
|
|
|
2013-06-17 23:01:35 +02:00
|
|
|
umount_bin = module.get_bin_path('umount')
|
2012-07-24 13:30:08 +02:00
|
|
|
name = kwargs['name']
|
2013-06-17 23:01:35 +02:00
|
|
|
cmd = [umount_bin, name]
|
2012-07-15 20:38:40 +02:00
|
|
|
|
Update modules to use run_command in module_common.py
This updates apt, apt_repository, command, cron, easy_install, facter,
fireball, git, group, mount, ohai, pip, service, setup, subversion,
supervisorctl, svr4pkg, user, and yum to take advantage of run_command
in module_common.py.
2013-01-12 07:10:21 +01:00
|
|
|
rc, out, err = module.run_command(cmd)
|
|
|
|
if rc == 0:
|
2012-07-15 20:38:40 +02:00
|
|
|
return 0, ''
|
|
|
|
else:
|
Update modules to use run_command in module_common.py
This updates apt, apt_repository, command, cron, easy_install, facter,
fireball, git, group, mount, ohai, pip, service, setup, subversion,
supervisorctl, svr4pkg, user, and yum to take advantage of run_command
in module_common.py.
2013-01-12 07:10:21 +01:00
|
|
|
return rc, out+err
|
2012-07-24 13:30:08 +02:00
|
|
|
|
|
|
|
def main():
|
2012-07-31 03:50:32 +02:00
|
|
|
|
2012-07-24 13:30:08 +02:00
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec = dict(
|
|
|
|
state = dict(required=True, choices=['present', 'absent', 'mounted', 'unmounted']),
|
|
|
|
name = dict(required=True),
|
|
|
|
opts = dict(default=None),
|
|
|
|
passno = dict(default=None),
|
|
|
|
dump = dict(default=None),
|
|
|
|
src = dict(required=True),
|
|
|
|
fstype = dict(required=True),
|
2014-07-24 03:14:46 +02:00
|
|
|
fstab = dict(default='/etc/fstab')
|
2014-10-17 18:23:25 +02:00
|
|
|
),
|
|
|
|
supports_check_mode=True
|
2012-07-24 13:30:08 +02:00
|
|
|
)
|
2012-08-07 02:07:02 +02:00
|
|
|
|
2013-06-01 17:33:17 +02:00
|
|
|
|
2012-07-24 13:30:08 +02:00
|
|
|
changed = False
|
|
|
|
rc = 0
|
|
|
|
args = {
|
|
|
|
'name': module.params['name'],
|
|
|
|
'src': module.params['src'],
|
|
|
|
'fstype': module.params['fstype']
|
|
|
|
}
|
|
|
|
if module.params['passno'] is not None:
|
|
|
|
args['passno'] = module.params['passno']
|
|
|
|
if module.params['opts'] is not None:
|
|
|
|
args['opts'] = module.params['opts']
|
|
|
|
if module.params['dump'] is not None:
|
|
|
|
args['dump'] = module.params['dump']
|
|
|
|
if module.params['fstab'] is not None:
|
|
|
|
args['fstab'] = module.params['fstab']
|
2012-08-07 02:07:02 +02:00
|
|
|
|
2014-07-21 18:32:02 +02:00
|
|
|
# if fstab file does not exist, we first need to create it. This mainly
|
|
|
|
# happens when fstab optin is passed to the module.
|
|
|
|
if not os.path.exists(args['fstab']):
|
|
|
|
if not os.path.exists(os.path.dirname(args['fstab'])):
|
|
|
|
os.makedirs(os.path.dirname(args['fstab']))
|
|
|
|
open(args['fstab'],'a').close()
|
|
|
|
|
2012-07-24 13:30:08 +02:00
|
|
|
# absent == remove from fstab and unmounted
|
|
|
|
# unmounted == do not change fstab state, but unmount
|
|
|
|
# present == add to fstab, do not change mount state
|
|
|
|
# mounted == add to fstab if not there and make sure it is mounted, if it has changed in fstab then remount it
|
2012-08-07 02:07:02 +02:00
|
|
|
|
2012-07-24 13:30:08 +02:00
|
|
|
state = module.params['state']
|
|
|
|
name = module.params['name']
|
|
|
|
if state == 'absent':
|
2014-10-17 18:23:25 +02:00
|
|
|
name, changed = unset_mount(module, **args)
|
|
|
|
if changed and not module.check_mode:
|
2016-04-12 17:48:42 +02:00
|
|
|
if ismount(name):
|
Update modules to use run_command in module_common.py
This updates apt, apt_repository, command, cron, easy_install, facter,
fireball, git, group, mount, ohai, pip, service, setup, subversion,
supervisorctl, svr4pkg, user, and yum to take advantage of run_command
in module_common.py.
2013-01-12 07:10:21 +01:00
|
|
|
res,msg = umount(module, **args)
|
2012-07-24 13:30:08 +02:00
|
|
|
if res:
|
2012-08-13 21:20:36 +02:00
|
|
|
module.fail_json(msg="Error unmounting %s: %s" % (name, msg))
|
2012-08-07 02:07:02 +02:00
|
|
|
|
2012-07-24 13:30:08 +02:00
|
|
|
if os.path.exists(name):
|
|
|
|
try:
|
|
|
|
os.rmdir(name)
|
|
|
|
except (OSError, IOError), e:
|
2012-08-13 21:20:36 +02:00
|
|
|
module.fail_json(msg="Error rmdir %s: %s" % (name, str(e)))
|
2012-08-07 02:07:02 +02:00
|
|
|
|
2012-07-24 13:30:08 +02:00
|
|
|
module.exit_json(changed=changed, **args)
|
2012-08-07 02:07:02 +02:00
|
|
|
|
2012-07-24 13:30:08 +02:00
|
|
|
if state == 'unmounted':
|
2016-04-12 17:48:42 +02:00
|
|
|
if ismount(name):
|
2014-10-17 18:23:25 +02:00
|
|
|
if not module.check_mode:
|
|
|
|
res,msg = umount(module, **args)
|
|
|
|
if res:
|
|
|
|
module.fail_json(msg="Error unmounting %s: %s" % (name, msg))
|
2012-07-24 13:30:08 +02:00
|
|
|
changed = True
|
2012-08-07 02:07:02 +02:00
|
|
|
|
2012-07-24 13:30:08 +02:00
|
|
|
module.exit_json(changed=changed, **args)
|
2012-08-07 02:07:02 +02:00
|
|
|
|
2012-07-24 13:30:08 +02:00
|
|
|
if state in ['mounted', 'present']:
|
|
|
|
if state == 'mounted':
|
2014-10-17 18:23:25 +02:00
|
|
|
if not os.path.exists(name) and not module.check_mode:
|
2012-07-24 13:30:08 +02:00
|
|
|
try:
|
|
|
|
os.makedirs(name)
|
|
|
|
except (OSError, IOError), e:
|
2012-08-13 21:20:36 +02:00
|
|
|
module.fail_json(msg="Error making dir %s: %s" % (name, str(e)))
|
2012-08-07 02:07:02 +02:00
|
|
|
|
2014-10-17 18:23:25 +02:00
|
|
|
name, changed = set_mount(module, **args)
|
2014-07-17 14:49:40 +02:00
|
|
|
if state == 'mounted':
|
2012-07-24 13:30:08 +02:00
|
|
|
res = 0
|
2016-04-12 17:48:42 +02:00
|
|
|
if ismount(name):
|
2014-10-17 18:23:25 +02:00
|
|
|
if changed and not module.check_mode:
|
Update modules to use run_command in module_common.py
This updates apt, apt_repository, command, cron, easy_install, facter,
fireball, git, group, mount, ohai, pip, service, setup, subversion,
supervisorctl, svr4pkg, user, and yum to take advantage of run_command
in module_common.py.
2013-01-12 07:10:21 +01:00
|
|
|
res,msg = mount(module, **args)
|
2015-02-18 21:22:24 +01:00
|
|
|
elif 'bind' in args.get('opts', []):
|
2014-09-30 02:09:32 +02:00
|
|
|
changed = True
|
|
|
|
cmd = 'mount -l'
|
|
|
|
rc, out, err = module.run_command(cmd)
|
|
|
|
allmounts = out.split('\n')
|
|
|
|
for mounts in allmounts[:-1]:
|
|
|
|
arguments = mounts.split()
|
|
|
|
if arguments[0] == args['src'] and arguments[2] == args['name'] and arguments[4] == args['fstype']:
|
|
|
|
changed = False
|
|
|
|
if changed:
|
|
|
|
res,msg = mount(module, **args)
|
2012-07-24 13:30:08 +02:00
|
|
|
else:
|
|
|
|
changed = True
|
2014-10-17 18:23:25 +02:00
|
|
|
if not module.check_mode:
|
|
|
|
res,msg = mount(module, **args)
|
|
|
|
|
2012-08-07 02:07:02 +02:00
|
|
|
|
2012-07-24 13:30:08 +02:00
|
|
|
if res:
|
2012-08-13 21:20:36 +02:00
|
|
|
module.fail_json(msg="Error mounting %s: %s" % (name, msg))
|
2012-08-07 02:07:02 +02:00
|
|
|
|
|
|
|
|
2012-07-24 13:30:08 +02:00
|
|
|
module.exit_json(changed=changed, **args)
|
2012-08-07 02:07:02 +02:00
|
|
|
|
2012-07-24 13:30:08 +02:00
|
|
|
module.fail_json(msg='Unexpected position reached')
|
2012-08-07 02:07:02 +02:00
|
|
|
|
2013-12-02 21:13:49 +01:00
|
|
|
# import module snippets
|
2013-12-02 21:11:23 +01:00
|
|
|
from ansible.module_utils.basic import *
|
2016-04-12 17:48:42 +02:00
|
|
|
from ansible.module_utils.ismount import *
|
|
|
|
|
2012-07-24 13:30:08 +02:00
|
|
|
main()
|