Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(redis_info): add option to fetch cluster info #8464

Merged
merged 4 commits into from
Jun 12, 2024
Merged
Changes from 1 commit
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
Next Next commit
feat(redis_info): add option to fetch cluster info
  • Loading branch information
tyxieblub committed Jun 4, 2024
commit d91f7abc1195a2cbf23f9d186b5f5b52b468bc3c
46 changes: 44 additions & 2 deletions plugins/modules/redis_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
version_added: 7.5.0
ca_certs:
version_added: 7.5.0
cluster:
default: false
description: Get informations about cluster status
tyxieblub marked this conversation as resolved.
Show resolved Hide resolved
type: bool
version_added: 9.1.0
seealso:
- module: community.general.redis
author: "Pavlo Bashynskyi (@levonet)"
Expand All @@ -43,6 +48,15 @@
- name: Print server information
ansible.builtin.debug:
var: result.info

- name: Get server cluster information
community.general.redis_info:
cluster: true
register: result

- name: Print server cluster information
ansible.builtin.debug:
var: result.cluster_info
'''

RETURN = r'''
Expand Down Expand Up @@ -178,6 +192,24 @@
"used_memory_scripts_human": "0B",
"used_memory_startup": 791264
}
cluster:
description: The default set of cluster information sections U(https://redis.io/commands/cluster-info).
returned: success
tyxieblub marked this conversation as resolved.
Show resolved Hide resolved
type: dict
sample: {
"cluster_state": ok,
"cluster_slots_assigned": 16384,
"cluster_slots_ok": 16384,
"cluster_slots_pfail": 0,
"cluster_slots_fail": 0,
"cluster_known_nodes": 6,
"cluster_size": 3,
"cluster_current_epoch": 6,
"cluster_my_epoch": 2,
"cluster_stats_messages_sent": 1483972,
"cluster_stats_messages_received": 1483968,
"total_cluster_links_buffer_limit_exceeded": 0
}
'''

import traceback
Expand All @@ -202,14 +234,19 @@ def redis_client(**client_params):

# Module execution.
def main():
module_args = dict(
cluster=dict(type='bool', default=False)
tyxieblub marked this conversation as resolved.
Show resolved Hide resolved
)
module_args.update(redis_auth_argument_spec(tls_default=False))
module = AnsibleModule(
argument_spec=redis_auth_argument_spec(tls_default=False),
argument_spec=module_args,
supports_check_mode=True,
)

fail_imports(module, module.params['tls'])

redis_params = redis_auth_params(module)
cluster = module.params['cluster']

# Connect and check
client = redis_client(**redis_params)
Expand All @@ -219,7 +256,12 @@ def main():
module.fail_json(msg="unable to connect to database: %s" % to_native(e), exception=traceback.format_exc())

info = client.info()
module.exit_json(changed=False, info=info)

cluster_info = dict()
if cluster:
cluster_info = client.execute_command('CLUSTER INFO')

module.exit_json(changed=False, info=info, cluster_info=cluster_info)
tyxieblub marked this conversation as resolved.
Show resolved Hide resolved


if __name__ == '__main__':
Expand Down
Loading