How to check if a file exists in unencrypted windows?
I am using Ansible for windows and I have to check if the file exists in C: \ Temp . If the file doesn't exist, I must skip the task. I am trying to use the win_stat module and this is what I have, which is not working:
- name: Check that the ABC.txt exists
win_stat:
path: 'C:\ABC.txt '
- name: Create DEF.txt file if ABC.txt exists
win_file:
path: 'C:\DEF.txt'
state: touch
when: stat_file.stat.exists == True
+3
source to share
1 answer
So, I have not used the win_stat module ,
Should add register argument to my first "task".
This is how it works -
- name: Check that the ABC.txt exists
win_stat: path= 'C:\ABC.txt'
register: stat_file
- name: Create DEF.txt file if ABC.txt exists
win_file:
path: 'C:\DEF.txt'
state: touch
when: stat_file.stat.exists == True
+4
source to share