Ansible debug msg with item.stdout not working with Ansible 2.1

Hello,

I have following playbook.

`

  • hosts: localhost
    vars:
    routes:
  • name: /blue
  • name: /green
    password: test #will be reading from inventory in original case
    gather_facts: no

tasks:

  • name: Execute manage command
    shell: ./manage.sh “{{item.name}} {{password}}”
    with_items:

  • “{{routes}}”
    no_log: true
    register: cmd_out

  • debug: msg=“item.rc={{item.rc}} item.stdout={{item.stdout}}”
    with_items: “{{ cmd_out.results }}”
    `

It is a waste of time to try to maintain compatibility between Ansible
2.ancient and 2.recent. This is not the only problem you're going to
run into, by far.

I suggest looking into shipping your customer a complete Python
virtualenv containing a current version of Ansible as well as all
dependencies. That way they can run your playbooks using a
self-contained Ansible installation (i.e., restricted to a single
directory), and the two Ansible installations will not interact in any
way, so they don't need to upgrade anything, and it will not affect
any other playbooks that they need to run under Ansible 2.1.

-- Abhijit

Hi Abhijit,

Agreed, but to tell you, its upgrade will take. We already initiated that effort but then its not straight forward considering amount of roles and plays they have and all of them needs to work well. Different version execution is also little difficult as the play orchestrated via UCD where UCD has its defined component process template. That’s the reason I am looking for a hack.

I just wanted to get a nice command output. I can get that by using

`

  • debug: msg=“item.stdout={{cmd_out.results[0].stdout}}”
  • debug: msg=“item.stdout={{cmd_out.results[1].stdout}}”

`

But then the problem is number of index can vary, so depends up on route items (based on number of items) I would be able to mark index.

If there is a quick way something like

`

  • debug: msg="item.stdout=cmd_out.results[index].stdout
    `

or with_items would work.

Thanks
Rijesh.

No problem. I found a way to get this till Ansible getting updated.

`

Assuming we support 5 routes, if this goes beyond, then it will fail. Long term solution is to get ansible upgraded and uncomment above block.

  • debug: msg=“item.stdout={{cmd_out_set.results[0].stdout}}”
    when: cmd_out_set.results|length > 0
    no_log: false
  • debug: msg=“item.stdout={{cmd_out_set.results[1].stdout}}”
    when: cmd_out_set.results|length > 1
    no_log: false
  • debug: msg=“item.stdout={{cmd_out_set.results[2].stdout}}”
    when: cmd_out_set.results|length > 2
    no_log: false
  • debug: msg=“item.stdout={{cmd_out_set.results[3].stdout}}”
    when: cmd_out_set.results|length > 3
    no_log: false
  • debug: msg=“item.stdout={{cmd_out_set.results[4].stdout}}”
    when: cmd_out_set.results|length > 4
    no_log: false

`