Ansible Error: The task includes an option with an undefined variable. When Creating new folders

  • name: Update apt cahce
    apt: update_cache=yes cache_valid_time=3600

  • name: Install NFS Common on FileServer
    apt: name={{ item }} state=present
    with_items:

  • nfs-common

  • name: Create webservers directory
    file:
    path: “{{ item }}”
    with_items:

  • /nfs/webserver1

  • /nfs/webserver2
    state: directory

Hello guys while running this ansible playbook to create multiple folders i get error:

“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/user/.ansible/roles/mount/tasks/main.yml’: line 10, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Create webservers directory\n ^ here\n”

What i am doing wrong?

with_items isn’t a module parameter, so it needs to be indented to same level as file, like this:
`

  • name: Update apt cahce
    apt: update_cache=yes cache_valid_time=3600

  • name: Install NFS Common on FileServer
    apt: name={{ item }} state=present
    with_items:

  • nfs-common

  • name: Create webservers directory
    file:
    path: “{{ item }}”
    state: directory
    with_items:

  • /nfs/webserver1

  • /nfs/webserver2
    `

Hi

Remove quotes for item under path, it should work.

Regards
Pratap Bachu