mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Updating how to run commands in check mode
This commit is contained in:
parent
ca3b8228f7
commit
507e49396b
2 changed files with 24 additions and 26 deletions
|
@ -57,9 +57,11 @@ class RabbitMqPlugins(object):
|
||||||
self._rabbitmq_plugins = module.get_bin_path('rabbitmq-plugins', True)
|
self._rabbitmq_plugins = module.get_bin_path('rabbitmq-plugins', True)
|
||||||
|
|
||||||
def _exec(self, args, run_in_check_mode=False):
|
def _exec(self, args, run_in_check_mode=False):
|
||||||
cmd = [self._rabbitmq_plugins]
|
if not self.module.check_mode or (self.module.check_mode and run_in_check_mode):
|
||||||
rc, out, err = self.module.run_command(cmd + args, check_rc=True)
|
cmd = [self._rabbitmq_plugins]
|
||||||
return out.splitlines()
|
rc, out, err = self.module.run_command(cmd + args, check_rc=True)
|
||||||
|
return out.splitlines()
|
||||||
|
return list()
|
||||||
|
|
||||||
def get_all(self):
|
def get_all(self):
|
||||||
return self._exec(['list', '-E', '-m'], True)
|
return self._exec(['list', '-E', '-m'], True)
|
||||||
|
|
|
@ -108,13 +108,15 @@ class RabbitMqUser(object):
|
||||||
self._permissions = None
|
self._permissions = None
|
||||||
self._rabbitmqctl = module.get_bin_path('rabbitmqctl', True)
|
self._rabbitmqctl = module.get_bin_path('rabbitmqctl', True)
|
||||||
|
|
||||||
def _exec(self, args):
|
def _exec(self, args, run_in_check_mode=False):
|
||||||
cmd = [self._rabbitmqctl, '-q']
|
if not self.module.check_mode or (self.module.check_mode and run_in_check_mode):
|
||||||
rc, out, err = self.module.run_command(cmd + args, check_rc=True)
|
cmd = [self._rabbitmqctl, '-q']
|
||||||
return out.splitlines()
|
rc, out, err = self.module.run_command(cmd + args, check_rc=True)
|
||||||
|
return out.splitlines()
|
||||||
|
return list()
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
users = self._exec(['list_users'])
|
users = self._exec(['list_users'], True)
|
||||||
|
|
||||||
for user_tag in users:
|
for user_tag in users:
|
||||||
user, tags = user_tag.split('\t')
|
user, tags = user_tag.split('\t')
|
||||||
|
@ -129,13 +131,11 @@ class RabbitMqUser(object):
|
||||||
self._tags = list()
|
self._tags = list()
|
||||||
|
|
||||||
self._permissions = self._get_permissions()
|
self._permissions = self._get_permissions()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _get_permissions(self):
|
def _get_permissions(self):
|
||||||
perms_out = self._exec(['list_user_permissions', self.username])
|
perms_out = self._exec(['list_user_permissions', self.username], True)
|
||||||
|
|
||||||
for perm in perms_out:
|
for perm in perms_out:
|
||||||
vhost, configure_priv, write_priv, read_priv = perm.split('\t')
|
vhost, configure_priv, write_priv, read_priv = perm.split('\t')
|
||||||
|
@ -145,27 +145,23 @@ class RabbitMqUser(object):
|
||||||
return dict()
|
return dict()
|
||||||
|
|
||||||
def add(self):
|
def add(self):
|
||||||
if not self.module.check_mode:
|
self._exec(['add_user', self.username, self.password])
|
||||||
self._exec(['add_user', self.username, self.password])
|
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
if not self.module.check_mode:
|
self._exec(['delete_user', self.username])
|
||||||
self._exec(['delete_user', self.username])
|
|
||||||
|
|
||||||
def set_tags(self):
|
def set_tags(self):
|
||||||
if not self.module.check_mode:
|
self._exec(['set_user_tags', self.username] + self.tags)
|
||||||
self._exec(['set_user_tags', self.username] + self.tags)
|
|
||||||
|
|
||||||
def set_permissions(self):
|
def set_permissions(self):
|
||||||
if not self.module.check_mode:
|
cmd = ['set_permissions']
|
||||||
cmd = ['set_permissions']
|
cmd.append('-p')
|
||||||
cmd.append('-p')
|
cmd.append(self.permissions['vhost'])
|
||||||
cmd.append(self.permissions['vhost'])
|
cmd.append(self.username)
|
||||||
cmd.append(self.username)
|
cmd.append(self.permissions['configure_priv'])
|
||||||
cmd.append(self.permissions['configure_priv'])
|
cmd.append(self.permissions['write_priv'])
|
||||||
cmd.append(self.permissions['write_priv'])
|
cmd.append(self.permissions['read_priv'])
|
||||||
cmd.append(self.permissions['read_priv'])
|
self._exec(cmd)
|
||||||
self._exec(cmd)
|
|
||||||
|
|
||||||
def has_tags_modifications(self):
|
def has_tags_modifications(self):
|
||||||
return set(self.tags) != set(self._tags)
|
return set(self.tags) != set(self._tags)
|
||||||
|
|
Loading…
Reference in a new issue