summaryrefslogtreecommitdiffstats
path: root/lib/postmulti
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2014-07-06 19:10:59 +0200
committerGuilhem Moulin <guilhem@fripost.org>2015-06-07 02:52:31 +0200
commitf877db8c189fc0a0c43aa5df9303ad34cceb774e (patch)
treea472854d639de03d7338e2c00dd761a89a3fd382 /lib/postmulti
parenta427a868d388513da7b5386ba36f1898d7048dd0 (diff)
Move ansible modules to another directory.
Diffstat (limited to 'lib/postmulti')
-rw-r--r--lib/postmulti103
1 files changed, 0 insertions, 103 deletions
diff --git a/lib/postmulti b/lib/postmulti
deleted file mode 100644
index d6ecb09..0000000
--- a/lib/postmulti
+++ /dev/null
@@ -1,103 +0,0 @@
-#!/usr/bin/python
-
-# Create and manage postfix instances.
-# Copyright (c) 2013 Guilhem Moulin <guilhem@fripost.org>
-#
-# This program 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.
-#
-# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
-
-
-# Look up postfix configuration variable
-def postconf(k, instance=None):
- if instance:
- cmd = [ os.path.join(os.sep, 'usr', 'sbin', 'postmulti')
- , '-x'
- , '-i', instance
- , '--'
- ]
- else:
- cmd = []
-
- cmd.extend([ os.path.join(os.sep, 'usr', 'sbin', 'postconf')
- , '-h', k ])
- return subprocess.check_output(cmd, stderr=subprocess.STDOUT).rstrip()
-
-
-# To destroy an existing instance:
-# postmulti -e disable -i mx
-# postmulti -e destroy -i mx
-
-def main():
- module = AnsibleModule(
- argument_spec = dict(
- instance = dict( required=True ),
- group = dict( required=False )
- ),
- supports_check_mode=True
- )
-
- params = module.params
- instance = params['instance']
- group = params['group']
-
- changed=False
- try:
- enable = postconf('multi_instance_enable')
- wrapper = postconf('multi_instance_wrapper')
-
- if enable != "yes" or not wrapper:
- # Initiate postmulti
- changed = True
- if module.check_mode:
- module.exit_json(changed=changed, msg="init postmulti")
- cmd = [ os.path.join(os.sep, 'usr', 'sbin', 'postmulti') ]
- cmd.extend([ '-e', 'init' ])
- subprocess.check_output(cmd, stderr=subprocess.STDOUT).rstrip()
-
- instances = postconf('multi_instance_directories').split()
- if os.path.join(os.sep, 'etc', 'postfix-%s' % instance) not in instances:
- changed = True
- # Create the instance
-
- if module.check_mode:
- module.exit_json(changed=changed, msg="create postmulti")
- cmd = [ os.path.join(os.sep, 'usr', 'sbin', 'postmulti') ]
- cmd.extend([ '-e', 'create' ])
- if group:
- cmd.extend([ '-G', group ])
- cmd.extend([ '-I', 'postfix-%s' % instance ])
- subprocess.check_output(cmd, stderr=subprocess.STDOUT).rstrip()
-
- elif group != postconf('multi_instance_group', instance):
- changed = True
-
- # Assign a new group, or remove the existing group
- if module.check_mode:
- module.exit_json(changed=changed, msg="assign group")
- cmd = [ os.path.join(os.sep, 'usr', 'sbin', 'postmulti') ]
- cmd.extend([ '-e', 'assign', '-i', 'postfix-%s' % instance ])
- if group:
- cmd.extend([ '-G', group ])
- else:
- cmd.extend([ '-G', '-' ])
- subprocess.check_output(cmd, stderr=subprocess.STDOUT).rstrip()
-
- module.exit_json(changed=changed)
-
- except subprocess.CalledProcessError, e:
- module.fail_json(rv=e.returncode, msg=e.output.rstrip())
-
-
-# this is magic, see lib/ansible/module_common.py
-#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
-main()