# Help In Understanding/Resolving Loop Variables Within include\_tasks Loops Error

**URL:** <https://forum.ansible.com/t/help-in-understanding-resolving-loop-variables-within-include-tasks-loops-error/44257>\
**Category:** Get Help\
**Tags:** include\_tasks, loop\
**Created:** [August 8, 2025, 7:39am UTC](https://forum.ansible.com/t/help-in-understanding-resolving-loop-variables-within-include-tasks-loops-error/44257 "2025-08-08T07:39:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dulux-Oz](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulux-oz/32/9047_2.png) [@Dulux-Oz](https://forum.ansible.com/u/Dulux-Oz)\
**Post date:** [August 8, 2025, 7:39am UTC](https://forum.ansible.com/t/help-in-understanding-resolving-loop-variables-within-include-tasks-loops-error/44257/1 "2025-08-08T07:39:51Z")

</div>

Hi All,

I’m having trouble sorting out the below issue, and so I’m looking for a little help. I know (actually, I suspect) that its something simple I’ve missed, but after several hours of googling, etc, I can’t work it out.

My role is (tasks/main.yml):

```auto
- name: Include Tasks
  ansible.builtin.include_tasks:
    file: "{{Task_Item}}.yml"
  loop: "{{Task_List}}"
  loop_control:
    loop_var: Task_Item

```

My vars/main.yml is:

```auto
Python_Version: 3.12.1

Task_List:
  - task_1
  - task_2

PIP_List:
  - passlib
  - proxmoxer
  - requests

```

My tasks/task\_1.yml is:

```auto
- name: Task 1 - Install Python Packages
  ansible.builtin.dnf:
    name: "{{item}}"
    state: present
  with_items:
    - "python{{Python_Version}}"
    - "python{{Python_Version}}-pip"

```

My tasks/task\_2.yml is:

```auto
- name: Task 2 - Install via PIP
  ansible.builtin.pip:
    name: "{{item}}"
    state: latest
    loop: "{{PIP_List}}"

```

The Issue:

Task 1 runs AOK, but Task 2 give the following error message (which is what I’m having trouble understanding/resolving - I mean, I unserstand what its saying, but I don’t understand _why_ its saying it ie how to resolve it):

```auto
[ERROR]: Task failed: Finalization of task args for 'ansible.builtin.pip' failed: Error while resolving value for 'name': 'item' is undefined

```

So, could someone please help educate me as to _why_ this is happening (& if a solution was included that’d be great) - thanks.

---

<div class="post-metadata">

**Author:** ![mkrizek](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mkrizek/32/2055_2.png) [@mkrizek](https://forum.ansible.com/u/mkrizek)\
**Post date:** [August 8, 2025, 8:30am UTC](https://forum.ansible.com/t/help-in-understanding-resolving-loop-variables-within-include-tasks-loops-error/44257/2 "2025-08-08T08:30:46Z")

</div>

I don’t know if it’s just incorrectly copy-pasted but the `loop`keyword in your `pip` task is indented on wrong level, it should be:

```auto
- name: Task 2 - Install via PIP
  ansible.builtin.pip:
    name: "{{item}}"
    state: latest
  loop: "{{PIP_List}}"

```

---

<div class="post-metadata">

**Author:** ![Dulux-Oz](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulux-oz/32/9047_2.png) [@Dulux-Oz](https://forum.ansible.com/u/Dulux-Oz)\
**Post date:** [August 8, 2025, 9:52am UTC](https://forum.ansible.com/t/help-in-understanding-resolving-loop-variables-within-include-tasks-loops-error/44257/3 "2025-08-08T09:52:20Z")

</div>

Thanks @mkrizek (Martin),

DOH!

Like I said, it’s something simple that I was missing.

Cheers 😄

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [September 7, 2025, 9:52am UTC](https://forum.ansible.com/t/help-in-understanding-resolving-loop-variables-within-include-tasks-loops-error/44257/4 "2025-09-07T09:52:52Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
