【发布时间】:2019-08-15 10:48:06
【问题描述】:
我有以下情况,有一些目录通过列表接收,例如:
目录: - /path/to/dir1 - /path/to/dir2 - /path/to/dir3
我的目标是使用 find 模块获取这些目录的扩展名为 .sh 的文件并设置 +x 权限,当我注册 find 命令时,会收到如下输出:
[查看代码]
正如所见,文件是一个元组,然后为了加入第一个索引,我可以使用这个变量:
item.files.0.path
但是有可能为了目录的大小更大,我如何使用 with_items 加入所有索引?
非常感谢。 最好的问候
"results": [
{
"ansible_loop_var": "item",
"changed": false,
"examined": 2,
"failed": false,
"files": [
{
..
"path": "/path/to/dir1/ficheros20.txt",
..
},
{
..
"path": "/path/to/dir1/ficheros20.txt",
..
}
],
"invocation": {
"module_args": {
"age": null,
"age_stamp": "mtime",
"contains": null,
"depth": null,
"excludes": null,
"file_type": "file",
"follow": false,
"get_checksum": false,
"hidden": false,
"path": "/path/to/dir1/",
"paths": [
"/path/to/dir1/"
],
"patterns": [
"*"
],
"recurse": false,
"size": null,
"use_regex": false
}
},
"item": "/path/to/dir1/",
"matched": 2,
"msg": ""
},
{
"ansible_loop_var": "item",
"changed": false,
"examined": 2,
"failed": false,
"files": [
{
..
"path": "/path/to/dir2/ficheros20.txt",
..
},
{
..
"path": "/path/to/dir2/ficheros20.txt",
..
}
],
"invocation": {
"module_args": {
"age": null,
"age_stamp": "mtime",
"contains": null,
"depth": null,
"excludes": null,
"file_type": "file",
"follow": false,
"get_checksum": false,
"hidden": false,
"path": "/path/to/dir2/",
"paths": [
"/path/to/dir2/"
],
"patterns": [
"*"
],
"recurse": false,
"size": null,
"use_regex": false
}
},
"item": "/path/to/dir2/",
"matched": 2,
"msg": ""
}
]
【问题讨论】:
标签: ansible