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

8,042 views
Skip to first unread message

Victor Sava

unread,
Jun 27, 2018, 7:26:30 AM6/27/18
to Ansible Project
- 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?

J Hawkesworth

unread,
Jun 27, 2018, 7:42:17 AM6/27/18
to Ansible Project
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    

Bachu Prathap

unread,
Jun 27, 2018, 7:54:39 AM6/27/18
to ansible...@googlegroups.com
Hi 

Remove quotes for item under path, it should work.

Regards
Pratap Bachu 

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/437c4634-9835-4bdf-b35e-f3f6888d1452%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages