unable to specify volumes for new instance

43 views
Skip to first unread message

i iordanov

unread,
Mar 3, 2014, 11:03:17 PM3/3/14
to ansible...@googlegroups.com
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

Frédéric Badel

unread,
Mar 4, 2014, 3:09:40 AM3/4/14
to ansible...@googlegroups.com
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

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/08b3f198-f0fb-41ac-b909-d0e13b137db1%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

i iordanov

unread,
Mar 6, 2014, 8:38:38 AM3/6/14
to ansible...@googlegroups.com
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

Reply all
Reply to author
Forward
0 new messages