community.general.redis_data – Set key value pairs in Redis

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_data.

New in version 3.7.0: of community.general

Synopsis

  • Set key value pairs in Redis database.

Requirements

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

  • redis
  • certifi

Parameters

Parameter Choices/Defaults Comments
ca_certs
string
Path to root certificates file. If not set and tls is set to true, certifi ca-certificates will be used.
existing
boolean
    Choices:
  • no
  • yes
Only set key if it already exists.
expiration
integer
Expiration time in milliseconds. Setting this flag will always result in a change in the database.
keep_ttl
boolean
    Choices:
  • no
  • yes
Retain the time to live associated with the key.
key
string / required
Database key.
login_host
string
Default:
"localhost"
Specify the target host running the database.
login_password
string
Specify the password to authenticate with.
Usually not used when target is localhost.
login_port
integer
Default:
6379
Specify the port to connect to.
login_user
string
Specify the user to authenticate with.
Requires redis >= 3.4.0.
non_existing
boolean
    Choices:
  • no
  • yes
Only set key if it does not already exist.
state
string
    Choices:
  • present
  • absent
State of the key.
tls
boolean
    Choices:
  • no
  • yes
Specify whether or not to use TLS for the connection.
validate_certs
boolean
    Choices:
  • no
  • yes
Specify whether or not to validate TLS certificates.
This should only be turned off for personally controlled sites or with localhost as target.
value
string
Value that key should be set to.

Notes

Note

  • Requires the redis Python package on the remote host. You can install it with pip (pip install redis) or with a package manager. Information on the library can be found at https://github.com/andymccurdy/redis-py.

See Also

See also

community.general.redis_data_info

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

community.general.redis

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

Examples

- name: Set key foo=bar on localhost with no username
  community.general.redis_data:
    login_host: localhost
    login_password: supersecret
    key: foo
    value: bar
    state: present

- name: Set key foo=bar if non existing with expiration of 30s
  community.general.redis_data:
    login_host: localhost
    login_password: supersecret
    key: foo
    value: bar
    non_existing: true
    expiration: 30000
    state: present

- name: Set key foo=bar if existing and keep current TTL
  community.general.redis_data:
    login_host: localhost
    login_password: supersecret
    key: foo
    value: bar
    existing: true
    keep_ttl: true

- name: Set key foo=bar on redishost with custom ca-cert file
  community.general.redis_data:
    login_host: redishost
    login_password: supersecret
    login_user: someuser
    validate_certs: true
    ssl_ca_certs: /path/to/ca/certs
    key: foo
    value: bar

- name: Delete key foo on localhost with no username
  community.general.redis_data:
    login_host: localhost
    login_password: supersecret
    key: foo
    state: absent

Return Values

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

Key Returned Description
msg
string
always
A short message.

Sample:
Set key: foo to bar
old_value
string
on_success if state is present and key exists in database.
Value of key before setting.

Sample:
old_value_of_key
value
string
on success if state is present.
Value key was set to.

Sample:
new_value_of_key


Authors

  • Andreas Botzner (@paginabianca)

© 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_data_module.html