如何检查文件是否存在于安全的窗口中?

问题描述:

我在Windows上使用Ansible,我必须检查文件是否存在C:\ Temp。 如果该文件不存在,那么我必须跳过该任务。我试图使用win_stat模块,这是我这不工作:如何检查文件是否存在于安全的窗口中?

- 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 
+0

请解释一下什么是“*不*工作”的意思。也从'path'参数中删除引号。 – techraf

所以我没有使用win_stat模块正确,

应该补充的在我的第一个“任务”中注册参数。

这是怎么工程─

- 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