Ansible显示错误:"使用'with_items'时,"一个或多个未定义的变量:'item'未定义"

Jus*_*n S 2 ansible

我试图计算一个elb中的实例.这是我的Ansible剧本:

- name: Get elb facts
  local_action:
    module: ec2_elb_facts
    name: "{{elb}}"
    region: "{{ansible_ec2_placement_region}}"
  environment: creds
  register: elb_facts

- debug:
    var: elb_facts
    verbosity: 2

- debug:
    msg: "Instance: {{ item.instances }}"
    with_items: "{{ elb_facts.elbs }}"
Run Code Online (Sandbox Code Playgroud)

和我的输出(敏感数据已删除):

TASK: [debug ] ****************************************************************
ok: [10.0.0.0] => {
    "elb_facts": {
        "changed": false,
        "elbs": [
            {
                "availability_zones": [
                    "ap-southeast-2b",
                    "ap-southeast-2a"
                ],
                "dns_name": "elbname123.ap-southeast-2.elb.amazonaws.com",
                "health_check": {
                    "healthy_threshold": 2,
                    "interval": 10,
                    "target": "TCP:0000",
                    "timeout": 5,
                    "unhealthy_threshold": 2
                },
                "instances": [
                    {
                        "id": "i-000000000000000",
                        "state": null
                    }
                ],
                "name": "accessgateway",
                "scheme": "internal",
                "security_groups": [
                    "sg-00000000"
                ],
                "subnet": [
                    "subnet-0000000",
                    "subnet-1111111"
                ],
                "vpc_id": "vpc-000000"
            }
        ],
        "invocation": {
            "module_args": "",
            "module_name": "ec2_elb_facts"
        }
    }
}

TASK: [debug ] ****************************************************************
fatal: [10.0.0.0] => One or more undefined variables: 'item' is undefined

FATAL: all hosts have already failed -- aborting
Run Code Online (Sandbox Code Playgroud)

所以我试图做的只是循环并打印elb_facts,instances变量中的所有内容.从我可以告诉它是一个哈希,包含哈希列表.

我使用http://docs.ansible.com/ansible/playbooks_loops.html#looping-over-subelements作为参考.我不能为我的生活弄清楚为什么这不起作用.

tec*_*raf 8

with_items(以及整个with_循环系列)是在任务中定义的字典键,而不是操作的参数.

修复缩进:

- debug:
    msg: "Instance: {{ item.instances }}"
  with_items: "{{ elb_facts.elbs }}"
Run Code Online (Sandbox Code Playgroud)