2017-03-09 14 views
1

を持っていない私は、この脚本を実行すると、私は、私は次のエラーをいくつかAnsibleの脚本Ansible、ec2_remote_facts - エラー: '辞書のオブジェクトが' 無属性

--- 

- name: Sandbox 
    hosts: localhost 
    connection: local 
    gather_facts: true 
    tasks: 

    - name: Get facts by filter 
    ec2_remote_facts: 
     region: "{{ aws_default_region }}" 
     filters: 
     instance-state-name: running 
    register: ec2_remote_facts 

    - name: debug 
    debug: var=ec2_remote_facts 

    - name: Add running sandbox instances to in-memory inventory host group 
    add_host: 
     hostname: "{{ item.public_ip }}" 
     groups: running 
    with_items: "{{ ec2_remote_facts.instances }}" 

- name: Configure provisioned servers 
    hosts: running 
    gather_facts: true 
    user: ec2-user 
    become: true 
    roles: 
    - base 

を取得していています

TASK [Add running sandbox instances to in-memory inventory host group] ********* 
fatal: [127.0.0.1]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'dict object' has no attribute 'public_ip' 

私はec2の作成とプロビジョニングでは同じコードがうまく動作するため、少し混乱します。

最初のプレイでは、debug: var=ec2_remote_factsは私が2番目のプレイブックで作成したインスタンスを表示します。

--- 

- name: Sandbox instances 
    hosts: localhost 
    connection: local 
    gather_facts: false 

    tasks: 

    - name: Launch a sandbox instance 
    ec2: 
     keypair: "{{ aws_default_keypair }}" 
     aws_access_key: "{{ aws_access_key }}" 
     aws_secret_key: "{{ aws_secret_key }}" 
     instance_type: "{{ aws_default_instance_type }}" 
     image: "{{ aws_default_ami_image }}" 
     region: "{{ aws_default_region }}" 
     group: "{{ aws_default_security_group_name }}" 
     count: "{{ aws_default_count_of_instances }}" 
     instance_tags: 
     Name: "{{ aws_default_instance_tag_name }}" 
     Group: "{{ aws_default_instance_tag_group }}" 
     wait: yes 
    register: ec2 

    - name: debug 
    debug: var=ec2 

    - name: Add new sandbox instances to in-memory inventory host group 
    add_host: 
     hostname: "{{ item.public_ip }}" 
     groupname: running 
    with_items: "{{ ec2.instances }}" 

    - name: Wait for SSH to come up 
    wait_for: 
     host: "{{ item.public_dns_name }}" 
     port: 22 
     delay: 60 
     timeout: 320 
     state: started 
    with_items: "{{ ec2.instances }}" 

- name: Configure provisioned servers 
    hosts: running 
    gather_facts: false 
    user: ec2-user 
    become: true 
    roles: 
    - base 

Ansibleのバージョンは2.2.1.0

私は何をしないのですのですか?前もって感謝します!

+0

最初の試合で 'debug:var = ec2'でエラーになるのはなぜですか?代わりに、 'debug:var = ec2_remote_facts'の出力は何ですか? – techraf

+0

'debug:var = ec2_remote_facts'は私の既存のインスタンスを表示します – BattleLoot

+0

私はあなたの説明を求めませんでした。私は質問に出力を含めるように頼んだ。 – techraf

答えて

2

ec2ec2_remote_factsの結果に矛盾があることに注意してください。

ec2は、private_ippublic_ipです。
ec2_remote_factsは、private_ip_addresspublic_ip_addressとなります。

ケースごとにadd_hostタスクを適切に変更してください。

+0

それは、私の誤植誤解...多くのありがとう! – BattleLoot

関連する問題