with_items flatten list of lists #5913

Closed
ko-zu opened this Issue Feb 8, 2014 · 4 comments

Comments

Projects
None yet
3 participants
@ko-zu

ko-zu commented Feb 8, 2014

Issue Type:

Bug Report

Ansible Version:

ansible 1.4.4

Environment:

N/A

Summary:

with_items flatten list of lists.

Steps To Reproduce:
    - debug: msg="{{ item.src }} , {{ item.dest }}"
      with_items:
        - { src: abc, dest: def }
    - debug: msg="{{ item.0 }} , {{ item.1 }}"
      with_items:
        - [abc, def]

should be identical tasks.
but later one iterates through "abc" AND "def", which prints "a , b" and "d , e".

Expected Results:

both should output msg=""abc, def"

ok: [host] => (item=[abc, def]) => {
    "item": ["abc, "def"],
    "msg": "abc , bef"
}
Actual Results:

later one iterates through "abc" and "def", which prints "a , b" and "d , e".

ok: [host] => (item=abc) => {
    "item": "abc",
    "msg": "a , b"
}
ok: [host] => (item=def) => {
    "item": "def",
    "msg": "d , e"
}
@kuba

This comment has been minimized.

Show comment
Hide comment
@kuba

kuba Feb 8, 2014

I can confirm this bug. With this playbook:

- hosts: all
  gather_facts: no
  tasks:
  - debug: var=item
    with_items:
    - ['abc', 'def']
    - ['ghi', 'jkl']

following output is produced:

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

TASK: [debug var=item] ******************************************************** 
ok: [localhost] => (item=abc) => {
    "item": "abc"
}
ok: [localhost] => (item=def) => {
    "item": "def"
}
ok: [localhost] => (item=ghi) => {
    "item": "ghi"
}
ok: [localhost] => (item=jkl) => {
    "item": "jkl"
}

PLAY RECAP ******************************************************************** 
localhost                  : ok=1    changed=0    unreachable=0    failed=0   

This happens for both:

  • 1.4.4
  • and ansible 1.5 (devel ab0adaf) last updated 2014/02/08 13:49:16 (GMT +100)

kuba commented Feb 8, 2014

I can confirm this bug. With this playbook:

- hosts: all
  gather_facts: no
  tasks:
  - debug: var=item
    with_items:
    - ['abc', 'def']
    - ['ghi', 'jkl']

following output is produced:

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

TASK: [debug var=item] ******************************************************** 
ok: [localhost] => (item=abc) => {
    "item": "abc"
}
ok: [localhost] => (item=def) => {
    "item": "def"
}
ok: [localhost] => (item=ghi) => {
    "item": "ghi"
}
ok: [localhost] => (item=jkl) => {
    "item": "jkl"
}

PLAY RECAP ******************************************************************** 
localhost                  : ok=1    changed=0    unreachable=0    failed=0   

This happens for both:

  • 1.4.4
  • and ansible 1.5 (devel ab0adaf) last updated 2014/02/08 13:49:16 (GMT +100)
@kuba

This comment has been minimized.

Show comment
Hide comment
@kuba

kuba Feb 8, 2014

This is related to 43d22b0 and #1711.

kuba commented Feb 8, 2014

This is related to 43d22b0 and #1711.

@kuba

This comment has been minimized.

Show comment
Hide comment
@kuba

kuba Feb 8, 2014

Haha, have a look at #1711 (comment) and #1711 (comment). As @mpdehaan stated: "I know it breaks that, but it is completely gross and deserves to be broken". What they didn't foresee at that point is that somebody may just have a list of lists on with_items input:

- hosts: all
  gather_facts: no
  vars:
    foo: [['abc', 'def'], ['ghi', 'jkl']]
  tasks:
  - debug: var=item
    with_items: foo

and with the same run output as I pasted above in #5913 (comment).

This is clearly a bug and IMHO 43d22b0 shall be reverted, but this might be hard as it's been like that since 1.1... However, given that now we have with_flattened (that has slightly different behaviour) maybe this odd flatten(terms) bit of code could be safely removed.

kuba commented Feb 8, 2014

Haha, have a look at #1711 (comment) and #1711 (comment). As @mpdehaan stated: "I know it breaks that, but it is completely gross and deserves to be broken". What they didn't foresee at that point is that somebody may just have a list of lists on with_items input:

- hosts: all
  gather_facts: no
  vars:
    foo: [['abc', 'def'], ['ghi', 'jkl']]
  tasks:
  - debug: var=item
    with_items: foo

and with the same run output as I pasted above in #5913 (comment).

This is clearly a bug and IMHO 43d22b0 shall be reverted, but this might be hard as it's been like that since 1.1... However, given that now we have with_flattened (that has slightly different behaviour) maybe this odd flatten(terms) bit of code could be safely removed.

@mpdehaan

This comment has been minimized.

Show comment
Hide comment
@mpdehaan

mpdehaan Feb 8, 2014

Contributor

This is intended behavior.

@kuba, Assumptions that it is "clearly a bug" are of opinion nature.

Please ask on the list if you like.

Contributor

mpdehaan commented Feb 8, 2014

This is intended behavior.

@kuba, Assumptions that it is "clearly a bug" are of opinion nature.

Please ask on the list if you like.

@mpdehaan mpdehaan closed this Feb 8, 2014

ko-zu added a commit to ko-zu/ansible that referenced this issue Feb 9, 2014

@olavph olavph referenced this issue in open-power-host-os/infrastructure Oct 30, 2017

Merged

ansible: Add role `time` #121

@dougszumski dougszumski referenced this issue in stackhpc/ansible-role-grafana-conf Jan 23, 2018

Merged

Simplify configuration of datasources #4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment