我使用 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() 方法返回值的适当文档。
任何帮助表示赞赏。
谢谢,