0
我有我的Ansible播放下面的調試輸出,我試圖在「路徑」提取文件名,我想從遠程複製它們(多個文件)到本地機器。但我失敗了,細節如下。Ansible:通過調試提取文件名
ok: [environment_1] => {
"changed": false,
"examined": 42,
"files": [
{
"atime": 1506085793.8824277,
"ctime": 1506085493.1115315,
"dev": 64771,
"gid": 0,
"inode": 41,
"isblk": false,
"ischr": false,
"isdir": false,
"isfifo": false,
"isgid": false,
"islnk": false,
"isreg": true,
"issock": false,
"isuid": false,
"mode": "0644",
"mtime": 1506085398.274815,
"nlink": 1,
"path": "/tmp/env1_2017-09-22_command_output.txt",
"rgrp": true,
"roth": true,
"rusr": true,
"size": 70728,
"uid": 0,
"wgrp": false,
"woth": false,
"wusr": true,
"xgrp": false,
"xoth": false,
"xusr": false
},
{
"atime": 1506085725.0863488,
"ctime": 1506085718.8424354,
"dev": 64771,
"gid": 0,
"inode": 40,
"isblk": false,
"ischr": false,
"isdir": false,
"isfifo": false,
"isgid": false,
"islnk": false,
"isreg": true,
"issock": false,
"isuid": false,
"mode": "0644",
"mtime": 1506085636.4565618,
"nlink": 1,
"path": "/tmp/env2_2017-09-22_command_output.txt",
"rgrp": true,
"roth": true,
"rusr": true,
"size": 70952,
"uid": 0,
"wgrp": false,
"woth": false,
"wusr": true,
"xgrp": false,
"xoth": false,
"xusr": false
}
],
"invocation": {
"module_args": {
"age": null,
"age_stamp": "mtime",
"contains": null,
"file_type": "file",
"follow": false,
"get_checksum": false,
"hidden": false,
"path": "/tmp",
"paths": [
"/tmp"
],
"patterns": [
"*command_output.txt"
],
"recurse": false,
"size": null,
"use_regex": false
}
},
"matched": 2,
"msg": ""
}
有沒有什麼辦法可以提取"path": "/tmp/env2_2017-09-22_command_output.txt" ""path": "/tmp/env2_2017-09-22_command_output.txt"
,這樣我就可以使用讀取模塊將它們從遠程計算機複製到本地機器。
現在我的戲看起來像下面
---
- name: find the file in the temp location
find:
path: /tmp
patterns: '*command_output.txt'
register: path_name
- debug: msg={{ path_name.files.0.path }}
- fetch:
src: "{{ item }}"
dest: ./environment_1/
flat: yes
with_items:
- "path_name.files.0.path"
- "path_name.files.1.path"
和我得到以下錯誤
{
changed": false,
"file": "path_name.files.1.path",
"item": "path_name.files.1.path",
"msg": "the remote file does not exist, not transferring, ignored"
}
請幫助我瞭解我的錯誤。