community.general.redis – Various redis commands, replica and flush

Note

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

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

  • Unified utility to interact with redis instances.

Requirements

The below requirements are needed on the host that executes this module.

  • redis

Parameters

Parameter Choices/Defaults Comments
command
string
    Choices:
  • config
  • flush
  • replica
  • slave
The selected redis command
config ensures a configuration setting on an instance.
flush flushes all the instance or a specified db.
replica sets a redis instance in replica or master mode. (slave is an alias for replica.)
db
integer
The database to flush (used in db mode) [flush command]
flush_mode
string
    Choices:
  • all
  • db
Type of flush (all the dbs in a redis instance or a specific one) [flush command]
login_host
string
Default:
"localhost"
The host running the database
login_password
string
The password used to authenticate with (usually not used)
login_port
integer
Default:
6379
The port to connect to
master_host
string
The host of the master instance [replica command]
master_port
integer
The port of the master instance [replica command]
name
string
A redis config key.
replica_mode
string
    Choices:
  • master
  • replica
  • slave
The mode of the redis instance [replica command]
slave is an alias for replica.

aliases: slave_mode
value
string
A redis config value. When memory size is needed, it is possible to specify it in the usal form of 1KB, 2M, 400MB where the base is 1024. Units are case insensitive i.e. 1m = 1mb = 1M = 1MB.

Notes

Note

  • Requires the redis-py Python package on the remote host. You can install it with pip (pip install redis) or with a package manager. https://github.com/andymccurdy/redis-py
  • If the redis master instance we are making replica of is password protected this needs to be in the redis.conf in the masterauth variable

See Also

See also

community.general.redis_info

The official documentation on the community.general.redis_info module.

Examples

- name: Set local redis instance to be a replica of melee.island on port 6377
  community.general.redis:
    command: replica
    master_host: melee.island
    master_port: 6377

- name: Deactivate replica mode
  community.general.redis:
    command: replica
    replica_mode: master

- name: Flush all the redis db
  community.general.redis:
    command: flush
    flush_mode: all

- name: Flush only one db in a redis instance
  community.general.redis:
    command: flush
    db: 1
    flush_mode: db

- name: Configure local redis to have 10000 max clients
  community.general.redis:
    command: config
    name: maxclients
    value: 10000

- name: Configure local redis maxmemory to 4GB
  community.general.redis:
    command: config
    name: maxmemory
    value: 4GB

- name: Configure local redis to have lua time limit of 100 ms
  community.general.redis:
    command: config
    name: lua-time-limit
    value: 100

Authors

  • Xabier Larrakoetxea (@slok)

© 2012–2018 Michael DeHaan
© 2018–2021 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/collections/community/general/redis_module.html