2016-06-10 12:43:19 +02:00
|
|
|
#!/usr/bin/python
|
2016-05-24 17:02:17 +02:00
|
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
|
2016-06-10 12:44:26 +02:00
|
|
|
# Copyright (c) 2016, Adfinis SyGroup AG
|
|
|
|
# Tobias Rueetschi <tobias.ruetschi@adfinis-sygroup.ch>
|
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
#
|
|
|
|
|
2016-05-24 17:02:17 +02:00
|
|
|
|
2016-06-10 12:54:50 +02:00
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
2016-06-10 12:42:44 +02:00
|
|
|
from ansible.module_utils.univention_umc import (
|
|
|
|
umc_module_for_add,
|
|
|
|
umc_module_for_edit,
|
|
|
|
ldap_search,
|
|
|
|
base_dn,
|
2016-05-24 17:02:17 +02:00
|
|
|
)
|
2016-06-10 12:42:44 +02:00
|
|
|
import socket
|
2016-05-24 17:02:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec = dict(
|
|
|
|
name = dict(required=True,
|
|
|
|
type='str'),
|
|
|
|
ou = dict(required=True,
|
|
|
|
type='str'),
|
|
|
|
owner = dict(type='str',
|
|
|
|
default='0'),
|
|
|
|
group = dict(type='str',
|
|
|
|
default='0'),
|
|
|
|
path = dict(type='path',
|
|
|
|
default=None),
|
|
|
|
directorymode = dict(type='str',
|
|
|
|
default='00755'),
|
|
|
|
host = dict(type='str',
|
|
|
|
default=None),
|
|
|
|
root_squash = dict(type='str',
|
|
|
|
default='1'),
|
|
|
|
subtree_checking = dict(type='str',
|
|
|
|
default='1'),
|
|
|
|
sync = dict(type='str',
|
|
|
|
default='sync'),
|
|
|
|
writeable = dict(type='str',
|
|
|
|
default='1'),
|
|
|
|
sambaBlockSize = dict(type='str',
|
|
|
|
default=None),
|
|
|
|
sambaBlockingLocks = dict(type='str',
|
|
|
|
default='1'),
|
|
|
|
sambaBrowseable = dict(type='str',
|
|
|
|
default='1'),
|
|
|
|
sambaCreateMode = dict(type='str',
|
|
|
|
default='0744'),
|
|
|
|
sambaCscPolicy = dict(type='str',
|
|
|
|
default='manual'),
|
|
|
|
sambaCustomSettings = dict(type='list',
|
|
|
|
default=[]),
|
|
|
|
sambaDirectoryMode = dict(type='str',
|
|
|
|
default='0755'),
|
|
|
|
sambaDirectorySecurityMode = dict(type='str',
|
|
|
|
default='0777'),
|
|
|
|
sambaDosFilemode = dict(type='str',
|
|
|
|
default='0'),
|
|
|
|
sambaFakeOplocks = dict(type='str',
|
|
|
|
default='0'),
|
|
|
|
sambaForceCreateMode = dict(type='str',
|
|
|
|
default='0'),
|
|
|
|
sambaForceDirectoryMode = dict(type='str',
|
|
|
|
default='0'),
|
|
|
|
sambaForceDirectorySecurityMode = dict(type='str',
|
|
|
|
default='0'),
|
|
|
|
sambaForceGroup = dict(type='str',
|
|
|
|
default=None),
|
|
|
|
sambaForceSecurityMode = dict(type='str',
|
|
|
|
default='0'),
|
|
|
|
sambaForceUser = dict(type='str',
|
|
|
|
default=None),
|
|
|
|
sambaHideFiles = dict(type='str',
|
|
|
|
default=None),
|
|
|
|
sambaHideUnreadable = dict(type='str',
|
|
|
|
default='0'),
|
|
|
|
sambaHostsAllow = dict(type='list',
|
|
|
|
default=[]),
|
|
|
|
sambaHostsDeny = dict(type='list',
|
|
|
|
default=[]),
|
|
|
|
sambaInheritAcls = dict(type='str',
|
|
|
|
default='1'),
|
|
|
|
sambaInheritOwner = dict(type='str',
|
|
|
|
default='0'),
|
|
|
|
sambaInheritPermissions = dict(type='str',
|
|
|
|
default='0'),
|
|
|
|
sambaInvalidUsers = dict(type='str',
|
|
|
|
default=None),
|
|
|
|
sambaLevel2Oplocks = dict(type='str',
|
|
|
|
default='1'),
|
|
|
|
sambaLocking = dict(type='str',
|
|
|
|
default='1'),
|
|
|
|
sambaMSDFSRoot = dict(type='str',
|
|
|
|
default='0'),
|
|
|
|
sambaName = dict(type='str',
|
2016-06-07 14:48:58 +02:00
|
|
|
default=None),
|
2016-05-24 17:02:17 +02:00
|
|
|
sambaNtAclSupport = dict(type='str',
|
|
|
|
default='1'),
|
|
|
|
sambaOplocks = dict(type='str',
|
|
|
|
default='1'),
|
|
|
|
sambaPostexec = dict(type='str',
|
|
|
|
default=None),
|
|
|
|
sambaPreexec = dict(type='str',
|
|
|
|
default=None),
|
|
|
|
sambaPublic = dict(type='str',
|
|
|
|
default='0'),
|
|
|
|
sambaSecurityMode = dict(type='str',
|
|
|
|
default='0777'),
|
|
|
|
sambaStrictLocking = dict(type='str',
|
|
|
|
default='Auto'),
|
|
|
|
sambaVFSObjects = dict(type='str',
|
|
|
|
default=None),
|
|
|
|
sambaValidUsers = dict(type='str',
|
|
|
|
default=None),
|
|
|
|
sambaWriteList = dict(type='str',
|
|
|
|
default=None),
|
|
|
|
sambaWriteable = dict(type='str',
|
|
|
|
default='1'),
|
|
|
|
nfs_hosts = dict(type='list',
|
|
|
|
default=[]),
|
|
|
|
nfsCustomSettings = dict(type='list',
|
|
|
|
default=[]),
|
|
|
|
state = dict(default='present',
|
|
|
|
choices=['present', 'absent'],
|
|
|
|
type='str')
|
|
|
|
),
|
2016-06-10 12:43:39 +02:00
|
|
|
supports_check_mode=True,
|
|
|
|
required_if = ([
|
|
|
|
('state', 'present', ['path', 'host', 'sambaName'])
|
|
|
|
])
|
2016-05-24 17:02:17 +02:00
|
|
|
)
|
|
|
|
name = module.params['name']
|
|
|
|
state = module.params['state']
|
|
|
|
changed = False
|
|
|
|
|
|
|
|
obj = list(ldap_search(
|
|
|
|
'(&(objectClass=univentionShare)(cn={}))'.format(name),
|
|
|
|
attr=['cn']
|
|
|
|
))
|
|
|
|
|
|
|
|
exists = bool(len(obj))
|
2016-06-10 12:42:44 +02:00
|
|
|
container = 'cn=shares,ou={},{}'.format(module.params['ou'], base_dn())
|
2016-05-24 17:02:17 +02:00
|
|
|
dn = 'cn={},{}'.format(name, container)
|
|
|
|
|
|
|
|
if state == 'present':
|
|
|
|
try:
|
|
|
|
if not exists:
|
|
|
|
obj = umc_module_for_add('shares/share', container)
|
|
|
|
else:
|
|
|
|
obj = umc_module_for_edit('shares/share', dn)
|
|
|
|
|
|
|
|
module.params['printablename'] = '{} ({})'.format(name, module.params['host'])
|
|
|
|
for k in obj.keys():
|
|
|
|
obj[k] = module.params[k]
|
|
|
|
|
|
|
|
diff = obj.diff()
|
2016-06-07 14:48:58 +02:00
|
|
|
if exists:
|
|
|
|
for k in obj.keys():
|
|
|
|
if obj.hasChanged(k):
|
|
|
|
changed=True
|
|
|
|
else:
|
|
|
|
changed=True
|
2016-05-24 17:02:17 +02:00
|
|
|
if not module.check_mode:
|
|
|
|
if not exists:
|
|
|
|
obj.create()
|
|
|
|
elif changed:
|
|
|
|
obj.modify()
|
2016-06-07 14:48:58 +02:00
|
|
|
except Exception as e:
|
2016-05-24 17:02:17 +02:00
|
|
|
module.fail_json(
|
|
|
|
msg='Creating/editing share {} in {} failed: {}'.format(name, container, e)
|
|
|
|
)
|
|
|
|
|
|
|
|
if state == 'absent' and exists:
|
|
|
|
try:
|
|
|
|
obj = umc_module_for_edit('shares/share', dn)
|
|
|
|
if not module.check_mode:
|
|
|
|
obj.remove()
|
|
|
|
changed = True
|
|
|
|
except:
|
|
|
|
module.fail_json(
|
|
|
|
msg='Removing share {} in {} failed: {}'.format(name, container, e)
|
|
|
|
)
|
|
|
|
|
|
|
|
module.exit_json(
|
|
|
|
changed=changed,
|
|
|
|
name=name,
|
|
|
|
diff=diff,
|
|
|
|
container=container
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|