Ansible fail a playbook if directory not exist in windows

Viewed 530

How can I fail a playbook if directory in windows not exist

 - name: Obtain information about a folder
   win_stat:
     path: C:\temp
   register: file_info

 - debug:
     var: file_info
1 Answers

You can use failed_when on the task itself.

And then you can assess the existence of the folder based on stat.exists.

- name: Obtain information about a folder
  win_stat:
    path: C:\temp
  register: file_info
  failed_when: not file_info.stat.exists
Related