我有一些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
显示我的实例,我在第二个剧本期间创建。
---
- 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
我缺少什么?提前致谢!
为什么不在第一次播放时在debug:var = ec2中出错?相反,'debug:var = ec2_remote_facts'的输出是什么? – techraf
'debug:var = ec2_remote_facts'显示我现有的实例 – BattleLoot
我没有要求您的解释。我要求你在问题中包含输出。 – techraf