mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -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
|
@ -35,31 +35,6 @@ options:
|
|||
choices: [ "present", "absent" ]
|
||||
required: false
|
||||
default: present
|
||||
login_user:
|
||||
description:
|
||||
- rabbitMQ user for connection
|
||||
required: false
|
||||
default: guest
|
||||
login_password:
|
||||
description:
|
||||
- rabbitMQ password for connection
|
||||
required: false
|
||||
default: false
|
||||
login_host:
|
||||
description:
|
||||
- rabbitMQ host for connection
|
||||
required: false
|
||||
default: localhost
|
||||
login_port:
|
||||
description:
|
||||
- rabbitMQ management api port
|
||||
required: false
|
||||
default: 15672
|
||||
vhost:
|
||||
description:
|
||||
- rabbitMQ virtual host
|
||||
required: false
|
||||
default: "/"
|
||||
durable:
|
||||
description:
|
||||
- whether exchange is durable or not
|
||||
|
@ -90,6 +65,8 @@ options:
|
|||
- extra arguments for exchange. If defined this argument is a key/value dictionary
|
||||
required: false
|
||||
default: {}
|
||||
extends_documentation_fragment:
|
||||
- rabbitmq
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
|
@ -114,30 +91,27 @@ except ImportError:
|
|||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.six.moves.urllib import parse as urllib_parse
|
||||
from ansible.module_utils.rabbitmq import rabbitmq_argument_spec
|
||||
|
||||
|
||||
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, 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'),
|
||||
durable=dict(default=True, type='bool'),
|
||||
auto_delete=dict(default=False, type='bool'),
|
||||
internal=dict(default=False, type='bool'),
|
||||
exchange_type=dict(default='direct', aliases=['type'], type='str'),
|
||||
arguments=dict(default=dict(), type='dict')
|
||||
),
|
||||
supports_check_mode=True
|
||||
)
|
||||
)
|
||||
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
|
||||
|
||||
result = dict(changed=False, name=module.params['name'])
|
||||
|
||||
url = "http://%s:%s/api/exchanges/%s/%s" % (
|
||||
url = "%s://%s:%s/api/exchanges/%s/%s" % (
|
||||
module.params['login_protocol'],
|
||||
module.params['login_host'],
|
||||
module.params['login_port'],
|
||||
urllib_parse.quote(module.params['vhost'], ''),
|
||||
|
@ -147,8 +121,11 @@ def main():
|
|||
if not HAS_REQUESTS:
|
||||
module.fail_json(msg="requests library is required for this module. To install, use `pip install requests`")
|
||||
|
||||
result = dict(changed=False, name=module.params['name'])
|
||||
|
||||
# Check if exchange already exists
|
||||
r = requests.get(url, auth=(module.params['login_user'], module.params['login_password']))
|
||||
r = requests.get(url, auth=(module.params['login_user'], module.params['login_password']),
|
||||
verify=module.params['cacert'], cert=(module.params['cert'], module.params['key']))
|
||||
|
||||
if r.status_code == 200:
|
||||
exchange_exists = True
|
||||
|
@ -199,10 +176,13 @@ def main():
|
|||
"internal": module.params['internal'],
|
||||
"type": module.params['exchange_type'],
|
||||
"arguments": module.params['arguments']
|
||||
})
|
||||
}),
|
||||
verify=module.params['cacert'],
|
||||
cert=(module.params['cert'], module.params['key'])
|
||||
)
|
||||
elif module.params['state'] == 'absent':
|
||||
r = requests.delete(url, auth=(module.params['login_user'], module.params['login_password']))
|
||||
r = requests.delete(url, auth=(module.params['login_user'], module.params['login_password']),
|
||||
verify=module.params['cacert'], cert=(module.params['cert'], module.params['key']))
|
||||
|
||||
# RabbitMQ 3.6.7 changed this response code from 204 to 201
|
||||
if r.status_code == 204 or r.status_code == 201:
|
||||
|
@ -216,8 +196,10 @@ def main():
|
|||
)
|
||||
|
||||
else:
|
||||
result['changed'] = False
|
||||
module.exit_json(**result)
|
||||
module.exit_json(
|
||||
changed=False,
|
||||
name=module.params['name']
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue