Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flatten filter does not flatten lists when chained to other filters #44327

Closed
techraf opened this issue Aug 17, 2018 · 1 comment · Fixed by #44331
Closed

flatten filter does not flatten lists when chained to other filters #44327

techraf opened this issue Aug 17, 2018 · 1 comment · Fixed by #44331
Labels
affects_2.6 This issue/PR affects Ansible v2.6 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@techraf
Copy link
Contributor

techraf commented Aug 17, 2018

SUMMARY

flatten filter does not flatten lists when chained to filters producing lists of tuples.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

flatten filter

ANSIBLE VERSION
ansible 2.6.3
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/Users/macraf/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/macraf/anaconda2/lib/python2.7/site-packages/ansible
  executable location = /Users/macraf/anaconda2/bin/ansible
  python version = 2.7.15 |Anaconda, Inc.| (default, May  1 2018, 18:37:05) [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]

(also previous versions)

CONFIGURATION
RETRY_FILES_ENABLED(/etc/ansible/ansible.cfg) = False
OS / ENVIRONMENT

N/A

STEPS TO REPRODUCE
- hosts: localhost
  connection: local
  gather_facts: no

  vars:
    my_list1: [[1,2],[3,4]]
    my_list2: "{{ [1,3] | zip([2,4]) | list }}"
    # or:
    #   my_list2: "{{ {1: 2, 3: 4} | dictsort | list }}"

  tasks:
    - set_fact:
        my_list3: "{{ my_list2 }}"
    - name: "[[1,2],[3,4]] | flatten"
      debug:
        msg: "{{ my_list1 | flatten }}"
    - name: "[1,3] | zip([2,4]) | list | flatten"
      debug:
        msg: "{{ my_list2 | flatten }}"
    - name: "[1,3] | zip([2,4]) | list <--- set_fact ---> | flatten"
      debug:
        msg: "{{ my_list3 | flatten }}"
EXPECTED RESULTS

All debug tasks returning the same flattened list.

ACTUAL RESULTS
TASK [set_fact] ********************************************************************************************************************************************************
ok: [localhost]

TASK [[[1,2],[3,4]] | flatten] *****************************************************************************************************************************************
ok: [localhost] => {
    "msg": [
        1,
        2,
        3,
        4
    ]
}

TASK [[1,3] | zip([2,4]) | list | flatten] *****************************************************************************************************************************
ok: [localhost] => {
    "msg": [
        [
            1,
            2
        ],
        [
            3,
            4
        ]
    ]
}

TASK [[1,3] | zip([2,4]) | list <--- set_fact ---> | flatten] **********************************************************************************************************
ok: [localhost] => {
    "msg": [
        1,
        2,
        3,
        4
    ]
}
@ansibot
Copy link
Contributor

ansibot commented Aug 17, 2018

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added affects_2.6 This issue/PR affects Ansible v2.6 bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Aug 17, 2018
@sivel sivel added has_pr This issue has an associated PR. and removed needs_triage Needs a first human triage before being processed. labels Aug 17, 2018
sivel added a commit to sivel/ansible that referenced this issue Aug 21, 2018
)

* Use newer is_sequence function instead of MutableSequence. Fixes ansible#44327

* Add changelog for ansible#44331

* Update changelog fragment to describe the fix in more detail
sivel added a commit to sivel/ansible that referenced this issue Aug 21, 2018
ansible#44331)

* Use newer is_sequence function instead of MutableSequence. Fixes ansible#44327

* Add changelog for ansible#44331

* Update changelog fragment to describe the fix in more detail
(cherry picked from commit 2bf6507)

Co-authored-by: Matt Martz <matt@sivel.net>
sivel added a commit to sivel/ansible that referenced this issue Aug 21, 2018
ansible#44331)

* Use newer is_sequence function instead of MutableSequence. Fixes ansible#44327

* Add changelog for ansible#44331

* Update changelog fragment to describe the fix in more detail
(cherry picked from commit 2bf6507)

Co-authored-by: Matt Martz <matt@sivel.net>
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.6 This issue/PR affects Ansible v2.6 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants