with_items loops saying item undefined even if its present in parameter

39 views
Skip to first unread message

Sameer Modak

unread,
Aug 21, 2017, 11:29:38 AM8/21/17
to Ansible Project
 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", repo: "/etc/yum.repos.d/epel.repo" }
      - { href: "http://rpms.famillecollet.com/enterprise/remi-release-7.rpm", repo: "/etc/yum.repos.d/remi.repo" }
========================

We are getting below error, cant understand whats the issue
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  - name: \"install EPEL and Remi reps\"\n    ^ here\n"}
fatal: [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 undefi


Kai Stian Olstad

unread,
Aug 21, 2017, 12:47:13 PM8/21/17
to ansible...@googlegroups.com
On 21. aug. 2017 17:29, Sameer Modak wrote:
> 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",
> repo: "/etc/yum.repos.d/epel.repo" }
> - { href:
> "http://rpms.famillecollet.com/enterprise/remi-release-7.rpm", repo:
> "/etc/yum.repos.d/remi.repo" }
> ========================

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.


--
Kai Stian Olstad
Message has been deleted

Sameer Modak

unread,
Aug 22, 2017, 10:55:11 AM8/22/17
to Ansible Project, ansible-pr...@olstad.com
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:
repo: "/etc/yum.repos.d/epel.repo" }
      - { href:
"/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

Kai Stian Olstad

unread,
Aug 22, 2017, 11:11:30 AM8/22/17
to ansible...@googlegroups.com
On 22. aug. 2017 16:55, Sameer Modak wrote:
> No its still the same,

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


> - 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",
> repo: "/etc/yum.repos.d/epel.repo" }
> - { href:
> "http://rpms.famillecollet.com/enterprise/remi-release-7.rpm", 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"
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",
repo: "/etc/yum.repos.d/epel.repo" }
- { href:
"http://rpms.famillecollet.com/enterprise/remi-release-7.rpm", repo:
"/etc/yum.repos.d/remi.repo" }


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages