mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-18 02:40:21 -07:00
Rabbitmq: Enable communication to management API over HTTPS (#18437)
* Enable communication to management API over HTTPS. * Specify version added tags to new parameters * Set proper parameter type. * Corrected version_added numbers. * Extracted commons to ansible utils. * Fix PEP8 error * Fix documentation extension syntax. Fixes #22953
This commit is contained in:
parent
5e67981dd2
commit
e7ddff1928
5 changed files with 142 additions and 110 deletions
|
@ -36,26 +36,6 @@ options:
|
|||
- source exchange to create binding on.
|
||||
required: true
|
||||
aliases: [ "src", "source" ]
|
||||
login_user:
|
||||
description:
|
||||
- rabbitMQ user for the connection.
|
||||
default: guest
|
||||
login_password:
|
||||
description:
|
||||
- rabbitMQ password for the connection.
|
||||
default: false
|
||||
login_host:
|
||||
description:
|
||||
- rabbitMQ host for the connection.
|
||||
default: localhost
|
||||
login_port:
|
||||
description:
|
||||
- rabbitMQ management API port.
|
||||
default: 15672
|
||||
vhost:
|
||||
description:
|
||||
- rabbitMQ virtual host.
|
||||
default: "/"
|
||||
destination:
|
||||
description:
|
||||
- destination exchange or queue for the binding.
|
||||
|
@ -73,8 +53,11 @@ options:
|
|||
default: "#"
|
||||
arguments:
|
||||
description:
|
||||
- extra arguments for exchange. If defined this argument is a key/value dictionary.
|
||||
- extra arguments for exchange. If defined this argument is a key/value dictionary
|
||||
required: false
|
||||
default: {}
|
||||
extends_documentation_fragment:
|
||||
- rabbitmq
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
|
@ -104,6 +87,7 @@ except ImportError:
|
|||
|
||||
from ansible.module_utils.six.moves.urllib import parse as urllib_parse
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.rabbitmq import rabbitmq_argument_spec
|
||||
|
||||
|
||||
class RabbitMqBinding(object):
|
||||
|
@ -117,13 +101,18 @@ class RabbitMqBinding(object):
|
|||
self.login_password = self.module.params['login_password']
|
||||
self.login_host = self.module.params['login_host']
|
||||
self.login_port = self.module.params['login_port']
|
||||
self.login_protocol = self.module.params['login_protocol']
|
||||
self.vhost = self.module.params['vhost']
|
||||
self.destination = self.module.params['destination']
|
||||
self.destination_type = 'q' if self.module.params['destination_type'] == 'queue' else 'e'
|
||||
self.routing_key = self.module.params['routing_key']
|
||||
self.arguments = self.module.params['arguments']
|
||||
self.base_url = 'http://{0}:{1}/api/bindings'.format(self.login_host,
|
||||
self.login_port)
|
||||
self.verify = self.module.params['cacert']
|
||||
self.cert = self.module.params['cert']
|
||||
self.key = self.module.params['key']
|
||||
self.base_url = '{0}://{1}:{2}/api/bindings'.format(self.login_protocol,
|
||||
self.login_host,
|
||||
self.login_port)
|
||||
self.url = '{0}/{1}/e/{2}/{3}/{4}/{5}'.format(self.base_url,
|
||||
urllib_parse.quote(self.vhost, safe=''),
|
||||
urllib_parse.quote(self.name, safe=''),
|
||||
|
@ -253,6 +242,8 @@ class RabbitMqBinding(object):
|
|||
urllib_parse.quote(self.destination, safe=''))
|
||||
self.api_result = self.request.post(self.url,
|
||||
auth=self.authentication,
|
||||
verify=self.cacert,
|
||||
cert=(self.cert, self.key),
|
||||
headers={"content-type": "application/json"},
|
||||
data=json.dumps({
|
||||
'routing_key': self.routing_key,
|
||||
|
@ -277,23 +268,20 @@ class RabbitMqBinding(object):
|
|||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
|
||||
argument_spec = rabbitmq_argument_spec()
|
||||
argument_spec.update(
|
||||
dict(
|
||||
state=dict(default='present', choices=['present', 'absent'], type='str'),
|
||||
name=dict(required=True, aliases=["src", "source"], type='str'),
|
||||
login_user=dict(default='guest', type='str'),
|
||||
login_password=dict(default='guest', type='str', no_log=True),
|
||||
login_host=dict(default='localhost', type='str'),
|
||||
login_port=dict(default='15672', type='str'),
|
||||
vhost=dict(default='/', type='str'),
|
||||
destination=dict(required=True, aliases=["dst", "dest"], type='str'),
|
||||
destination_type=dict(required=True, aliases=["type", "dest_type"], choices=["queue", "exchange"],
|
||||
type='str'),
|
||||
routing_key=dict(default='#', type='str'),
|
||||
arguments=dict(default=dict(), type='dict')
|
||||
),
|
||||
supports_check_mode=True
|
||||
)
|
||||
)
|
||||
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
|
||||
|
||||
if not HAS_REQUESTS:
|
||||
module.fail_json(msg="requests library is required for this module. To install, use `pip install requests`")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue