volumes parameter in ec2 module

1,668 views
Skip to first unread message

Fred Badel

unread,
Feb 18, 2014, 7:57:08 AM2/18/14
to ansible...@googlegroups.com
Hello,

I am trying to create an ec2 instance with specific volumes requirement ... but I keep getting a "this module requires key=value arguments" error message.
Looking closer at ansible output (see below), it looks like the single-quoting of the volumes parameter is a little bit "fancy"...

Am I doing something wrong? 

---
- hosts: 127.0.0.1
  connection: local
  gather_facts: True
  vars:
      volumes:
      - device_name: /dev/sda1
        volume_size: 10
      - device_name: /dev/xvdf
        ephemeral: ephemeral0
      - device_name: /dev/xvdg
        volume_size: 25
      keypair: ec2key
      image: ami-xxx
      dnsdomain: domain.com
  vars_prompt:
      hostname: "What is this instance hostname?"
      subnet: "What is this instance subnet?"
      ip: "What is this instance ip?"
      group: "Provide a list of group name"
      instance_type: "Provide the instance type"
  tasks:
      - name: create instance
        ec2: key_name={{ keypair }} image={{ image }} instance_type={{ instance_type }} vpc_subnet_id={{ subnet }} user_data='{"shortname":"{{ hostname }}", "hostname":"{{ hostname }}.{{ dnsdomain }}"}' wait_timeout=500 private_ip={{ ip }} wait=yes group={{ group }} count=1 state=present volumes={{ volumes }}



<127.0.0.1> REMOTE_MODULE ec2 key_name=ec2key image=ami-xxx instance_type=m1.small vpc_subnet_id=subnet-xxx user_data='{"shortname":"test4", "hostname":"test4.domain.com"}' wait_timeout=500 private_ip=172.16.4.100 wait=yes group="['default', 'J2EE']" count=1 state=present volumes=[{'volume_size': 10, 'device_name': '/dev/sda1'}, {'ephemeral': 'ephemeral0', 'device_name': '/dev/xvdf'}, {'volume_size': 25, 'device_name': '/dev/xvdg'}]
<127.0.0.1> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1392727140.89-11533654997021 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1392727140.89-11533654997021 && echo $HOME/.ansible/tmp/ansible-tmp-1392727140.89-11533654997021']
<127.0.0.1> PUT /var/folders/38/_r_kpxbd4cvfq_9qdvkb0jd40000gn/T/tmpapBeCB TO /Users/fred/.ansible/tmp/ansible-tmp-1392727140.89-11533654997021/ec2
<127.0.0.1> EXEC ['/bin/sh', '-c', '/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python /Users/fred/.ansible/tmp/ansible-tmp-1392727140.89-11533654997021/ec2; rm -rf /Users/fred/.ansible/tmp/ansible-tmp-1392727140.89-11533654997021/ >/dev/null 2>&1']
failed: [127.0.0.1] => {"failed": true}
msg: this module requires key=value arguments (['key_name=ec2key', 'image=ami-xxx', 'instance_type=m1.small', 'vpc_subnet_id=subnet-xxx', 'user_data={"shortname":"test4", "hostname":"test4.domain.com"}', 'wait_timeout=500', 'private_ip=172.16.4.100', 'wait=yes', "group=['default', 'J2EE']", 'count=1', 'state=present', 'volumes=[{volume_size:', '10,', 'device_name:', '/dev/sda1},', '{ephemeral:', 'ephemeral0,', 'device_name:', '/dev/xvdf},', '{volume_size:', '25,', 'device_name:', '/dev/xvdg}]'])

FATAL: all hosts have already failed -- aborting


ansible-playbook --version
ansible-playbook 1.5 (devel 7e23ed345f) last updated 2014/02/18 12:15:46 (GMT +200)

Thanks for your advices!

Fred

Michael DeHaan

unread,
Feb 18, 2014, 8:48:38 AM2/18/14
to ansible...@googlegroups.com
When using the ec2 module it's almost always easier to use the complex arguments style as shown in the examples.

If you are going to pass typed data to modules (like "volumes"), that is going to be required.




--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Frédéric Badel

unread,
Feb 18, 2014, 11:00:19 AM2/18/14
to ansible...@googlegroups.com
Hi Michael,

Thanks for your help.
… I am not sure to understand though …

I tried to copy the example given on doc.ansible.com:
local_action:
    module: ec2
    keypair: mykey
    group: webserver
    instance_type: m1.large
    image: ami-6e649707
    wait: yes
    wait_timeout: 500
    volumes:
    - device_name: /dev/sdb
      snapshot: snap-abcdef12
      device_type: io1
      iops: 1000
      volume_size: 100
and I get the following error:

ERROR: parse error: playbooks must be formatted as a YAML list, got <type 'dict’>


Then I tried with

volumes: [{ device_name: '/dev/sda1', volume_size: '10' }, { device_name: '/dev/xvdf', ephemeral: 'ephemeral0' }, { device_name: '/dev/xvdg', volume_size: '25'}]

and

volumes:
- { device_name: '/dev/sda1', volume_size: '10' }, 
- { device_name: '/dev/xvdf', ephemeral: 'ephemeral0’ }
- { device_name: '/dev/xvdg', volume_size: '25’}

And with both, I get:

msg: this module requires key=value arguments (['key_name=GenericLinux', 'image=ami-75342c01', 'instance_type=m1.small', 'vpc_subnet_id=subnet-81407bf5', 'user_data={shortname:test4, hostname:test4.aws.onlotaris.com}', 'wait_timeout=500', 'private_ip=172.16.4.100', 'wait=yes', 'group=default', 'count=1', 'state=present', 'instance_tags={"Name":"test4"}', 'volumes=[{volume_size:', '10,', 'device_name:', '/dev/sda1},', '{ephemeral:', 'ephemeral0,', 'device_name:', '/dev/xvdf},', '{volume_size:', '25,', 'device_name:', '/dev/xvdg}]'])

Thanks in advance.

Fred

David Adams

unread,
Feb 18, 2014, 12:31:00 PM2/18/14
to ansible...@googlegroups.com
That snippet of code you posted isn't a complete playbook. You need at least:

- hosts: myhost
  tasks:
    - local_action: ...

Paul Durivage

unread,
Feb 18, 2014, 5:24:45 PM2/18/14
to ansible...@googlegroups.com
Hi Fred,

In your first example, you did not quote your variables in the play:

tasks:
      - name: create instance
        ec2: key_name={{ keypair }} image={{ image }} instance_type={{ instance_type }} vpc_subnet_id={{ subnet }} user_data='{"shortname":"{{ hostname }}", "hostname":"{{ hostname }}.{{ dnsdomain }}"}' wait_timeout=500 private_ip={{ ip }} wait=yes group={{ group }} count=1 state=present volumes={{ volumes }}

The second error you received:

ERROR: parse error: playbooks must be formatted as a YAML list, got <type 'dict’>

This error means that you likely did not format your playbook into a list of plays.  The format should be as David Adams previously described.



On Tue, Feb 18, 2014 at 10:00 AM, Frédéric Badel <fr...@never-mind.ch> wrote:
Reply all
Reply to author
Forward
0 new messages