Ansible显示变量的内容

Ansible显示变量的内容,ansible,ansible-playbook,Ansible,Ansible Playbook,如果我有这两个任务 - name: Replace ServerIP in config_file on OTHER NODES set_fact: variable: "{{hostvars.localhost.new_ips.results}}" - name: Display variable debug: var=variable 其结果是: TASK: [Display variable] **************************************

如果我有这两个任务

- name: Replace ServerIP in config_file on OTHER NODES
  set_fact:
    variable: "{{hostvars.localhost.new_ips.results}}"

- name: Display variable
  debug: var=variable
其结果是:

TASK: [Display variable] ********************************************************* 
ok: [vm2] => {
    "variable": [
        {
            "changed": true, 
            "cmd": "echo \"11.11.4.74\"", 
            "delta": "0:00:00.002244", 
            "end": "2014-08-26 02:34:22.880447", 
            "invocation": {
                "module_args": "echo \"11.11.4.74\"", 
                "module_name": "shell"
            }, 
            "item": "74", 
            "rc": 0, 
            "start": "2014-08-26 02:34:22.878203", 
            "stderr": "", 
            "stdout": "11.11.4.74"
        }, 
        {
            "changed": true, 
            "cmd": "echo \"11.11.4.138\"", 
            "delta": "0:00:00.002156", 
            "end": "2014-08-26 02:34:22.958337", 
            "invocation": {
                "module_args": "echo \"11.11.4.138\"", 
                "module_name": "shell"
            }, 
            "item": "138", 
            "rc": 0, 
            "start": "2014-08-26 02:34:22.956181", 
            "stderr": "", 
            "stdout": "11.11.4.138"
        }
    ]
}
ok: [vm1] => {
    "variable": [
        {
            "changed": true, 
            "cmd": "echo \"11.11.4.74\"", 
            "delta": "0:00:00.002244", 
            "end": "2014-08-26 02:34:22.880447", 
            "invocation": {
                "module_args": "echo \"11.11.4.74\"", 
                "module_name": "shell"
            }, 
            "item": "74", 
            "rc": 0, 
            "start": "2014-08-26 02:34:22.878203", 
            "stderr": "", 
            "stdout": "11.11.4.74"
        }, 
        {
            "changed": true, 
            "cmd": "echo \"11.11.4.138\"", 
            "delta": "0:00:00.002156", 
            "end": "2014-08-26 02:34:22.958337", 
            "invocation": {
                "module_args": "echo \"11.11.4.138\"", 
                "module_name": "shell"
            }, 
            "item": "138", 
            "rc": 0, 
            "start": "2014-08-26 02:34:22.956181", 
            "stderr": "", 
            "stdout": "11.11.4.138"
        }
    ]
}

那么我怎样才能访问变量的stdout部分呢。请注意,我只需要这个变量的stdout部分,即11.11.4.74和11.11.4.138(最好在循环中)

您可以单独访问它

{{ variable[0].stdout }}
及 {{变量[1].stdout}

或者使用循环

  - debug: var=item.stdout
    with_items: variable

尝试
variable.0.stdout
?如果执行类似variable.stdout的操作,则会出现以下错误:一个或多个未定义的变量:“dict object”没有属性“stdout”。如果我像你说的那样做,那么我会得到一个错误:一个或多个未定义的变量:dict对象没有元素0Hey wait:new_ips1:“{{variable.results.0.stdout}”工作,但只存储第一个条目!是否有某种方法可以遍历列表并将其保存为{{variable.results.{{i}.stdout}}或{variable.results[i].stdout}或
{variables[“results”][“i”][“stdout”]}
-不确定Jinja插值在这里是如何工作的