mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #2251 from chrishoffman/rabbitmq
Rabbitmq parameters module
This commit is contained in:
commit
f9824838c3
3 changed files with 145 additions and 3 deletions
|
@ -15,7 +15,7 @@
|
||||||
apt: pkg=rabbitmq-server=$rabbitmq_version state=installed force=yes
|
apt: pkg=rabbitmq-server=$rabbitmq_version state=installed force=yes
|
||||||
|
|
||||||
- name: enable rabbitmq plugins
|
- name: enable rabbitmq plugins
|
||||||
rabbitmq_plugin: names=rabbitmq_management,rabbitmq_tracing state=enabled
|
rabbitmq_plugin: names=rabbitmq_management,rabbitmq_tracing,rabbitmq_federation state=enabled
|
||||||
notify:
|
notify:
|
||||||
- restart rabbitmq
|
- restart rabbitmq
|
||||||
|
|
||||||
|
@ -31,6 +31,9 @@
|
||||||
- name: ensure vhost /test is present
|
- name: ensure vhost /test is present
|
||||||
rabbitmq_vhost: name=/test state=present
|
rabbitmq_vhost: name=/test state=present
|
||||||
|
|
||||||
|
- name: set federation local-username
|
||||||
|
rabbitmq_parameter: component=federation name=local-username value='"user1"' state=present
|
||||||
|
|
||||||
handlers:
|
handlers:
|
||||||
- name: restart rabbitmq
|
- name: restart rabbitmq
|
||||||
service: name=rabbitmq-server state=restarted
|
service: name=rabbitmq-server state=restarted
|
||||||
|
|
138
library/rabbitmq_parameter
Normal file
138
library/rabbitmq_parameter
Normal file
|
@ -0,0 +1,138 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# (c) 2013, Chatham Financial <oss@chathamfinancial.com>
|
||||||
|
#
|
||||||
|
# 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/>.
|
||||||
|
|
||||||
|
DOCUMENTATION = '''
|
||||||
|
---
|
||||||
|
module: rabbitmq_parameter
|
||||||
|
short_description: Adds or removes parameters to RabbitMQ
|
||||||
|
description:
|
||||||
|
- Manage dynamic, cluster-wide parameters for RabbitMQ
|
||||||
|
version_added: 1.1
|
||||||
|
author: Chris Hoffman
|
||||||
|
options:
|
||||||
|
component:
|
||||||
|
description:
|
||||||
|
- Name of the component of which the parameter is being set
|
||||||
|
required: true
|
||||||
|
default: null
|
||||||
|
name:
|
||||||
|
description:
|
||||||
|
- Name of the parameter being set
|
||||||
|
required: true
|
||||||
|
default: null
|
||||||
|
value:
|
||||||
|
description:
|
||||||
|
- Value of the parameter, as a JSON term
|
||||||
|
required: false
|
||||||
|
default: null
|
||||||
|
vhost:
|
||||||
|
description:
|
||||||
|
- vhost to apply access privileges.
|
||||||
|
required: false
|
||||||
|
default: /
|
||||||
|
state:
|
||||||
|
description:
|
||||||
|
- Specify if user is to be added or removed
|
||||||
|
required: false
|
||||||
|
default: present
|
||||||
|
choices: [present, absent]
|
||||||
|
examples:
|
||||||
|
- code: rabbitmq_parameter: component=federation name=local-username value='"guest"' state=present
|
||||||
|
description: Add the federation parameter local_username to value of guest
|
||||||
|
'''
|
||||||
|
|
||||||
|
class RabbitMqParameter(object):
|
||||||
|
def __init__(self, module, component, name, value, vhost):
|
||||||
|
self.module = module
|
||||||
|
self.component = component
|
||||||
|
self.name = name
|
||||||
|
self.value = value
|
||||||
|
self.vhost = vhost
|
||||||
|
|
||||||
|
self._value = None
|
||||||
|
|
||||||
|
self._rabbitmqctl = module.get_bin_path('rabbitmqctl', True)
|
||||||
|
|
||||||
|
def _exec(self, args, run_in_check_mode=False):
|
||||||
|
if not self.module.check_mode or (self.module.check_mode and run_in_check_mode):
|
||||||
|
cmd = [self._rabbitmqctl, '-q']
|
||||||
|
rc, out, err = self.module.run_command(cmd + args, check_rc=True)
|
||||||
|
return out.splitlines()
|
||||||
|
return list()
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
parameters = self._exec(['list_parameters', '-p', self.vhost], True)
|
||||||
|
|
||||||
|
for param_item in parameters:
|
||||||
|
component, name, value = param_item.split('\t')
|
||||||
|
|
||||||
|
if component == self.component and name == self.name:
|
||||||
|
self._value = value
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def set(self):
|
||||||
|
self._exec(['set_parameter', '-p', self.vhost, self.component, self.name, self.value])
|
||||||
|
|
||||||
|
def delete(self):
|
||||||
|
self._exec(['clear_parameter', '-p', self.vhost, self.component, self.name])
|
||||||
|
|
||||||
|
def has_modifications(self):
|
||||||
|
return self.value != self._value
|
||||||
|
|
||||||
|
def main():
|
||||||
|
arg_spec = dict(
|
||||||
|
component=dict(required=True),
|
||||||
|
name=dict(required=True),
|
||||||
|
value=dict(default=None),
|
||||||
|
vhost=dict(default='/'),
|
||||||
|
state=dict(default='present', choices=['present', 'absent'])
|
||||||
|
)
|
||||||
|
module = AnsibleModule(
|
||||||
|
argument_spec=arg_spec,
|
||||||
|
supports_check_mode=True
|
||||||
|
)
|
||||||
|
|
||||||
|
component = module.params['component']
|
||||||
|
name = module.params['name']
|
||||||
|
value = module.params['value']
|
||||||
|
vhost = module.params['vhost']
|
||||||
|
state = module.params['state']
|
||||||
|
|
||||||
|
rabbitmq_parameter = RabbitMqParameter(module, component, name, value, vhost)
|
||||||
|
|
||||||
|
changed = False
|
||||||
|
if rabbitmq_parameter.get():
|
||||||
|
if state == 'absent':
|
||||||
|
rabbitmq_parameter.delete()
|
||||||
|
changed = True
|
||||||
|
else:
|
||||||
|
if rabbitmq_parameter.has_modifications():
|
||||||
|
rabbitmq_parameter.set()
|
||||||
|
changed = True
|
||||||
|
elif state == 'present':
|
||||||
|
rabbitmq_parameter.set()
|
||||||
|
changed = True
|
||||||
|
|
||||||
|
module.exit_json(changed=changed, component=component, name=name, vhost=vhost, state=state)
|
||||||
|
|
||||||
|
# this is magic, see lib/ansible/module_common.py
|
||||||
|
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
|
||||||
|
main()
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# (c) 2013, Matt Cordial <matt.cordial@gmail.com>
|
# (c) 2013, Chatham Financial <oss@chathamfinancial.com>
|
||||||
#
|
#
|
||||||
# This file is part of Ansible
|
# This file is part of Ansible
|
||||||
#
|
#
|
||||||
|
@ -25,6 +25,8 @@ module: rabbitmq_vhost
|
||||||
short_description: Manage the state of a virtual host in RabbitMQ
|
short_description: Manage the state of a virtual host in RabbitMQ
|
||||||
description:
|
description:
|
||||||
- Manage the state of a virtual host in RabbitMQ
|
- Manage the state of a virtual host in RabbitMQ
|
||||||
|
version_added: 1.1
|
||||||
|
author: Chris Hoffman
|
||||||
options:
|
options:
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
|
@ -46,7 +48,6 @@ options:
|
||||||
examples:
|
examples:
|
||||||
- code: 'rabbitmq_vhost: name=/test state=present'
|
- code: 'rabbitmq_vhost: name=/test state=present'
|
||||||
description: Ensure that the vhost /test exists.
|
description: Ensure that the vhost /test exists.
|
||||||
author: Matt Cordial
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
class RabbitMqVhost(object):
|
class RabbitMqVhost(object):
|
||||||
|
|
Loading…
Reference in a new issue