小编D.F*_*itz的帖子

如何在ansible中解析XML响应?

我正在运行 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>"
  }
}
Run Code Online (Sandbox Code Playgroud)

这是我可以为“结果”分配值的最接近的结果。

ok: [localhost] => {
  "result.stdout": {
    "response": {
        "@status": "success", 
        "result": "no"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我的目标是为 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 …
Run Code Online (Sandbox Code Playgroud)

xml-parsing ansible

3
推荐指数
1
解决办法
8417
查看次数

标签 统计

ansible ×1

xml-parsing ×1