使用Ansible从新创建的ebs卷中获取卷ID [英] Get volume id from newly created ebs volume using ansible
本文介绍了使用Ansible从新创建的ebs卷中获取卷ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用ansible的ec2_vol模块创建了ebs卷.我看到了源代码,发现它在内部使用用户指定的参数调用boto的create_volume()方法.我想注册ec2_vol模块的返回值并获取新创建的卷的volume_ids.
到目前为止,我的剧本看起来像
- name: Attach a volume to previously created instances
local_action: ec2_vol instance={{item.id}} volume_size=5 aws_access_key={{aa_key}} aws_secret_key={{as_key}} region={{region}}
with_items: ec2.instances
register: ec2_volumes
ignore_errors: yes
- name: Stop the instances
local_action: command aws ec2 stop-instances --profile=xervmon --instance-id={{item.id}}
with_items: ec2.instances
ignore_errors: yes
- name: Detach volume from instances
local_action: command aws ec2 detach-volume --profile=xervmon --volume-id=????
ignore_errors: yes
我想知道如何获取新创建的卷的卷ID.我看到run_instances()方法的返回对象具有一个实例实例,其中包含实例列表.但是我找不到关于create_volume()方法返回值的任何适当文档.
感谢您的帮助.
谢谢
解决方案
根据 解决方案
According to the ec2_vol module source code, the module returns:
volume_id
device
In your case, you are creating multiple volumes via with_items, so the ec2_volumes
variable that you register will be a dictionary with a key named results
that holds the list of results from each of the individual ec2_vol invocations.
Here's an example that prints out the volume ids (warning: I haven't tested this).
- name: Attach a volume to previously created instances
local_action: ec2_vol instance={{item.id}} volume_size=5 aws_access_key={{aa_key}} aws_secret_key={{as_key}} region={{region}}
with_items: ec2.instances
register: ec2_volumes
- name: Print out the volume ids
debug: msg={{ item.volume_id }}
with_items: ec2_volumes.results
这篇关于使用Ansible从新创建的ebs卷中获取卷ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文