Hi,
I want to register the return value of ec2_vol module so that I can retrieve the volume id and use it later.
My playbook is -
-
name: Add volume
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_vol
ignore_errors: yes
-
name: Stop instance
local_action: command aws ec2 stop-instances --profile=test --instance-id={{item.id}}
with_items: ec2.instances
ignore_errors: yes
-
name: Detach volume from instance
local_action: command aws ec2 detach-volume --profile=test --volume-id={{item.Y}} <--------------------------------------------------------
with_items: ec2_vol.X <----------------------------------------------------------------------------------------------------------------------------------------------------
ignore_errors: yes
What should I use in place of X and Y to get the volume ids of newly created volumes…??
Hi,
I think just volume_id, so ec2_vol.volume_id as the with_items.
Kind Regards,
Lester
Hi lester,
I tried but it didn’t work. Below is my playbook-
- name: Detach volume from instance
local_action: command aws ec2 detach-volume --profile=test --volume-id={{item}}
with_items: ec2_vol.volume_id
ignore_errors: yes
I get an error as shown below -
TASK: [Detach volume from instance] *******************************************
failed: [localhost] => (item=ec2_vol.volume_id) => {“changed”: true, “cmd”: [“aws”, “ec2”, “detach-volume”, “–profile=test”, “–volume-id=ec2_vol.volume_id”], “delta”: “0:00:00.756544”, “end”: “2013-09-17 15:38:39.200170”, “item”: “ec2_vol.volume_id”, “rc”: 255, “start”: “2013-09-17 15:38:38.443626”}
stderr: A client error (InvalidVolumeID.Malformed) occurred: Invalid id: “ec2_vol.volume_id” (expecting “vol-…”)
…ignoring
I saw the code for ec2_vol and it uses boto’s create_volume() module. But in boto’s documentation(http://docs.pythonboto.org/en/latest/ref/ec2.html#module-boto.ec2.volume), it says that id represents volume_id.
Any help is appreciated.
Thanks,