community.general.accumulate 过滤器 – 生成输入列表内容的累积和列表

注意

此过滤器插件是 community.general 集合(版本 10.1.0)的一部分。

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

要安装它,请使用:ansible-galaxy collection install community.general

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

community.general 10.1.0 中的新增功能

概要

  • 传递到 Python itertools.accumulate 函数

  • 将输入列表转换为将加法应用于输入列表元素的累积结果列表。

  • 加法表示输入列表元素类型的默认 Python 实现 +

输入

这描述了过滤器的输入,即 | community.general.accumulate 前面的值。

参数

注释

输入

列表 / 元素=任意 / 必需

一个列表。

示例

- name: Enumerate parent directories of some path
  ansible.builtin.debug:
    var: >
       "/some/path/to/my/file"
       | split('/') | map('split', '/')
       | community.general.accumulate | map('join', '/')
    # Produces: ['', '/some', '/some/path', '/some/path/to', '/some/path/to/my', '/some/path/to/my/file']
- name: Growing string
  ansible.builtin.debug:
    var: "'abc' | community.general.accumulate"
    # Produces ['a', 'ab', 'abc']

返回值

描述

返回值

列表 / 元素=任意

输入列表元素的累积和列表。

返回: 成功

作者

  • Max Gautier (@VannTen)

提示

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