community.general.accumulate filter – Produce a list of accumulated sums of the input list contents

Note

This filter plugin is part of the community.general collection (version 10.1.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general.

To use it in a playbook, specify: community.general.accumulate.

New in community.general 10.1.0

Synopsis

  • Passthrough to the Python itertools.accumulate function.

  • Transforms an input list into the cumulative list of results from applying addition to the elements of the input list.

  • Addition means the default Python implementation of + for input list elements type.

Input

This describes the input of the filter, the value before | community.general.accumulate.

Parameter

Comments

Input

list / elements=any / required

A list.

Examples

- 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']

Return Value

Key

Description

Return value

list / elements=any

A list of cumulated sums of the elements of the input list.

Returned: success

Authors

  • Max Gautier (@VannTen)

Hint

Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.