The task includes an option with an undefined variable The error was item is undefined n nThe error appears to be in root haproxy user yml

0 votes

Hi Guys,

I am trying to iterate one database using the item keyword in Ansible Playbook. But it is showing me the below error.

fatal: [192.168.0.129]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'item' is undefined\n\nThe error appears to be in '/root/haproxy/user.yml': line 12, 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  - group:\n    ^ here\n"}

I am using the below playbook.

- hosts: all
  vars:
    password: "password"
    userdb:
      - name: nadim
        password: "nadim"
        group: "mygrp"
      - name: akhtar
        password: akhtar
        group: mygrp1
  tasks:
  - group:
      name: "{{ item.group }}"
      state: present
Sep 1, 2020 in Ansible by akhtar
• 38,170 points
3,130 views

1 answer to this question.

0 votes

Hi@akhtar,

You can perform iterate tasks in Ansible Playbook using the item keyword. But the Item keyword comes under the loop module. So you have to use the loop module as shown below.

- hosts: all
  vars:
    password: "password"
    userdb:
      - name: nadim
        password: "nadim"
        group: "mygrp"
      - name: akhtar
        password: akhtar
        group: mygrp1
  tasks:
  - group:
      name: "{{ item.group }}"
      state: present
    loop: "{{ userdb }}"
answered Sep 1, 2020 by MD
• 95,180 points

Related Questions In Ansible

0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
1,075 views
+2 votes
1 answer
0 votes
1 answer