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

Note

This plugin is part of the community.general collection.

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 / required
    Choices:
  • config
  • flush
  • slave
The selected redis command
config (new in 1.6), ensures a configuration setting on an instance.
flush flushes all the instance or a specified db.
slave sets a redis instance in slave or master mode.
db
string
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
string
Default:
6379
The port to connect to
master_host
string
The host of the master instance [slave command]
master_port
string
The port of the master instance [slave command]
name
string
A redis config key.
slave_mode
string
    Choices:
  • master
  • slave ←
the mode of the redis instance [slave command]
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 slave 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 slave of melee.island on port 6377
  community.general.redis:
    command: slave
    master_host: melee.island
    master_port: 6377

- name: Deactivate slave mode
  community.general.redis:
    command: slave
    slave_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)