从下面的输出中我只需要看到“值”信息..如何调试才能仅获取值信息?/
ok: [localhost] => {
"msg": {
"changed": false,
"connection": "close",
"content_length": "342",
"content_type": "application/json",
"cookies": {},
"cookies_string": "",
"date": "Tue, 23 Apr 2019 07:44:55 GMT",
"failed": false,
"json": {
"info": [
{
"name": "networkDomainId",
"value": "f173b777-d460-4050-9562-fc6b201415c3"
}
],
"message": "Request to Deploy Network Domain has been accepted. Please use appropriate Get or List API for status.",
"operation": "DEPLOY_NETWORK_DOMAIN",
"requestId": "eu_20190423T094455564+0200_1515ad61-58a7-4853-96fb-2b52d8eddd8a",
"responseCode": "IN_PROGRESS"
},
答案1
如下任务应该可以解决您的问题:
- debug:
var=msg.json.value
下面是使用另一个任务的示例(我不知道您使用哪个模块来生成问题中报告的 msg 变量):
$ cat /tmp/tmp
- hosts: localhost
tasks:
- command: uptime
register: msg
- debug:
var=msg
- debug: var=msg.cmd
$ ansible-playbook /tmp/tmp
PLAY [localhost] *****************************************************************************
TASK [Gathering Facts] ***********************************************************************
ok: [localhost]
TASK [command] *******************************************************************************
changed: [localhost]
TASK [debug] *********************************************************************************
ok: [localhost] => {
"msg": {
"changed": true,
"cmd": [
"uptime"
],
"delta": "0:00:00.003576",
"end": "2019-04-23 11:45:43.393217",
"rc": 0,
"start": "2019-04-23 11:45:43.389641",
"stderr": "",
"stderr_lines": [],
"stdout": " 11:45:43 up 1:57, 1 user, load average: 0,33, 0,61, 0,83",
"stdout_lines": [
" 11:45:43 up 1:57, 1 user, load average: 0,33, 0,61, 0,83"
]
}
}
TASK [debug] *********************************************************************************
ok: [localhost] => {
"msg.cmd": [
"uptime"
]
}
PLAY RECAP ***********************************************************************************
localhost : ok=4 changed=1 unreachable=0 failed=0
答案2
- 您可以将输出保存到文件中并通过 grep 查找值。
grep value <filename>
- 要调试 ansible 输出,请使用 -vvv
ansible-playbook abc.yml -vvv
答案3
我得到了下面的答案..
注册:创建-调试:
var: create.json.info.0.value
确定:[localhost] => {“create.json.info.0.value”:“b9cebba5-22d5-4689-b04e-3882f377f575”}