community.general.redis lookup – fetch data from Redis

Note

This lookup plugin is part of the community.general collection (version 9.5.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general. You need further requirements to be able to use this lookup plugin, see Requirements for details.

To use it in a playbook, specify: community.general.redis.

Synopsis

  • This lookup returns a list of results from a Redis DB corresponding to a list of items given to it

Requirements

The below requirements are needed on the local controller node that executes this lookup.

Terms

Parameter

Comments

Terms

list / elements=string

list of keys to query

Keyword parameters

This describes keyword parameters of the lookup. These are the values key1=value1, key2=value2 and so on in the following examples: lookup('community.general.redis', key1=value1, key2=value2, ...) and query('community.general.redis', key1=value1, key2=value2, ...)

Parameter

Comments

host

string

location of Redis host

Default: "127.0.0.1"

Configuration:

port

integer

port on which Redis is listening on

Default: 6379

Configuration:

socket

path

path to socket on which to query Redis, this option overrides host and port options when set.

Configuration:

Notes

Note

  • When keyword and positional parameters are used together, positional parameters must be listed before keyword parameters: lookup('community.general.redis', term1, term2, key1=value1, key2=value2) and query('community.general.redis', term1, term2, key1=value1, key2=value2)

Examples

- name: query redis for somekey (default or configured settings used)
  ansible.builtin.debug:
    msg: "{{ lookup('community.general.redis', 'somekey') }}"

- name: query redis for list of keys and non-default host and port
  ansible.builtin.debug:
    msg: "{{ lookup('community.general.redis', item, host='myredis.internal.com', port=2121) }}"
  loop: '{{list_of_redis_keys}}'

- name: use list directly
  ansible.builtin.debug:
    msg: "{{ lookup('community.general.redis', 'key1', 'key2', 'key3') }}"

- name: use list directly with a socket
  ansible.builtin.debug:
    msg: "{{ lookup('community.general.redis', 'key1', 'key2', socket='/var/tmp/redis.sock') }}"

Return Value

Key

Description

Return value

list / elements=string

value(s) stored in Redis

Returned: success

Authors

  • Jan-Piet Mens (@jpmens) <jpmens(at)gmail.com>

  • Ansible Core Team

Hint

Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.