Please explain ec2_instance volumes config

I am trying to use the ec2_instance module to create an ec2 instance. When using the ec2 module to configure a volume one would do something like this:

volumes:

  • device_name: /dev/sda1
    volume_type: gp2
    volume_size: 50

With ec2_instance I am not sure how to set the values.

In the description it says:

A list of block device mappings, by default this will always use the AMI root device so the volumes option is primarily for adding more storage.
A mapping contains the (optional) keys device_name, virtual_name, ebs.device_type, ebs.device_size, ebs.kms_key_id, ebs.iops, and ebs.delete_on_termination.

Please let me know how I would set the info from above example using the ec2_instance module.

Thank you

Yes, it’s not clear. And is made worse by the fact that there are STILL no ec2_instance examples! The examples given are ec2_instance_facts examples.

Regard, K.

please submit an issue or a PR to update the docs if you have examples or figure out how it should be.

Hi,

/dev/sda is reserved for root.

Please try below…

# Single instance with ssd gp2 root volume
- ec2:
    key_name: mykey
    group: webserver
    instance_type: c3.medium
    image: ami-123456
    wait: yes
    wait_timeout: 500
    volumes:
      - device_name: /dev/xvda
        volume_type: gp2
        volume_size: 8
    vpc_subnet_id: subnet-29e63245
    assign_public_ip: yes
    count_tag:
      Name: dbserver
    exact_count: 1

You may need to specify /dev/sda1 still, if you want to attach a larger root volume than the AMI provides, or a volume with characteristics the default volume does not have.

Regards, K.

Well, I don’t know what I was looking at, but now there ARE ec2_instance examples. I haven’t checked them out beyond noting that at least they are not ec2_instance_facts examples :slight_smile:

Maybe I was looking at older documentation.

As soon as I logged into github I found the previous bug report on this issue.

Regards, K.

when you are checking module documentation, make sure you match the correct ansible version. For example, latest https://docs.ansible.com/ansible/latest/modules/modules_by_category.html you can change the latest part to 2.4, 2.5, 2.6, or devel. Sometimes the documentation changes so the path in the url might be different but, for the most part this works.

I send you the file where error is permission denied. Please see if you can help me.

(attachments)

It’s free version having default setting .

I have free account so only default instances can be created but I changed Root Password To Root before starting so there should not be permission issue but it gives me an permission issue.

Hullo Kiran Sonawane.

Jonathan Lozada De La Matta was actually speaking to me about the doco issue. But send your stuff, we’ll see if we can answer your question.

Regards, K.

Kiran,

Your issue seems to be more an issue about connecting right to the aws vm than ansible. Did you create the keys, downloaded them, ssh-add and connecting as the right user? are you using -K and escalating correctly?

now I tried connection ec2 instance from putty. then i followed all the steps in all videos on youtube its giving the following error.

(ECDSA) to the list of known hosts.
Permission denied (publickey).

(attachments)

Hullo Kiran Sonawane

"permission denied"is good! It means that you do have network connectivity to the instance. It also means that either the username OR the private key (OR both :slight_smile: are incorrect.

Turn on all the debugging you can find in putty, try connecting again, and post the debug output here.

This page really has everything you need:

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html

And this page will help you if you still have issues:

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstancesConnecting.html

Regards, K.

I didn’t notice your attachment, sorry.

The attachment indicates that you are not specifying the private key!

Copy the key (that you downloaded when you created the instance) into ~/.ssh. Set it’s permissions to “-rw-------”:

cp /path/to/downloaded/keyfile.pem ~/.ssh
chmod u=rw,go= ~/.ssh/keyfile.pem

Then specify the key when connecting:

ssh -i ~/.ssh/keyfile.pem ubuntu@18.191.217.98

You can make life simpler by creating a file called ~/.ssh/config and putting this in it:

Host myhost
HostName 18.191.217.98
User ubuntu
IdentityFile ~/.ssh/keyfile.pem

Then you can just say:

ssh myhost

Obviously replace “myhost” with whatever name you prefer, and “keyfile.pem” with the actual name of the private key file.

Setting up putty takes longer, partly because you have to convert the private key, but once set up it’s just point and click to connect.

Regards, K.

My .pem file is on remote machine (windows) how can I now copy that file into my ec2 instance?

Hullo Kiran Sonawane

I’m puzzled. How did you download the .pem file onto an instance you have no access to?

There are two parts to a key pair in AWS.

The PUBLIC part will be placed on the instance by AWS as it is created, as an entry in ~ubuntu/.ssh/authorized_keys

The PRIVATE part will be offered to you for download when you create it - whether you create it using the CLI, an API or the Console. That PRIVATE part will be called something.pem.

Please confirm that the .pem file offered to you when you created the keypair is on the remote server - that you have no access to.

If you really have no access to the server the .pem file is on, you will be unable to access the instance without going through a relatively complicated recovery process. It’s generally simpler to create a new instance.

Regards, K.

i created config file in .ssh folder but now i’m getting error

/root/.ssh/config line 4: Missing argument.

I’m sending you config files cat screen shot and error screen shot

thanx in advance

Actually I opened powershell in windows and copy the content (which was easy) then I vi and pasted it in .ssh folder with same name and .pem extension that’s it.

But that config file you told me to create I put an public IP as HostName also the last line IdentityFile I don’t understand. So still confused what’s an missing argument?