community.general.redis 查找 – 从 Redis 获取数据

注意

此查找插件是 community.general 集合(版本 10.1.0)的一部分。

如果您正在使用 ansible 包,您可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.general。您需要其他要求才能使用此查找插件,有关详细信息,请参阅要求

要在 playbook 中使用它,请指定:community.general.redis

概要

  • 此查找从 Redis 数据库返回与给定的项目列表对应的结果列表

要求

在执行此查找的本地控制器节点上需要以下要求。

术语

参数

评论

术语

列表 / 元素=字符串

要查询的键的列表

关键字参数

这描述了查找的关键字参数。这些是在以下示例中的值 key1=value1key2=value2 等等:lookup('community.general.redis', key1=value1, key2=value2, ...)query('community.general.redis', key1=value1, key2=value2, ...)

参数

评论

主机

字符串

Redis 主机的位置

默认值: "127.0.0.1"

配置

端口

整数

Redis 监听的端口

默认值: 6379

配置

套接字

路径

用于查询 Redis 的套接字路径,设置此选项后,将覆盖主机和端口选项。

配置

说明

注意

  • 当关键字和位置参数一起使用时,位置参数必须在关键字参数之前列出:lookup('community.general.redis', term1, term2, key1=value1, key2=value2)query('community.general.redis', term1, term2, key1=value1, key2=value2)

示例

- name: query redis for somekey (default or configured settings used)
  ansible.builtin.debug:
    msg: "{{ lookup('community.general.redis', 'somekey') }}"

- name: query redis for list of keys and non-default host and port
  ansible.builtin.debug:
    msg: "{{ lookup('community.general.redis', item, host='myredis.internal.com', port=2121) }}"
  loop: '{{list_of_redis_keys}}'

- name: use list directly
  ansible.builtin.debug:
    msg: "{{ lookup('community.general.redis', 'key1', 'key2', 'key3') }}"

- name: use list directly with a socket
  ansible.builtin.debug:
    msg: "{{ lookup('community.general.redis', 'key1', 'key2', socket='/var/tmp/redis.sock') }}"

返回值

描述

返回值

列表 / 元素=字符串

存储在 Redis 中的值

返回: 成功

作者

  • Jan-Piet Mens (@jpmens) <jpmens(at)gmail.com>

  • Ansible 核心团队

提示

每个条目类型的配置条目都有从低到高的优先级顺序。例如,列表中较低的变量将覆盖较高的变量。