community.general.dict_kv 过滤器 – 将值转换为具有单个键值对的字典
注意
此过滤器插件是 community.general 集合 (版本 10.1.0) 的一部分。
如果您正在使用 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用: ansible-galaxy collection install community.general。
要在剧本中使用它,请指定: community.general.dict_kv。
community.general 1.3.0 中的新增功能
概要
- 将值转换为具有单个键值对的字典。 
输入
这描述了过滤器的输入,即 | community.general.dict_kv 之前的值。
| 参数 | 注释 | 
|---|---|
| 单个键值对的值。 | 
位置参数
这描述了过滤器的 位置参数。这些是在以下示例中的 positional1、positional2 等值:input | community.general.dict_kv(positional1, positional2, ...)
| 参数 | 注释 | 
|---|---|
| 单个键值对的键。 | 
示例
- name: Create a one-element dictionary from a value
  ansible.builtin.debug:
    msg: "{{ 'myvalue' | dict_kv('mykey') }}"
    # Produces the dictionary {'mykey': 'myvalue'}
返回值
| 键 | 描述 | 
|---|---|
| 具有单个键值对的字典。 返回:成功 | 
