# item variable not defined loop does not work well with stdout\_lines

**URL:** <https://forum.ansible.com/t/item-variable-not-defined-loop-does-not-work-well-with-stdout-lines/38057>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [June 4, 2023, 8:02pm UTC](https://forum.ansible.com/t/item-variable-not-defined-loop-does-not-work-well-with-stdout-lines/38057 "2023-06-04T20:02:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [June 4, 2023, 8:02pm UTC](https://forum.ansible.com/t/item-variable-not-defined-loop-does-not-work-well-with-stdout-lines/38057/1 "2023-06-04T20:02:04Z")

</div>

The inconsistencies in your indentation lead me to suspect you are withholding evidence. 🙂 Assuming your code is this:

```auto
<b>- name: check previous kafka broker server.properties
  shell: "ps -ef | grep -i kafka | grep -i server.properties | awk '{print $NF}'"
  register: serverfile
  tags:
    - upgrade
    - upgrade12

- name: debug grepout
  set_fact:
    srvfilepath: "{{ item }}"
  loop: "{{ serverfile.stdout_lines }}"
  when: "'server' in item"
  tags:
    - upgrade
    - upgrade12

- name: get the interbroker and messge format version details if set
  shell: 'grep -e inter.broker.protocol.version -e log.message.format.version {{srvfilepath}}'
  register: regintbrkpt
  tags:
    - upgrade12

- name: display interbroker version
  debug:
    msg: "{{ item }}"
  loop:
    - "{{regintbrkpt.stdout_lines}}"
  tags:
    - upgrade12</b>

```

Because the “ **display interbroker version** ” task is claiming **item** is undefined, then the previous task is not registering anything containing **stdout\_lines**. I would not be surprised to find the poorly named “ **debug grepout** ” task is not finding ‘ **server** ’ in the expected output from the first task, possibly because the shell pipeline isn’t producing what you expect.

Suggestions:

- Run with **-vv** until this is working reliably.
- Insert debug tasks after every task that registers to ensure the data you are passing to subsequent tasks is what you expect.
- Consider using **pgrep -f -a kafka** and **grep -o** with to extract relevant data from existing processes command lines.

Good luck; let us know what you find.
