我在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
Run Code Online (Sandbox Code Playgroud)
所以我没有正确使用win_stat模块,
应该在我的第一个“任务”中添加register参数。
这是这样的-
- 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
Run Code Online (Sandbox Code Playgroud)
当我尝试上面的答案时,它给了我一个语法错误,而我必须这样写:
- 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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3996 次 |
| 最近记录: |