Hi guys,
I’m stuck with an issue and hoping somebody can spot my mistake. I have a task like the following where I’m trying to specify a volume for the ec2 instance.
tasks:
- name: Start instance
ec2: image=ami-xxxx
count=1
aws_access_key=xxx
aws_secret_key=yyy
.
.
volumes=‘{ “device_name”:/dev/sdb, “volume_size”:“10” }’
wait=true
No matter what syntax I try, ansible refuses to accept my specification. I can’t specify a single, let alone multiple volumes. Can anybody tell me what the syntax should look like?
Many thanks!
iordan
Hi,
I had some trouble putting everything together with the ec2 module …
with the help of the list I finally got it working.
As Michael pointed out, with the ec2 module, it is easier to use complex arguments style.
This is a working example:
- hosts: 127.0.0.1
connection: local
gather_facts: True
vars:
…
tasks:
- name: create a vm
local_action:
module: ec2
image: “{{ image }}”
count: 1
instance_type: “{{ instance_type }}”
group: “{{ group }}”
key_name: “{{ keypair }}”
vpc_subnet_id: “{{ subnet }}”
private_ip: “{{ ip }}”
user_data: “{{ hostname }}.{{ dnsdomain }}”
instance_tags: ‘{“Name”:“{{ hostname }}”}’
volumes:
- device_name: /dev/sda1
volume_size: 10
- device_name: /dev/sdb
ephemeral: ephemeral0
- device_name: /dev/sdc
volume_size: 25
wait: true
wait_timeout: 500
state: present
register: ec2
Hope this help.
Fred
Hi Fred,
Thank you very much, your suggestion to use complex arguments style was spot on. However, for some reason I couldn’t get the parser to accept local_action and my rule took on yet a different form. Here it is, in case it helps somebody!
- name: Make {{ hostname }}
ec2:
image: “{{ ami }}”
id: “{{ hostname }}”
instance_tags: ‘{“Name”:“{{ hostname }}”, “type”:“{{ group }}”}’
instance_type: “{{ type }}”
count: “{{ count }}”
aws_access_key: “{{ ec2_access_key }}”
aws_secret_key: “{{ ec2_secret_key }}”
region: “{{ region }}”
keypair: “{{ keypair }}”
group_id: “{{ group_id }}”
vpc_subnet_id: “{{ vpc_subnet_id }}”
volumes:
- device_name: “{{ root_dev_name }}”
volume_size: “{{ root_dev_size }}”
state: present
wait: true
register: machine_info
delegate_to: 127.0.0.1