我想从输出/结果数组中选择一个特定的键,但我遇到了困难,我已经检查了这个post,但我无法将其适应我的剧本:
---
- hosts: '{{ site }}'
gather_facts: false
tasks:
- name: Get Checkmk version
community.windows.win_file_version:
path: 'C:\Program Files (x86)\checkmk\service\check_mk_agent.exe'
register: file_version
- debug:
var: file_version
我想选择“product_version”的输出,例如“2.2.0p7”。
TASK [debug] *******************************************************************
ok: [10.10.10.10] => {
"file_version": {
"changed": false,
"failed": false,
"win_file_version": {
"file_build_part": "0",
"file_major_part": "2",
"file_minor_part": "1",
"file_private_part": "0",
"file_version": "2.1.0.0",
"path": "C:\\Program Files (x86)\\checkmk\\service\\check_mk_agent.exe",
"product_version": "2.2.0p7"
}
}
}
一个最小的示例手册
---
- hosts: localhost
become: false
gather_facts: false
vars:
result: {
"changed": false,
"failed": false,
"win_file_version": {
"file_build_part": "0",
"file_major_part": "2",
"file_minor_part": "1",
"file_private_part": "0",
"file_version": "2.1.0.0",
"path": "C:\\Program Files (x86)\\checkmk\\service\\check_mk_agent.exe",
"product_version": "2.2.0p7"
}
}
tasks:
- debug:
var: result.win_file_version
- name: Product version is
debug:
msg: "{{ result.win_file_version.product_version }}"
将产生
的输出TASK [debug] *******************************************************
ok: [localhost] =>
result.win_file_version:
file_build_part: '0'
file_major_part: '2'
file_minor_part: '1'
file_private_part: '0'
file_version: 2.1.0.0
path: C:\Program Files (x86)\checkmk\service\check_mk_agent.exe
product_version: 2.2.0p7
TASK [Product version is] *******************************************************************
ok: [localhost] =>
msg: 2.2.0p7
文档