我尝试了以下操作,但出现以下错误:
任务[向主机组添加新实例]
致命:[localhost]:失败! => {“ msg”:“该任务包含带有未定义变量的选项。错误是:'item'未定义\ n \ n错误似乎出在'/root/site_mini_yarn.yaml'中:第29行,列7,但根据确切的语法问题,\ n可能不在文件的其他位置。\ n \ n出现问题的行似乎是:\ n \ n调试:var = ec2 \ n-名称:将新实例添加到主机组\ n ^ \ n \ nexception类型:\ nexception:'item'未定义“}
以下是yaml文件:
---
# Talk to all hosts just so we can learn about them...
- name: Create a sandbox instance
hosts: localhost
gather_facts: False
vars:
keypair: mynewkeypair
instance_type: t2.micro
image: ami-05868579
region: ap-southeast-1
security_group: mywebDM
tasks:
- name: Launch instance
ec2:
key_name: "{{ keypair }}"
group: "{{ security_group }}"
instance_type: "{{ instance_type }}"
image: "{{ image }}"
instance_tags:
Name: ansibleclient1
wait: true
region: "{{ region }}"
aws_access_key: AKIAJMZ4QEDNMFRGOKIQ
aws_secret_key: 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
register: ec2
- name: Print all ec2 variables
debug: var=ec2
- name: Add new instance to host group
add_host:
hostname: "{{ item.public_ip }}"
with_items: ec2.instances