0

This my ansible script

- hosts: localhost
  tasks:
    - file:
       name: add dir
       path: /etc/ansible/roles/webservers/'{{item}}'
       state: directory
       mode: 0755
       owner: nikola
      vars:
       dir_list:
        - handlers
        - vars
        - defaults
        - meta
      with_items: ' {{ dir_list }} '

and this is the output from --check option

PLAY [localhost] ****************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [file] *********************************************************************************************************************************************************************************************************************************
ok: [localhost] => (item=handlers)
ok: [localhost] => (item=vars)
ok: [localhost] => (item=defaults)
ok: [localhost] => (item=meta)

PLAY RECAP **********************************************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0
1

You have two mistakes:

  1. name as parameter of file module. It is an alias of path, so you actually try to create directory add dir.

  2. Unnecessary single quotes in path, giving you actual paths like etc/ansible/roles/webservers/'handlers'.

Try with:

...
- name: add dir
  file:
    path: '/etc/ansible/roles/webservers/{{ item }}'
...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy