[英]Get the AMI ID of an AMI created with Ansible
I'm building an EC2 instance with Ansible, then creating an AMI from the instance. 我正在使用Ansible构建EC2实例,然后从实例创建AMI。 I'm sure I'm missing something here, but how do I get the DI of the newly created AMI?
我确定我在这里遗漏了一些东西,但是如何获得新创建的AMI的DI? I've tried:
我试过了:
tasks:
- name: create an ami in us-east-1
ec2_ami: wait=yes
aws_access_key={{ ec2_access_key }}
aws_secret_key={{ ec2_secret_key }}
instance_id={{ item }}
region={{ region1 }}
name=data-mgmt-qa-006
with_items: hostvars[inventory_hostname]['ansible_ec2_instance_id']
register: ec2_ami_info
- debug: var=item
with_items: ec2_ami_info.image_id
and: 和:
tasks:
- name: create an ami in us-east-1
ec2_ami: wait=yes
aws_access_key={{ ec2_access_key }}
aws_secret_key={{ ec2_secret_key }}
instance_id={{ item }}
region={{ region1 }}
name=data-mgmt-qa-006
with_items: hostvars[inventory_hostname]['ansible_ec2_instance_id']
register: instance
- debug: var=item
with_items: instance.image_id
The latter 'register' is copied from the docs, but I'm not able to get the right with_items obviously. 后者'注册'是从文档中复制的,但我显然无法正确使用with_items。
The AMI is being created fine. AMI正在创建中。 Any suggestions would be much appreciated.
任何建议将不胜感激。
Ran debug var=instance, and got: Ran debug var = instance,得到:
TASK: [debug var=instance] ****************************************************
ok: [54.90.128.104] => {
"instance": {
"changed": true,
"msg": "All items completed",
"results": [
{
"changed": true,
"image_id": "ami-be14b9d6",
"invocation": {
"module_args": "wait=yes aws_access_key=**** aws_secret_key=**** instance_id=i-393284d2 region=us-east-1 name=blah",
"module_name": "ec2_ami"
},
"item": "i-393284d2",
"msg": "AMI creation operation complete",
"state": "available"
}
]
}
}
Given that: 鉴于:
- debug: var=instance.results[0].image_id
gave the correct results. 给出了正确的结果。
The ec2_ami
task is correct, but your invocation of the debug
module is wrong. ec2_ami
任务是正确的,但是debug
模块的调用是错误的。 Try this: 试试这个:
- debug: var=instance.image_id
or alternatively 或者
- debug: msg={{instance.image_id}}
You don't need with_items
here since there's only one value. 你不需要
with_items
,因为只有一个值。 with_items
is a loop. with_items
是一个循环。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.