Amazon web services Ansible,ec2_remote_facts-错误为:';dict对象';没有属性

Amazon web services Ansible,ec2_remote_facts-错误为:';dict对象';没有属性,amazon-web-services,amazon-ec2,ansible,Amazon Web Services,Amazon Ec2,Ansible,我有一些很好的剧本 --- - 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

我有一些很好的剧本

---

- 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创建和配置期间可以正常工作

在第一个剧本中,调试:var=ec2_remote_facts向我展示了我在第二个剧本中创建的实例

---

- 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


我错过了什么?提前谢谢

注意
ec2
ec2\u remote\u facts
结果的不一致性

ec2
填充
private\u-ip
public\u-ip

ec2\u remote\u facts
填充
private\u ip\u地址
public\u ip\u地址


为每种情况适当地更改
add\u host
任务。

为什么在第一次播放时,您不在
debug:var=ec2
中得到一个错误?相反,debug:var=ec2\u remote\u facts的输出是什么?'debug:var=ec2\u remote\u facts'显示了我的现有实例,我没有要求您解释。我让你把结果包括在问题中。