调试不使用ansible play中的_项
在调试注册表任务中的特定值时需要一些帮助调试不使用ansible play中的_项,ansible,Ansible,在调试注册表任务中的特定值时需要一些帮助 - debug: msg: "{{ item.stdout }}" with_items: path_result.results 这不起作用 { "changed": false, "path_result": { "msg": "All items completed", "changed": true, "results": [ {
- debug:
msg: "{{ item.stdout }}"
with_items: path_result.results
这不起作用
{
"changed": false,
"path_result": {
"msg": "All items completed",
"changed": true,
"results": [
{
"_ansible_parsed": true,
"stderr_lines": [],
"_ansible_item_result": true,
"end": "2019-04-10 14:55:18.726270",
"_ansible_no_log": false,
"_ansible_delegated_vars": {
"ansible_delegated_host": "**.***.***.***",
"ansible_host": "**.***.***.***"
},
"cmd": "cat /tmp/abc.conf | grep apple",
"rc": 0,
"stdout": "fruit=apple",
"item": "**.***.***.***",
"delta": "0:00:00.021499",
"stderr": "",
"changed": true,
"invocation": {
"module_args": {
"creates": null,
"executable": null,
"_uses_shell": true,
"_raw_params": "cat /tmp/abc.conf | grep apple",
"removes": null,
"warn": true,
"chdir": null,
"stdin": null
}
},
"stdout_lines": [
"fruit=apple"
],
"start": "2019-04-10 14:55:18.704771",
"_ansible_ignore_errors": null,
"failed": false
}
]
},
"_ansible_verbose_always": true,
"_ansible_no_log": false
}
我想调试此特定输出:
"stdout": "fruit=apple"
看起来您已经
register
ed播放的结果:register:path\u result
。该变量内部还有path\u result
。以下是我认为您拥有的:
- command: cat /tmp/abc.conf | grep apple
register: path_result
- debug:
msg: "{{ item.stdout }}"
with_items: "{{ path_result.results }}"
以下是我认为您需要的:
- command: cat /tmp/abc.conf | grep apple
register: path_result
- debug:
msg: "{{ item.stdout }}"
with_items: "{{ path_result.path_result.results }}"
注意,在
中添加了.path\u result
部分,其中包含了\u items
我尝试了您提供的部分,但出现了以下错误:{“msg”:"该任务包含一个带有未定义变量的选项。错误是:“ansible.utils.unsafe\u proxy.AnsibleUnsafeText对象”没有属性“stdout”\n\n错误似乎出现在“playbook.yml”中:第10行第3列,但可能\n出现在文件的其他位置,具体取决于语法问题。\n\n出现问题的行是:\n\n\n-debug:\n^here\n“}@jack-shell:cat/tmp/abc.conf | grep apple delegate|u to:“{item}”和{groups.rhel7}”寄存器:path_result-debug:msg:{{item.stdout}“with_items:path_result.path_result.results这是我在游戏中使用的内容。我忘记了将with_items
变量取消引用。现在修好它。