1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Pep8 fixes for rabbitmq modules (#24590)

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2017-08-10 15:27:11 +05:30 committed by René Moser
parent 85fc4c67ef
commit f7321a87ca
9 changed files with 192 additions and 207 deletions

View file

@ -116,117 +116,110 @@ from ansible.module_utils.six.moves.urllib import parse as urllib_parse
def main(): def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec = dict( argument_spec=dict(
state = dict(default='present', choices=['present', 'absent'], type='str'), state=dict(default='present', choices=['present', 'absent'], type='str'),
name = dict(required=True, aliases=[ "src", "source" ], type='str'), name=dict(required=True, aliases=["src", "source"], type='str'),
login_user = dict(default='guest', type='str'), login_user=dict(default='guest', type='str'),
login_password = dict(default='guest', type='str', no_log=True), login_password=dict(default='guest', type='str', no_log=True),
login_host = dict(default='localhost', type='str'), login_host=dict(default='localhost', type='str'),
login_port = dict(default='15672', type='str'), login_port=dict(default='15672', type='str'),
vhost = dict(default='/', type='str'), vhost=dict(default='/', type='str'),
destination = dict(required=True, aliases=[ "dst", "dest"], 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'), destination_type=dict(required=True, aliases=["type", "dest_type"], choices=["queue", "exchange"], type='str'),
routing_key = dict(default='#', type='str'), routing_key=dict(default='#', type='str'),
arguments = dict(default=dict(), type='dict') arguments=dict(default=dict(), type='dict')
), ),
supports_check_mode = True supports_check_mode=True
) )
if not HAS_REQUESTS: if not HAS_REQUESTS:
module.fail_json(msg="requests library is required for this module. To install, use `pip install 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'])
if module.params['destination_type'] == "queue": if module.params['destination_type'] == "queue":
dest_type="q" dest_type = "q"
else: else:
dest_type="e" dest_type = "e"
if module.params['routing_key'] == "": if module.params['routing_key'] == "":
props = "~" props = "~"
else: else:
props = urllib_parse.quote(module.params['routing_key'],'') props = urllib_parse.quote(module.params['routing_key'], '')
url = "http://%s:%s/api/bindings/%s/e/%s/%s/%s/%s" % ( base_url = "http://%s:%s/api/bindings" % (module.params['login_host'], module.params['login_port'])
module.params['login_host'],
module.params['login_port'], url = "%s/%s/e/%s/%s/%s/%s" % (base_url,
urllib_parse.quote(module.params['vhost'],''), urllib_parse.quote(module.params['vhost'], ''),
urllib_parse.quote(module.params['name'],''), urllib_parse.quote(module.params['name'], ''),
dest_type, dest_type,
urllib_parse.quote(module.params['destination'],''), urllib_parse.quote(module.params['destination'], ''),
props props
) )
# Check if exchange already exists # 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']))
if r.status_code==200: if r.status_code == 200:
binding_exists = True binding_exists = True
response = r.json() response = r.json()
elif r.status_code==404: elif r.status_code == 404:
binding_exists = False binding_exists = False
response = r.text response = r.text
else: else:
module.fail_json( module.fail_json(
msg = "Invalid response from RESTAPI when trying to check if exchange exists", msg="Invalid response from RESTAPI when trying to check if exchange exists",
details = r.text details=r.text
) )
if module.params['state']=='present': if module.params['state'] == 'present':
change_required = not binding_exists change_required = not binding_exists
else: else:
change_required = binding_exists change_required = binding_exists
# Exit if check_mode # Exit if check_mode
if module.check_mode: if module.check_mode:
module.exit_json( result['changed'] = change_required
changed= change_required, result['details'] = response
name = module.params['name'], result['arguments'] = module.params['arguments']
details = response, module.exit_json(**result)
arguments = module.params['arguments']
)
# Do changes # Do changes
if change_required: if change_required:
if module.params['state'] == 'present': if module.params['state'] == 'present':
url = "http://%s:%s/api/bindings/%s/e/%s/%s/%s" % ( url = "%s/%s/e/%s/%s/%s" % (
module.params['login_host'], base_url,
module.params['login_port'], urllib_parse.quote(module.params['vhost'], ''),
urllib_parse.quote(module.params['vhost'],''), urllib_parse.quote(module.params['name'], ''),
urllib_parse.quote(module.params['name'],''),
dest_type, dest_type,
urllib_parse.quote(module.params['destination'],'') urllib_parse.quote(module.params['destination'], '')
) )
r = requests.post( r = requests.post(
url, url,
auth = (module.params['login_user'],module.params['login_password']), auth=(module.params['login_user'], module.params['login_password']),
headers = { "content-type": "application/json"}, headers={"content-type": "application/json"},
data = json.dumps({ data=json.dumps({
"routing_key": module.params['routing_key'], "routing_key": module.params['routing_key'],
"arguments": module.params['arguments'] "arguments": module.params['arguments']
}) })
) )
elif module.params['state'] == 'absent': 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']))
if r.status_code == 204 or r.status_code == 201: if r.status_code == 204 or r.status_code == 201:
module.exit_json( result['changed'] = True
changed = True, result['destination'] = module.params['destination']
name = module.params['name'], module.exit_json(**result)
destination = module.params['destination']
)
else: else:
module.fail_json( module.fail_json(
msg = "Error creating exchange", msg="Error creating exchange",
status = r.status_code, status=r.status_code,
details = r.text details=r.text
) )
else: else:
module.exit_json( result['changed'] = False
changed = False, module.exit_json(**result)
name = module.params['name']
)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -118,55 +118,57 @@ from ansible.module_utils.six.moves.urllib import parse as urllib_parse
def main(): def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec = dict( argument_spec=dict(
state = dict(default='present', choices=['present', 'absent'], type='str'), state=dict(default='present', choices=['present', 'absent'], type='str'),
name = dict(required=True, type='str'), name=dict(required=True, type='str'),
login_user = dict(default='guest', type='str'), login_user=dict(default='guest', type='str'),
login_password = dict(default='guest', type='str', no_log=True), login_password=dict(default='guest', type='str', no_log=True),
login_host = dict(default='localhost', type='str'), login_host=dict(default='localhost', type='str'),
login_port = dict(default='15672', type='str'), login_port=dict(default='15672', type='str'),
vhost = dict(default='/', type='str'), vhost=dict(default='/', type='str'),
durable = dict(default=True, type='bool'), durable=dict(default=True, type='bool'),
auto_delete = dict(default=False, type='bool'), auto_delete=dict(default=False, type='bool'),
internal = dict(default=False, type='bool'), internal=dict(default=False, type='bool'),
exchange_type = dict(default='direct', aliases=['type'], type='str'), exchange_type=dict(default='direct', aliases=['type'], type='str'),
arguments = dict(default=dict(), type='dict') arguments=dict(default=dict(), type='dict')
), ),
supports_check_mode = True supports_check_mode=True
) )
result = dict(changed=False, name=module.params['name'])
url = "http://%s:%s/api/exchanges/%s/%s" % ( url = "http://%s:%s/api/exchanges/%s/%s" % (
module.params['login_host'], module.params['login_host'],
module.params['login_port'], module.params['login_port'],
urllib_parse.quote(module.params['vhost'],''), urllib_parse.quote(module.params['vhost'], ''),
urllib_parse.quote(module.params['name'],'') urllib_parse.quote(module.params['name'], '')
) )
if not HAS_REQUESTS: if not HAS_REQUESTS:
module.fail_json(msg="requests library is required for this module. To install, use `pip install requests`") module.fail_json(msg="requests library is required for this module. To install, use `pip install requests`")
# Check if exchange already exists # 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']))
if r.status_code==200: if r.status_code == 200:
exchange_exists = True exchange_exists = True
response = r.json() response = r.json()
elif r.status_code==404: elif r.status_code == 404:
exchange_exists = False exchange_exists = False
response = r.text response = r.text
else: else:
module.fail_json( module.fail_json(
msg = "Invalid response from RESTAPI when trying to check if exchange exists", msg="Invalid response from RESTAPI when trying to check if exchange exists",
details = r.text details=r.text
) )
if module.params['state']=='present': if module.params['state'] == 'present':
change_required = not exchange_exists change_required = not exchange_exists
else: else:
change_required = exchange_exists change_required = exchange_exists
# Check if attributes change on existing exchange # Check if attributes change on existing exchange
if not change_required and r.status_code==200 and module.params['state'] == 'present': if not change_required and r.status_code == 200 and module.params['state'] == 'present':
if not ( if not (
response['durable'] == module.params['durable'] and response['durable'] == module.params['durable'] and
response['auto_delete'] == module.params['auto_delete'] and response['auto_delete'] == module.params['auto_delete'] and
@ -174,55 +176,48 @@ def main():
response['type'] == module.params['exchange_type'] response['type'] == module.params['exchange_type']
): ):
module.fail_json( module.fail_json(
msg = "RabbitMQ RESTAPI doesn't support attribute changes for existing exchanges" msg="RabbitMQ RESTAPI doesn't support attribute changes for existing exchanges"
) )
# Exit if check_mode # Exit if check_mode
if module.check_mode: if module.check_mode:
module.exit_json( result['changed'] = change_required
changed= change_required, result['details'] = response
name = module.params['name'], result['arguments'] = module.params['arguments']
details = response, module.exit_json(**result)
arguments = module.params['arguments']
)
# Do changes # Do changes
if change_required: if change_required:
if module.params['state'] == 'present': if module.params['state'] == 'present':
r = requests.put( r = requests.put(
url, url,
auth = (module.params['login_user'],module.params['login_password']), auth=(module.params['login_user'], module.params['login_password']),
headers = { "content-type": "application/json"}, headers={"content-type": "application/json"},
data = json.dumps({ data=json.dumps({
"durable": module.params['durable'], "durable": module.params['durable'],
"auto_delete": module.params['auto_delete'], "auto_delete": module.params['auto_delete'],
"internal": module.params['internal'], "internal": module.params['internal'],
"type": module.params['exchange_type'], "type": module.params['exchange_type'],
"arguments": module.params['arguments'] "arguments": module.params['arguments']
}) })
) )
elif module.params['state'] == 'absent': 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']))
# RabbitMQ 3.6.7 changed this response code from 204 to 201 # RabbitMQ 3.6.7 changed this response code from 204 to 201
if r.status_code == 204 or r.status_code == 201: if r.status_code == 204 or r.status_code == 201:
module.exit_json( result['changed'] = True
changed = True, module.exit_json(**result)
name = module.params['name']
)
else: else:
module.fail_json( module.fail_json(
msg = "Error creating exchange", msg="Error creating exchange",
status = r.status_code, status=r.status_code,
details = r.text details=r.text
) )
else: else:
module.exit_json( result['changed'] = False
changed = False, module.exit_json(**result)
name = module.params['name']
)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -65,7 +65,6 @@ EXAMPLES = """
state: present state: present
""" """
import json import json
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
@ -114,6 +113,7 @@ class RabbitMqParameter(object):
def has_modifications(self): def has_modifications(self):
return self.value != self._value return self.value != self._value
def main(): def main():
arg_spec = dict( arg_spec = dict(
component=dict(required=True), component=dict(required=True),
@ -137,23 +137,26 @@ def main():
state = module.params['state'] state = module.params['state']
node = module.params['node'] node = module.params['node']
result = dict(changed=False)
rabbitmq_parameter = RabbitMqParameter(module, component, name, value, vhost, node) rabbitmq_parameter = RabbitMqParameter(module, component, name, value, vhost, node)
changed = False
if rabbitmq_parameter.get(): if rabbitmq_parameter.get():
if state == 'absent': if state == 'absent':
rabbitmq_parameter.delete() rabbitmq_parameter.delete()
changed = True result['changed'] = True
else: else:
if rabbitmq_parameter.has_modifications(): if rabbitmq_parameter.has_modifications():
rabbitmq_parameter.set() rabbitmq_parameter.set()
changed = True result['changed'] = True
elif state == 'present': elif state == 'present':
rabbitmq_parameter.set() rabbitmq_parameter.set()
changed = True result['changed'] = True
module.exit_json(changed=changed, component=component, name=name, vhost=vhost, state=state)
result['component'] = component
result['name'] = name
result['vhost'] = vhost
result['state'] = state
module.exit_json(**result)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -57,11 +57,14 @@ EXAMPLES = '''
''' '''
import os import os
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
class RabbitMqPlugins(object): class RabbitMqPlugins(object):
def __init__(self, module): def __init__(self, module):
self.module = module self.module = module
@ -73,7 +76,7 @@ class RabbitMqPlugins(object):
else: else:
# No such path exists. # No such path exists.
raise Exception("No binary folder in prefix %s" % raise Exception("No binary folder in prefix %s" %
module.params['prefix']) module.params['prefix'])
self._rabbitmq_plugins = bin_path + "/rabbitmq-plugins" self._rabbitmq_plugins = bin_path + "/rabbitmq-plugins"
@ -116,6 +119,7 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
result = dict()
names = module.params['names'].split(',') names = module.params['names'].split(',')
new_only = module.params['new_only'] new_only = module.params['new_only']
state = module.params['state'] state = module.params['state']
@ -142,8 +146,10 @@ def main():
rabbitmq_plugins.disable(plugin) rabbitmq_plugins.disable(plugin)
disabled.append(plugin) disabled.append(plugin)
changed = len(enabled) > 0 or len(disabled) > 0 result['changed'] = len(enabled) > 0 or len(disabled) > 0
module.exit_json(changed=changed, enabled=enabled, disabled=disabled) result['enabled'] = enabled
result['disabled'] = disabled
module.exit_json(**result)
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -82,10 +82,13 @@ EXAMPLES = '''
tags: tags:
ha-mode: all ha-mode: all
''' '''
import json
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
class RabbitMqPolicy(object): class RabbitMqPolicy(object):
def __init__(self, module, name): def __init__(self, module, name):
self._module = module self._module = module
self._name = name self._name = name
@ -116,14 +119,13 @@ class RabbitMqPolicy(object):
return False return False
def set(self): def set(self):
import json
args = ['set_policy'] args = ['set_policy']
args.append(self._name) args.append(self._name)
args.append(self._pattern) args.append(self._pattern)
args.append(json.dumps(self._tags)) args.append(json.dumps(self._tags))
args.append('--priority') args.append('--priority')
args.append(self._priority) args.append(self._priority)
if (self._apply_to != 'all'): if self._apply_to != 'all':
args.append('--apply-to') args.append('--apply-to')
args.append(self._apply_to) args.append(self._apply_to)
return self._exec(args) return self._exec(args)
@ -153,19 +155,18 @@ def main():
state = module.params['state'] state = module.params['state']
rabbitmq_policy = RabbitMqPolicy(module, name) rabbitmq_policy = RabbitMqPolicy(module, name)
changed = False result = dict(changed=False, name=name, state=state)
if rabbitmq_policy.list(): if rabbitmq_policy.list():
if state == 'absent': if state == 'absent':
rabbitmq_policy.clear() rabbitmq_policy.clear()
changed = True result['changed'] = True
else: else:
changed = False result['changed'] = False
elif state == 'present': elif state == 'present':
rabbitmq_policy.set() rabbitmq_policy.set()
changed = True result['changed'] = True
module.exit_json(changed=changed, name=name, state=state)
module.exit_json(**result)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -133,72 +133,74 @@ from ansible.module_utils.six.moves.urllib import parse as urllib_parse
def main(): def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec = dict( argument_spec=dict(
state = dict(default='present', choices=['present', 'absent'], type='str'), state=dict(default='present', choices=['present', 'absent'], type='str'),
name = dict(required=True, type='str'), name=dict(required=True, type='str'),
login_user = dict(default='guest', type='str'), login_user=dict(default='guest', type='str'),
login_password = dict(default='guest', type='str', no_log=True), login_password=dict(default='guest', type='str', no_log=True),
login_host = dict(default='localhost', type='str'), login_host=dict(default='localhost', type='str'),
login_port = dict(default='15672', type='str'), login_port=dict(default='15672', type='str'),
vhost = dict(default='/', type='str'), vhost=dict(default='/', type='str'),
durable = dict(default=True, type='bool'), durable=dict(default=True, type='bool'),
auto_delete = dict(default=False, type='bool'), auto_delete=dict(default=False, type='bool'),
message_ttl = dict(default=None, type='int'), message_ttl=dict(default=None, type='int'),
auto_expires = dict(default=None, type='int'), auto_expires=dict(default=None, type='int'),
max_length = dict(default=None, type='int'), max_length=dict(default=None, type='int'),
dead_letter_exchange = dict(default=None, type='str'), dead_letter_exchange=dict(default=None, type='str'),
dead_letter_routing_key = dict(default=None, type='str'), dead_letter_routing_key=dict(default=None, type='str'),
arguments = dict(default=dict(), type='dict') arguments=dict(default=dict(), type='dict')
), ),
supports_check_mode = True supports_check_mode=True
) )
url = "http://%s:%s/api/queues/%s/%s" % ( url = "http://%s:%s/api/queues/%s/%s" % (
module.params['login_host'], module.params['login_host'],
module.params['login_port'], module.params['login_port'],
urllib_parse.quote(module.params['vhost'],''), urllib_parse.quote(module.params['vhost'], ''),
module.params['name'] module.params['name']
) )
if not HAS_REQUESTS: if not HAS_REQUESTS:
module.fail_json(msg="requests library is required for this module. To install, use `pip install requests`") module.fail_json(msg="requests library is required for this module. To install, use `pip install requests`")
# Check if queue already exists result = dict(changed=False, name=module.params['name'])
r = requests.get( url, auth=(module.params['login_user'],module.params['login_password']))
if r.status_code==200: # Check if queue already exists
r = requests.get(url, auth=(module.params['login_user'], module.params['login_password']))
if r.status_code == 200:
queue_exists = True queue_exists = True
response = r.json() response = r.json()
elif r.status_code==404: elif r.status_code == 404:
queue_exists = False queue_exists = False
response = r.text response = r.text
else: else:
module.fail_json( module.fail_json(
msg = "Invalid response from RESTAPI when trying to check if queue exists", msg="Invalid response from RESTAPI when trying to check if queue exists",
details = r.text details=r.text
) )
if module.params['state']=='present': if module.params['state'] == 'present':
change_required = not queue_exists change_required = not queue_exists
else: else:
change_required = queue_exists change_required = queue_exists
# Check if attributes change on existing queue # Check if attributes change on existing queue
if not change_required and r.status_code==200 and module.params['state'] == 'present': if not change_required and r.status_code == 200 and module.params['state'] == 'present':
if not ( if not (
response['durable'] == module.params['durable'] and response['durable'] == module.params['durable'] and
response['auto_delete'] == module.params['auto_delete'] and response['auto_delete'] == module.params['auto_delete'] and
( (
( 'x-message-ttl' in response['arguments'] and response['arguments']['x-message-ttl'] == module.params['message_ttl'] ) or ('x-message-ttl' in response['arguments'] and response['arguments']['x-message-ttl'] == module.params['message_ttl']) or
( 'x-message-ttl' not in response['arguments'] and module.params['message_ttl'] is None ) ('x-message-ttl' not in response['arguments'] and module.params['message_ttl'] is None)
) and ) and
( (
( 'x-expires' in response['arguments'] and response['arguments']['x-expires'] == module.params['auto_expires'] ) or ('x-expires' in response['arguments'] and response['arguments']['x-expires'] == module.params['auto_expires']) or
( 'x-expires' not in response['arguments'] and module.params['auto_expires'] is None ) ('x-expires' not in response['arguments'] and module.params['auto_expires'] is None)
) and ) and
( (
( 'x-max-length' in response['arguments'] and response['arguments']['x-max-length'] == module.params['max_length'] ) or ('x-max-length' in response['arguments'] and response['arguments']['x-max-length'] == module.params['max_length']) or
( 'x-max-length' not in response['arguments'] and module.params['max_length'] is None ) ('x-max-length' not in response['arguments'] and module.params['max_length'] is None)
) and ) and
( (
('x-dead-letter-exchange' in response['arguments'] and ('x-dead-letter-exchange' in response['arguments'] and
@ -212,12 +214,11 @@ def main():
) )
): ):
module.fail_json( module.fail_json(
msg = "RabbitMQ RESTAPI doesn't support attribute changes for existing queues", msg="RabbitMQ RESTAPI doesn't support attribute changes for existing queues",
) )
# Copy parameters to arguments as used by RabbitMQ # Copy parameters to arguments as used by RabbitMQ
for k,v in { for k, v in {
'message_ttl': 'x-message-ttl', 'message_ttl': 'x-message-ttl',
'auto_expires': 'x-expires', 'auto_expires': 'x-expires',
'max_length': 'x-max-length', 'max_length': 'x-max-length',
@ -229,48 +230,41 @@ def main():
# Exit if check_mode # Exit if check_mode
if module.check_mode: if module.check_mode:
module.exit_json( result['changed'] = change_required
changed= change_required, result['details'] = response
name = module.params['name'], result['arguments'] = module.params['arguments']
details = response, module.exit_json(**result)
arguments = module.params['arguments']
)
# Do changes # Do changes
if change_required: if change_required:
if module.params['state'] == 'present': if module.params['state'] == 'present':
r = requests.put( r = requests.put(
url, url,
auth = (module.params['login_user'],module.params['login_password']), auth=(module.params['login_user'], module.params['login_password']),
headers = { "content-type": "application/json"}, headers={"content-type": "application/json"},
data = json.dumps({ data=json.dumps({
"durable": module.params['durable'], "durable": module.params['durable'],
"auto_delete": module.params['auto_delete'], "auto_delete": module.params['auto_delete'],
"arguments": module.params['arguments'] "arguments": module.params['arguments']
}) })
) )
elif module.params['state'] == 'absent': 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']))
# RabbitMQ 3.6.7 changed this response code from 204 to 201 # RabbitMQ 3.6.7 changed this response code from 204 to 201
if r.status_code == 204 or r.status_code == 201: if r.status_code == 204 or r.status_code == 201:
module.exit_json( result['changed'] = True
changed = True, module.exit_json(**result)
name = module.params['name']
)
else: else:
module.fail_json( module.fail_json(
msg = "Error creating queue", msg="Error creating queue",
status = r.status_code, status=r.status_code,
details = r.text details=r.text
) )
else: else:
module.exit_json( result['changed'] = False
changed = False, module.exit_json(**result)
name = module.params['name']
)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -165,7 +165,7 @@ class RabbitMqUser(object):
user, tags = user_tag.split('\t') user, tags = user_tag.split('\t')
if user == self.username: if user == self.username:
for c in ['[',']',' ']: for c in ['[', ']', ' ']:
tags = tags.replace(c, '') tags = tags.replace(c, '')
if tags != '': if tags != '':
@ -229,6 +229,7 @@ class RabbitMqUser(object):
def has_permissions_modifications(self): def has_permissions_modifications(self):
return sorted(self._permissions) != sorted(self.permissions) return sorted(self._permissions) != sorted(self.permissions)
def main(): def main():
arg_spec = dict( arg_spec = dict(
user=dict(required=True, aliases=['username', 'name']), user=dict(required=True, aliases=['username', 'name']),
@ -261,7 +262,7 @@ def main():
node = module.params['node'] node = module.params['node']
bulk_permissions = True bulk_permissions = True
if permissions == []: if not permissions:
perm = { perm = {
'vhost': vhost, 'vhost': vhost,
'configure_priv': configure_priv, 'configure_priv': configure_priv,
@ -274,33 +275,33 @@ def main():
rabbitmq_user = RabbitMqUser(module, username, password, tags, permissions, rabbitmq_user = RabbitMqUser(module, username, password, tags, permissions,
node, bulk_permissions=bulk_permissions) node, bulk_permissions=bulk_permissions)
changed = False result = dict(changed=False, user=username, state=state)
if rabbitmq_user.get(): if rabbitmq_user.get():
if state == 'absent': if state == 'absent':
rabbitmq_user.delete() rabbitmq_user.delete()
changed = True result['changed'] = True
else: else:
if force: if force:
rabbitmq_user.delete() rabbitmq_user.delete()
rabbitmq_user.add() rabbitmq_user.add()
rabbitmq_user.get() rabbitmq_user.get()
changed = True result['changed'] = True
if rabbitmq_user.has_tags_modifications(): if rabbitmq_user.has_tags_modifications():
rabbitmq_user.set_tags() rabbitmq_user.set_tags()
changed = True result['changed'] = True
if rabbitmq_user.has_permissions_modifications(): if rabbitmq_user.has_permissions_modifications():
rabbitmq_user.set_permissions() rabbitmq_user.set_permissions()
changed = True result['changed'] = True
elif state == 'present': elif state == 'present':
rabbitmq_user.add() rabbitmq_user.add()
rabbitmq_user.set_tags() rabbitmq_user.set_tags()
rabbitmq_user.set_permissions() rabbitmq_user.set_permissions()
changed = True result['changed'] = True
module.exit_json(changed=changed, user=username, state=state)
module.exit_json(**result)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -123,24 +123,22 @@ def main():
tracing = module.params['tracing'] tracing = module.params['tracing']
state = module.params['state'] state = module.params['state']
node = module.params['node'] node = module.params['node']
result = dict(changed=False, name=name, state=state)
rabbitmq_vhost = RabbitMqVhost(module, name, tracing, node) rabbitmq_vhost = RabbitMqVhost(module, name, tracing, node)
changed = False
if rabbitmq_vhost.get(): if rabbitmq_vhost.get():
if state == 'absent': if state == 'absent':
rabbitmq_vhost.delete() rabbitmq_vhost.delete()
changed = True result['changed'] = True
else: else:
if rabbitmq_vhost.set_tracing(): if rabbitmq_vhost.set_tracing():
changed = True result['changed'] = True
elif state == 'present': elif state == 'present':
rabbitmq_vhost.add() rabbitmq_vhost.add()
rabbitmq_vhost.set_tracing() rabbitmq_vhost.set_tracing()
changed = True result['changed'] = True
module.exit_json(changed=changed, name=name, state=state)
module.exit_json(**result)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -216,12 +216,6 @@ lib/ansible/modules/files/replace.py
lib/ansible/modules/files/synchronize.py lib/ansible/modules/files/synchronize.py
lib/ansible/modules/files/tempfile.py lib/ansible/modules/files/tempfile.py
lib/ansible/modules/files/xattr.py lib/ansible/modules/files/xattr.py
lib/ansible/modules/messaging/rabbitmq_binding.py
lib/ansible/modules/messaging/rabbitmq_exchange.py
lib/ansible/modules/messaging/rabbitmq_parameter.py
lib/ansible/modules/messaging/rabbitmq_plugin.py
lib/ansible/modules/messaging/rabbitmq_queue.py
lib/ansible/modules/messaging/rabbitmq_user.py
lib/ansible/modules/monitoring/airbrake_deployment.py lib/ansible/modules/monitoring/airbrake_deployment.py
lib/ansible/modules/monitoring/bigpanda.py lib/ansible/modules/monitoring/bigpanda.py
lib/ansible/modules/monitoring/boundary_meter.py lib/ansible/modules/monitoring/boundary_meter.py