如何仅在ansible中发送文件路径?
How to msg only the file path in ansible?
这是我的ansible:
- name: finding files
find:
paths: /etc/nginx
patterns: '{{ my_vhost }}'
recurse: "yes"
file_type: "file"
delegate_to: '{{ my_server }}'
register: find_result
- name: output the path of the conf file
debug: msg="{{ find_result.files }}"
msg 的输出是:
"msg": [
{
"atime": 1567585207.0371234,
"ctime": 1567585219.9410768,
"dev": 64768,
"gid": 1001,
"inode": 4425684,
"isblk": false,
"ischr": false,
"isdir": false,
"isfifo": false,
"isgid": false,
"islnk": false,
"isreg": true,
"issock": false,
"isuid": false,
"mode": "0644",
"mtime": 1567585219.9410768,
"nlink": 1,
"path": "/etc/nginx/sites-enabled/specified-file",
"rgrp": true,
"roth": true,
"rusr": true,
"size": 546,
"uid": 1001,
"wgrp": false,
"woth": false,
"wusr": true,
"xgrp": false,
"xoth": false,
"xusr": false
}
]
}
我只想输出这一行:
"path": "/etc/nginx/sites-enabled/specified-file",
我不太关心消息,特别是我只想使用这条路径“/etc/nginx/sites-enabled/specified-file”供以后使用。我的系统中文件路径永远只有一个结果
请尝试如下
- name: output the path of the conf file
set_fact:
path: "{{ item.path }}"
with_items: "{{ find_result.files}}"
- debug:
msg: "{{ path }}"
@CzipO2,您可以使用以下任务,这些任务还可以在变量中设置文件路径,稍后可以在剧本中使用,
- set_fact:
filepath: "{{ find_result.files | map(attribute='path') | list | first}}"
- name: output the path of the conf file
debug:
msg: "{{ filepath }}"
I don't really care about the msg, specifically, I want to use just this path "/etc/nginx/sites-enabled/specified-file" for later usage.
文件路径事实可以在剧本中使用以备后用。
这是我的ansible:
- name: finding files
find:
paths: /etc/nginx
patterns: '{{ my_vhost }}'
recurse: "yes"
file_type: "file"
delegate_to: '{{ my_server }}'
register: find_result
- name: output the path of the conf file
debug: msg="{{ find_result.files }}"
msg 的输出是:
"msg": [
{
"atime": 1567585207.0371234,
"ctime": 1567585219.9410768,
"dev": 64768,
"gid": 1001,
"inode": 4425684,
"isblk": false,
"ischr": false,
"isdir": false,
"isfifo": false,
"isgid": false,
"islnk": false,
"isreg": true,
"issock": false,
"isuid": false,
"mode": "0644",
"mtime": 1567585219.9410768,
"nlink": 1,
"path": "/etc/nginx/sites-enabled/specified-file",
"rgrp": true,
"roth": true,
"rusr": true,
"size": 546,
"uid": 1001,
"wgrp": false,
"woth": false,
"wusr": true,
"xgrp": false,
"xoth": false,
"xusr": false
}
]
}
我只想输出这一行:
"path": "/etc/nginx/sites-enabled/specified-file",
我不太关心消息,特别是我只想使用这条路径“/etc/nginx/sites-enabled/specified-file”供以后使用。我的系统中文件路径永远只有一个结果
请尝试如下
- name: output the path of the conf file
set_fact:
path: "{{ item.path }}"
with_items: "{{ find_result.files}}"
- debug:
msg: "{{ path }}"
@CzipO2,您可以使用以下任务,这些任务还可以在变量中设置文件路径,稍后可以在剧本中使用,
- set_fact:
filepath: "{{ find_result.files | map(attribute='path') | list | first}}"
- name: output the path of the conf file
debug:
msg: "{{ filepath }}"
I don't really care about the msg, specifically, I want to use just this path "/etc/nginx/sites-enabled/specified-file" for later usage.
文件路径事实可以在剧本中使用以备后用。