Debug module throwing error when used with loopd

fatal: [localhost]: FAILED! => {“msg”: “The task includes an option with an undefined variable. The error was: ‘item’ is undefined\n\nThe error appears to have been in ‘/home/amit/playbooks/web/user.yml’: line 8, column 9, 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: create users\n ^ here\n”}

If I comment debug module and its attribute. The playbook works. Here is the play.


  • name: create user
    hosts: localhost
    become: true
    become_user: root
    become_method: sudo
    tasks:
    - name: create users
    user:
    name: “{{ item.name }}”
    state: present
    - debug:
    var: “{{ item.message }}”
    with_items:
    - { name: amit, message: amit_done }
    - { name: ankit, message: ankit_done }

sorted. You cannot use loop through more than task in a playbook. Label could be used if you wish to display that message.


  • name: create user
    hosts: localhost
    become: true
    become_user: root
    become_method: sudo
    tasks:
    - name: create users
    user:
    name: “{{ item }}”
    state: present
    with_items:
    - amit
    - ankit
    loop:control:
    label: “{{ item }}”_done