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 数据库的结果列表 
要求
执行此查找的本地控制器节点上需要以下要求。
- redis(python 库 https://github.com/andymccurdy/redis-py/) 
术语
| 参数 | 注释 | 
|---|---|
| 要查询的键列表 | 
关键字参数
这描述了查找的关键字参数。这些值是以下示例中的 key1=value1、key2=value2 等:lookup('community.general.redis', key1=value1, key2=value2, ...) 和 query('community.general.redis', key1=value1, key2=value2, ...)
| 参数 | 注释 | 
|---|---|
| 要查询 Redis 的套接字路径,设置此选项时,它会覆盖 host 和 port 选项。 配置 
 | 
说明
注意
- 当关键字和位置参数一起使用时,位置参数必须列在关键字参数之前: - 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 中的值 返回: 成功 | 
