Ansible stdout from item collected with loop

ansibleansible-playbookjson

Im trying to print stdout of registred items according to documentation documentation. Here is my yaml file:

- name: network-check
  tags: stats
  shell: "tail -n 3 {{ ansible_facts['nodename'] }}_{{ item }}.out | awk '/Mbits/ { sum += $7; n++} END { print sum / n }'"
  loop: "{{ groups['all'] }}"
  when: ansible_facts['nodename'] != item
  register: check

- name: network-check
  tags: stats
  shell: "echo {{ item.stdout }}"
  loop: "{{ check.results }}"

And im still getting "stdout atribute" error like below:

TASK [pretests : network-stat] ***************************************************************************************************************************************************************************************************************************************************************************************************************
fatal: [card-kub000]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'stdout'\n\nThe error appears to have been in '/home/holo/cardinality/source/sysop/ansible/roles/pretests/tasks/main.yaml': line 21, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: network-stat\n  ^ here\n"}

What am i doing wrong?

Here is how my output for:

- debug: msg="{{ item.item }}"
  loop: "{{ check.results }}"

looks like

ok: [card-kub000] => (item={'changed': True, 'end': '2019-01-31 00:36:50.479743', 'stdout': '128', 'cmd': "tail -n 3 card-kub000_card-kub004.out | awk '/Mbits/ { sum += $7; n++} END { print sum / n }'", 'rc': 0, 'start': '2019-01-31 00:36:50.470371', 'stderr': '', 'delta': '0:00:00.009372', 'invocation': {'module_args': {'creates': None, 'executable': None, '_uses_shell': True, '_raw_params': "tail -n 3 card-kub000_card-kub004.out | awk '/Mbits/ { sum += $7; n++} END { print sum / n }'", 'removes': None, 'argv': None, 'warn': True, 'chdir': None, 'stdin': None}}, '_ansible_parsed': True, 'stdout_lines': ['128'], 'stderr_lines': [], '_ansible_no_log': False, 'failed': False, 'item': 'card-kub004', '_ansible_item_result': True, '_ansible_ignore_errors': None, '_ansible_item_label': 'card-kub004'}) => {
    "msg": "card-kub004"

Best Answer

I finally find out where problem was. I have condition "when" which is telling ansible to skip some items if its same as nodename, because of that first item did not have stdout field. I added condition to check if item is not skiped and it start working.

- name: network-check
  tags: stats
  shell: "echo {{ item.stdout }}"
  loop: "{{ check.results }}"
  when: item.changed != False