community.general.redis_data module – Set key value pairs in Redis
Note
This module is part of the community.general collection (version 10.7.5).
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 module,
see Requirements for details.
To use it in a playbook, specify: community.general.redis_data.
New in community.general 3.7.0
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 | Comments | 
|---|---|
| Path to root certificates file. If not set and  | |
| Path to the client certificate file. | |
| Path to the client private key file. | |
| Only set key if it already exists. Choices: 
 | |
| Expiration time in milliseconds. Setting this option always results in a change in the database. | |
| Retain the time to live associated with the key. Choices: 
 | |
| Database key. | |
| Specify the target host running the database. Default:  | |
| Specify the password to authenticate with. Usually not used when target is localhost. | |
| Specify the port to connect to. Default:  | |
| Specify the user to authenticate with. Requires redis >= 3.4.0. | |
| Only set key if it does not already exist. Choices: 
 | |
| State of the key. Choices: 
 | |
| Specify whether or not to use TLS for the connection. Choices: 
 | |
| Specify whether or not to validate TLS certificates. This should only be turned off for personally controlled sites or with  Choices: 
 | |
| Value that key should be set to. | 
Attributes
| Attribute | Support | Description | 
|---|---|---|
| Support: full | Can run in  | |
| Support: none | Will return details on what has changed (or possibly needs changing in  | 
Notes
Note
- Requires the - redisPython 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_incr
- Increment keys in Redis. 
- community.general.redis_data_info
- Get value of key in Redis database. 
- community.general.redis
- Various redis commands, replica and flush. 
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 | Description | 
|---|---|
| A short message. Returned: always Sample:  | |
| Value of key before setting. Returned: on_success if  Sample:  | |
