# with\_items loops saying item undefined even if its present in parameter

**URL:** <https://forum.ansible.com/t/with-items-loops-saying-item-undefined-even-if-its-present-in-parameter/25297>\
**Category:** Ansible Project\
**Created:** [August 21, 2017, 3:29pm UTC](https://forum.ansible.com/t/with-items-loops-saying-item-undefined-even-if-its-present-in-parameter/25297 "2017-08-21T15:29:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sameer\_Modak](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sameer_modak/32/5180_2.png) [@Sameer\_Modak](https://forum.ansible.com/u/Sameer_Modak)\
**Post date:** [August 21, 2017, 3:29pm UTC](https://forum.ansible.com/t/with-items-loops-saying-item-undefined-even-if-its-present-in-parameter/25297/1 "2017-08-21T15:29:38Z")

</div>

hosts: all  
tasks:

- name: “install EPEL and Remi reps”  
yum\_repository:  
name: “{{ item.href }}”  
basurl: “{{ item.repo }}”  
with\_items:
- { href: “[http://dl.fedoraproject.org/pub/epel/7/x86\_64/e/epel-release-7-5.noarch.rpm](http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm)”, repo: “/etc/yum.repos.d/epel.repo” }
- { href: “[http://rpms.famillecollet.com/enterprise/remi-release-7.rpm](http://rpms.famillecollet.com/enterprise/remi-release-7.rpm)”, repo: “/etc/yum.repos.d/remi.repo” }

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 21, 2017, 4:46pm UTC](https://forum.ansible.com/t/with-items-loops-saying-item-undefined-even-if-its-present-in-parameter/25297/2 "2017-08-21T16:46:46Z")

</div>

You indentation on with\_items is wrong.  
with\_items is a property for the task and not yum\_repository, so indentation should be at the same level as name and yum\_repository.

---

<div class="post-metadata">

**Author:** ![Sameer\_Modak](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sameer_modak/32/5180_2.png) [@Sameer\_Modak](https://forum.ansible.com/u/Sameer_Modak)\
**Post date:** [August 22, 2017, 2:55pm UTC](https://forum.ansible.com/t/with-items-loops-saying-item-undefined-even-if-its-present-in-parameter/25297/3 "2017-08-22T14:55:11Z")

</div>

No its still the same,

- hosts: all  
tasks:
- name: “install EPEL and Remi reps”  
yum\_repository:  
name: “{{ item.href }}”  
basurl: “{{ item.repo }}”  
with\_items:
- { href:  
“[http://dl.fedoraproject.org/pub/epel/7/x86\_64/e/epel-release-7-5.noarch.rpm](http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm)”,  
repo: “/etc/yum.repos.d/epel.repo” }
- { href:  
“[http://rpms.famillecollet.com/enterprise/remi-release-7.rpm](http://rpms.famillecollet.com/enterprise/remi-release-7.rpm)”, repo:  
“/etc/yum.repos.d/remi.repo” }

=========samer error

atal: [192.168.211.129]: FAILED! =\> {“failed”: true, “msg”: “the field ‘args’ has an invalid value, which appears to include a variable that is undefined. The error was: ‘item’ is undefined\n\nThe error appears to have been in ‘/etc/ansible/lamp.yml’: line 3, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: "install EPEL and Remi reps"\n ^ here\n”}  
fatal: [192.168.211.130]: FAILED! =\> {“failed”: true, “msg”: “the field ‘args’ has an invalid value, which appears to include a variable that is undefined. The error was: ‘item’ is undefined\n\nThe error appears to have been in ‘/etc/ansible/lamp.yml’: line 3, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: "install EPEL and Remi reps"\n ^ here\n”}  
fatal: [192.168.211.131]: FAILED! =\> {“failed”: true, “msg”: "the field ‘args’ has an invalid value, which appears to include a variable that is undefined. The error was: ‘item’ is undefined\n\nThe error appears to have been in ‘/etc/ansible/lamp.yml’: line 3, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - nam

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 22, 2017, 3:10pm UTC](https://forum.ansible.com/t/with-items-loops-saying-item-undefined-even-if-its-present-in-parameter/25297/4 "2017-08-22T15:10:46Z")

</div>

> No its still the same,

That's as expected, you with\_items indentation is exactly the same as your previous mail.

> - hosts: all  
> &nbsp;&nbsp;tasks:  
> &nbsp;&nbsp;- name: "install EPEL and Remi reps"  
> &nbsp;&nbsp;&nbsp;&nbsp;yum\_repository:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: "{{ item.href }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;basurl: "{{ item.repo }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_items:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- { href:  
> "[http://dl.fedoraproject.org/pub/epel/7/x86\_64/e/epel-release-7-5.noarch.rpm&quot;](http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm&quot;),  
> repo: "/etc/yum.repos.d/epel.repo" }  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- { href:  
> "[http://rpms.famillecollet.com/enterprise/remi-release-7.rpm&quot;](http://rpms.famillecollet.com/enterprise/remi-release-7.rpm&quot;), repo:  
> "/etc/yum.repos.d/remi.repo" }

Your with\_items: is indented too fare, remove 2 space in front of it.

- name: "install EPEL and Remi reps"  
&nbsp;&nbsp;&nbsp;yum\_repository:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: "{{ item.href }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;basurl: "{{ item.repo }}"  
&nbsp;&nbsp;&nbsp;with\_items:  
&nbsp;&nbsp;&nbsp;- { href: "[http://dl.fedoraproject.org/pub/epel/7/x86\_64/e/epel-release-7-5.noarch.rpm&quot;](http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm&quot;), repo: "/etc/yum.repos.d/epel.repo" }  
&nbsp;&nbsp;&nbsp;- { href: "[http://rpms.famillecollet.com/enterprise/remi-release-7.rpm&quot;](http://rpms.famillecollet.com/enterprise/remi-release-7.rpm&quot;), repo: "/etc/yum.repos.d/remi.repo" }
