Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions plugins/modules/rabbitmq_feature_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
options:
name:
description:
- Feature flag name.
- Feature flag name, or 'all' to enable all features.
type: str
required: true
node:
Expand All @@ -35,6 +35,8 @@
node: rabbit@node-1
'''

import json

from ansible.module_utils.basic import AnsibleModule


Expand All @@ -49,20 +51,29 @@ def __init__(self, module, name, node):

def _exec(self, args, force_exec_in_check_mode=False):
if not self.module.check_mode or (self.module.check_mode and force_exec_in_check_mode):
cmd = [self._rabbitmqctl, '-q', '-n', self.node]
cmd = [self._rabbitmqctl, '--formatter', 'json', '-q', '-n', self.node]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does using this restrict which versions of rabbitmq we support?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jovial do you have any thoughts about the about the above?

rc, out, err = self.module.run_command(cmd + args, check_rc=True)
return out.splitlines()
return json.loads(out)
return list()

def get_flag_state(self):
global_parameters = self._exec(['list_feature_flags'], True)

for param_item in global_parameters:
name, state = param_item.split('\t')
global_parameters = self._exec(['list_feature_flags', 'name', 'state', 'stability'], True)
all_enabled = True

for item in global_parameters:
name = item['name']
state = item['state']
stability = item['stability']
if state != 'enabled' and stability != 'experimental':
all_enabled = False
if name == self.name:
if state == 'enabled':
return 'enabled'
return 'disabled'
if self.name == 'all':
if not all_enabled:
return 'disabled'
return 'enabled'
return 'unavailable'

def enable(self):
Expand All @@ -88,7 +99,7 @@ def main():
if rabbitmq_feature_flag.state == 'disabled':
rabbitmq_feature_flag.enable()
result['changed'] = True
if rabbitmq_feature_flag.state == 'unavailable':
elif rabbitmq_feature_flag.state == 'unavailable':
module.fail_json(msg="%s feature flag is not available" % (name))

module.exit_json(**result)
Expand Down