Skip to content

loop_control.label will not be considered #34

@rguhr

Description

@rguhr

The default behavior of Ansible is that you see the entire content of a loop element. This can be a lot and impractical. You can use loop_control.label to change what should be displayed. But dump_loop_items ignores the option and dumps the entire loop element.

Example:

---
- hosts: all
  connection: local
  gather_facts: false

  tasks:
    - set_fact:
        myvar: "{{ item }}"
      loop: 
        - name: aaa
        - name: bbb
        - name: ccc
      loop_control:
        extended: true
        extended_allitems: false
        label: "({{ ansible_loop.index }}/{{ ansible_loop.length }}) {{ item.name }}"

Plain Ansible output:

ansible-playbook test.yml -i localhost,

PLAY [all] *********************************************************************

TASK [set_fact] ****************************************************************
ok: [localhost] => (item=(1/3) aaa)
ok: [localhost] => (item=(2/3) bbb)
ok: [localhost] => (item=(3/3) ccc)

anstomlog (w/ dump_loop_items) output

ansible-playbook test.yml -i localhost,
[03:36:25] set_fact
localhost | SUCCESS - item={'ansible_facts': {'myvar': {'name': 'aaa'}}, 'item': {'name': 'aaa'}, 'ansible_loop': {'index': 1, 'index0': 0, 'first': True, 'last': False, 'length': 3, 'revindex': 3, 'revindex0': 2, 'nextitem': {'name': 'bbb'}}} | 30ms
localhost | SUCCESS - item={'ansible_facts': {'myvar': {'name': 'bbb'}}, 'item': {'name': 'bbb'}, 'ansible_loop': {'index': 2, 'index0': 1, 'first': False, 'last': False, 'length': 3, 'revindex': 2, 'revindex0': 1, 'nextitem': {'name': 'ccc'}, 'previtem': {'name': 'aaa'}}} | 30ms
localhost | SUCCESS - item={'ansible_facts': {'myvar': {'name': 'ccc'}}, 'item': {'name': 'ccc'}, 'ansible_loop': {'index': 3, 'index0': 2, 'first': False, 'last': True, 'length': 3, 'revindex': 1, 'revindex0': 0, 'previtem': {'name': 'bbb'}}} | 30ms

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions