【发布时间】:2018-04-16 21:42:56
【问题描述】:
我正在运行 panos_op ansible 模块并努力解析输出。
ok: [localhost] => {
"result": {
"changed": true,
"failed": false,
"msg": "Done",
"stdout": "{\"response\": {\"@status\": \"success\", \"result\": \"no\"}}",
"stdout_lines": [
"{\"response\": {\"@status\": \"success\", \"result\": \"no\"}}"
],
"stdout_xml": "<response status=\"success\"><result>no</result></response>"
}
}
这是我可以为“结果”分配值的尽可能接近。
ok: [localhost] => {
"result.stdout": {
"response": {
"@status": "success",
"result": "no"
}
}
}
我的目标是为 ansible 任务设置条件循环。
tasks:
- name: Checking for pending changes
panos_op:
ip_address: '{{ host }}'
password: '{{ operator_pw }}'
username: '{{ operator_user}}'
cmd: 'check pending-changes'
register: result
until: result.stdout.result = no
retries: 10
delay: 5
tags: check
我怎样才能做到这一点?
更新:我已经尝试过另一种方式,但现在我遇到了一个新问题,试图处理文字“
tasks:
- name: Checking for pending changes
panos_op:
ip_address: '{{ host }}'
password: '{{ operator_pw }}'
username: '{{ operator_user}}'
cmd: 'check pending-changes'
register: result
- fail:
msg: The Firewall has pending changes to commit.
when: '"<result>no"' not in result.stdout_xml
错误: 没有找到预期的密钥
非常感谢任何帮助。
【问题讨论】:
标签: xml-parsing ansible