add mailman_list module
This commit is contained in:
parent
72a2de6888
commit
b761932225
3 changed files with 75 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ mailman:
|
||||||
api:
|
api:
|
||||||
hostname: localhost
|
hostname: localhost
|
||||||
port: 8001
|
port: 8001
|
||||||
|
version: "3.1"
|
||||||
admin:
|
admin:
|
||||||
name: restadmin
|
name: restadmin
|
||||||
pw: "{{ lookup('password', '/dev/null length=32') }}"
|
pw: "{{ lookup('password', '/dev/null length=32') }}"
|
||||||
|
|
|
||||||
70
library/mailman_list.py
Normal file
70
library/mailman_list.py
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
import urllib
|
||||||
|
|
||||||
|
from mailmanclient import Client
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
|
MAILMAN_SUPPORTED_API_VERSION = '3.1'
|
||||||
|
|
||||||
|
def run_module():
|
||||||
|
module_args = dict(
|
||||||
|
api_url=dict(type='str', default='http://localhost:8001/3.1'),
|
||||||
|
api_user=dict(type='str', default='restapi'),
|
||||||
|
api_password=dict(type='str', required=True, no_log=True),
|
||||||
|
name=dict(type='str', required=True),
|
||||||
|
settings=dict(type='dict', default={})
|
||||||
|
)
|
||||||
|
|
||||||
|
result = dict(
|
||||||
|
changed=False,
|
||||||
|
message='',
|
||||||
|
diff={'before': '', 'after': ''}
|
||||||
|
)
|
||||||
|
|
||||||
|
module = AnsibleModule(
|
||||||
|
argument_spec=module_args,
|
||||||
|
supports_check_mode=True
|
||||||
|
)
|
||||||
|
|
||||||
|
client = Client(module.params['api_url'], module.params['api_user'], module.params['api_password'])
|
||||||
|
if not client.system['api_version'] == MAILMAN_SUPPORTED_API_VERSION:
|
||||||
|
module.fail_json(msg='API version {} is not supported, only {} is supported'.format(client.system['api_version'], MAILMAN_SUPPORTED_API_VERSION))
|
||||||
|
|
||||||
|
ml = None
|
||||||
|
try:
|
||||||
|
ml = client.get_list(module.params['name'])
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
if e.code != 404:
|
||||||
|
raise
|
||||||
|
result['changed'] = True
|
||||||
|
if module.check_mode:
|
||||||
|
module.exit_json(**result)
|
||||||
|
addr_domain =module.params['name'].split('@')[-1]
|
||||||
|
addr_local = '@'.join(module.params['name'].split('@')[0:-1])
|
||||||
|
domain = client.get_domain(addr_domain)
|
||||||
|
ml = domain.create_list(addr_local)
|
||||||
|
|
||||||
|
ml_settings = ml.settings
|
||||||
|
result['diff']['before'] = dict(ml_settings)
|
||||||
|
|
||||||
|
for i in module.params['settings']:
|
||||||
|
if ml_settings[i] != module.params['settings'][i]:
|
||||||
|
result['changed'] = True
|
||||||
|
ml_settings[i] = module.params['settings'][i]
|
||||||
|
|
||||||
|
if module.check_mode:
|
||||||
|
result['diff']['after'] = dict(ml.settings)
|
||||||
|
result['diff']['after'].update(module.params['settings'])
|
||||||
|
else:
|
||||||
|
ml_settings.save()
|
||||||
|
result['diff']['after'] = dict(ml.settings)
|
||||||
|
|
||||||
|
module.exit_json(**result)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
run_module()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
- python3-wheel
|
- python3-wheel
|
||||||
- python3-pip
|
- python3-pip
|
||||||
- python3-django-auth-ldap
|
- python3-django-auth-ldap
|
||||||
|
- python3-mailmanclient
|
||||||
|
|
||||||
- name: install mailman addons via pip
|
- name: install mailman addons via pip
|
||||||
notify: restart mailman
|
notify: restart mailman
|
||||||
|
|
@ -49,3 +50,6 @@
|
||||||
mode: 0640
|
mode: 0640
|
||||||
owner: root
|
owner: root
|
||||||
group: list
|
group: list
|
||||||
|
|
||||||
|
- name: flush handlers to get mailman ready
|
||||||
|
meta: flush_handlers
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue