community.general.redis – fetch data from Redis

Note

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

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.

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.

Parameters

Parameter

Comments

_terms

string

list of keys to query

host

string

location of Redis host

Default: “127.0.0.1”

Configuration:

  • INI entry:

    [lookup_redis]
    host = 127.0.0.1
    
  • Environment variable: ANSIBLE_REDIS_HOST

port

integer

port on which Redis is listening on

Default: 6379

Configuration:

  • INI entry:

    [lookup_redis]
    port = 6379
    
  • Environment variable: ANSIBLE_REDIS_PORT

socket

path

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

Configuration:

  • INI entry:

    [lookup_redis]
    socket = None
    
  • Environment variable: ANSIBLE_REDIS_SOCKET

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 Values

Common return values are documented here, the following are the fields unique to this lookup:

Key

Description

_raw

list / elements=string

value(s) stored in Redis

Returned: success

Authors

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

  • Ansible Core Team