2
# -*- coding: utf-8 -*-
4
# (c) 2013, Chatham Financial <oss@chathamfinancial.com>
6
# This file is part of Ansible
8
# Ansible is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
13
# Ansible is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
23
module: rabbitmq_plugin
24
short_description: Adds or removes users to RabbitMQ
26
- Enables or disables RabbitMQ plugins
32
- Comma-separated list of plugin names
38
- Only enable missing plugins
39
- Does not disable plugins that are not in the names list
42
choices: [ "yes", "no" ]
45
- Specify if pluginss are to be enabled or disabled
48
choices: [enabled, disabled]
50
- code: rabbitmq_plugin names=rabbitmq_management state=enabled
51
description: Enables the rabbitmq_management plugin
54
class RabbitMqPlugins(object):
55
def __init__(self, module):
57
self._rabbitmq_plugins = module.get_bin_path('rabbitmq-plugins', True)
59
def _exec(self, args, run_in_check_mode=False):
60
if not self.module.check_mode or (self.module.check_mode and run_in_check_mode):
61
cmd = [self._rabbitmq_plugins]
62
rc, out, err = self.module.run_command(cmd + args, check_rc=True)
63
return out.splitlines()
67
return self._exec(['list', '-E', '-m'], True)
69
def enable(self, name):
70
self._exec(['enable', name])
72
def disable(self, name):
73
self._exec(['disable', name])
77
names=dict(required=True, aliases=['name']),
78
new_only=dict(default='no', type='bool'),
79
state=dict(default='enabled', choices=['enabled', 'disabled'])
81
module = AnsibleModule(
82
argument_spec=arg_spec,
83
supports_check_mode=True
86
names = module.params['names'].split(',')
87
new_only = module.params['new_only']
88
state = module.params['state']
90
rabbitmq_plugins = RabbitMqPlugins(module)
91
enabled_plugins = rabbitmq_plugins.get_all()
95
if state == 'enabled':
97
for plugin in enabled_plugins:
98
if plugin not in names:
99
rabbitmq_plugins.disable(plugin)
100
disabled.append(plugin)
103
if name not in enabled_plugins:
104
rabbitmq_plugins.enable(name)
107
for plugin in enabled_plugins:
109
rabbitmq_plugins.disable(plugin)
110
disabled.append(plugin)
112
changed = len(enabled) > 0 or len(disabled) > 0
113
module.exit_json(changed=changed, enabled=enabled, disabled=disabled)
115
# this is magic, see lib/ansible/module_common.py
116
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>