我需要在未知目录位置找到文件并删除它们.试图使用"查找"模块,注册其输出,并将其传递给"文件".
即使我看到注册路径,我也不能在以后使用它:
< TASK [print find_result] >
ok: [1.2.3.4] => {
"find_result": {
"changed": false,
"examined": 3119,
"files": [
{
"atime": 1483973253.7295375,
...
"mode": "0600",
"mtime": 1483973253.7295375,
"nlink": 1,
"path": "/tmp/delme",
Run Code Online (Sandbox Code Playgroud)
我的剧本是:
- hosts: "{{ target }}"
become: no
vars:
find_what: "delme*"
find_where: "/tmp"
tasks:
- name: finding files
find:
paths: "{{ find_where }}"
patterns: "{{ find_what }}"
recurse: "yes"
file_type: "file"
register: find_result
# \/ for debugging
- name: print find_result
debug: var=find_result
- name: remove files
file:
path= "{{ item.path }}"
state=absent
with_items: "{{ find_result.files }}"
Run Code Online (Sandbox Code Playgroud)
Kon*_*rov 11
在file任务之后存在语法缺陷- 空间之后=.
尝试:
- name: remove files
file:
path: "{{ item.path }}"
state: absent
with_items: "{{ find_result.files }}"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24604 次 |
| 最近记录: |