community.general.redis_data (8.5.0) — module

Set key value pairs in Redis

| "added in version" 3.7.0 of community.general"

Authors: Andreas Botzner (@paginabianca)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

Set key value pairs in Redis database.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Delete key foo on localhost with no username
  community.general.redis_data:
    login_host: localhost
    login_password: supersecret
    key: foo
    state: absent

Inputs

    
key:
    description:
    - Database key.
    required: true
    type: str

tls:
    default: true
    description:
    - Specify whether or not to use TLS for the connection.
    type: bool

state:
    choices:
    - present
    - absent
    default: present
    description:
    - State of the key.
    type: str

value:
    description:
    - Value that key should be set to.
    required: false
    type: str

ca_certs:
    description:
    - Path to root certificates file. If not set and O(tls) is set to V(true), certifi
      ca-certificates will be used.
    type: str

existing:
    description:
    - Only set key if it already exists.
    required: false
    type: bool

keep_ttl:
    description:
    - Retain the time to live associated with the key.
    required: false
    type: bool

expiration:
    description:
    - Expiration time in milliseconds. Setting this flag will always result in a change
      in the database.
    required: false
    type: int

login_host:
    default: localhost
    description:
    - Specify the target host running the database.
    type: str

login_port:
    default: 6379
    description:
    - Specify the port to connect to.
    type: int

login_user:
    description:
    - Specify the user to authenticate with.
    - Requires L(redis,https://pypi.org/project/redis) >= 3.4.0.
    type: str

non_existing:
    description:
    - Only set key if it does not already exist.
    required: false
    type: bool

login_password:
    description:
    - Specify the password to authenticate with.
    - Usually not used when target is localhost.
    type: str

validate_certs:
    default: true
    description:
    - Specify whether or not to validate TLS certificates.
    - This should only be turned off for personally controlled sites or with C(localhost)
      as target.
    type: bool

Outputs

msg:
  description: A short message.
  returned: always
  sample: 'Set key: foo to bar'
  type: str
old_value:
  description: Value of key before setting.
  returned: on_success if O(state=present) and key exists in database.
  sample: old_value_of_key
  type: str
value:
  description: Value key was set to.
  returned: on success if O(state=present).
  sample: new_value_of_key
  type: str

See also