2017-02-15 9 views
0

私はELB内のインスタンスを数えようとしています。だから何イムがやろうとすることによって、単にループで不可能なショーのエラー:「with_items」を使用すると「未定義の変数が1つ以上あります: 'アイテムは未定義です」

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 

とelb_facts内のすべてのものを印刷し、インスタンス変数:

- 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 }}" 

と私の出力(機密データが削除):これは私のAnsible脚本です。私が知ることから、それはハッシュのリストを含んでいるハッシュです。

参考として、http://docs.ansible.com/ansible/playbooks_loops.html#looping-over-subelementsを使用しています。なぜ私はこれが機能していないのか理解できない。

答えて

4

with_items(およびwith_ループのファミリ全体)は、アクションのパラメータではなく、タスクで定義された辞書キーです。働い

- debug: 
    msg: "Instance: {{ item.instances }}" 
    with_items: "{{ elb_facts.elbs }}" 
+0

ありがとう:

は、インデントを修正します! –

関連する問題