volumes parameter in ec2 module

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?

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.

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

That snippet of code you posted isn’t a complete playbook. You need at least:

  • hosts: myhost
    tasks:
  • local_action: …

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.