Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible fail a playbook if directory not exist in windows

Tags:

ansible

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
like image 697
Roman Zinger Avatar asked Oct 29 '25 17:10

Roman Zinger


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
like image 66
β.εηοιτ.βε Avatar answered Nov 01 '25 13:11

β.εηοιτ.βε