Ansible windows issue about running yml task

Hi Friends ,

When I tried to run any .yml task on the Ansible , I get following error ;

My Syntax is here ,

- name: Create directory structure
  win_file:
    path: C:\Temp\folder\subfolder
    state: directory

ERROR! ‘win_file’ is not a valid attribute for a Play

The error appears to have been in ‘/etc/ansible/create.yml’: line 1, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  • name: Create directory structure
    ^ here

Any ideal ?

You don’t have whitespace right, which Ansible is very finicky about.
Try:

  • name: Create directory structure
    win_file:
    path: C:\Temp\folder\subfolder
    state: directory

Don’t use “tab” keys, use your space bar.

HTH,
Larry

This is one of my plays.

  • name: Make Tools folder

win_file:

path: C:\Tools

state: directory

  • name: Make build folder

win_file:

path: C:\build

state: directory

  • name: Make TEMP folder

win_file:

path: C:\TEMP

state: directory

  • name: Make log folder inside of temp

win_file:

path: C:\TEMP\log

state: directory

do you have “tasks:” defined before your win_file?

try this

  • hosts: all
    tasks:
  • name: Create directory structure
    win_file:
    path: C:\Temp\folder\subfolder
    state: directory

Yep, the post above is your problem, you are trying to run a list of tasks under ansible-playbook when you need to structure it like a play. When referring to roles you can just have the tasks but the root playbook must include things like hosts, tasks, roles and so on as the root keys.

Thanks

Jordan