# How to detect AWS instance type

**URL:** <https://forum.ansible.com/t/how-to-detect-aws-instance-type/29770>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [February 26, 2019, 4:56am UTC](https://forum.ansible.com/t/how-to-detect-aws-instance-type/29770 "2019-02-26T04:56:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frank\_Dias](https://avatars.discourse-cdn.com/v4/letter/f/eada6e/32.png) [@Frank\_Dias](https://forum.ansible.com/u/Frank_Dias)\
**Post date:** [February 26, 2019, 4:56am UTC](https://forum.ansible.com/t/how-to-detect-aws-instance-type/29770/1 "2019-02-26T04:56:48Z")

</div>

I have an old playbook that will add an addition volume and it works fine on t2 instances. With the move to t3 instances we also now have nvme based ebs.

The play book uses lvm to setup the second volume we add the volume as xvdf so /dev/xvdf.  
Now on t3 instances when we add the volume as xvdf the volume now shows up as /dev/nvme1n1.

Has anyone figured out a playbook to handle both situations?

---

<div class="post-metadata">

**Author:** ![Pshem\_Kowalczyk](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@Pshem\_Kowalczyk](https://forum.ansible.com/u/Pshem_Kowalczyk)\
**Post date:** [February 26, 2019, 9:40am UTC](https://forum.ansible.com/t/how-to-detect-aws-instance-type/29770/2 "2019-02-26T09:40:34Z")

</div>

Hi,

Depending what you’re after, something like this to figure out the instance type:

- name: determine if we’re on a nitro hypervisor  
set\_fact:  
on\_nitro: “{{ ansible\_ec2\_instance\_type.startswith(‘t3’) or ansible\_ec2\_instance\_type.startswith(‘c5’) or ansible\_ec2\_instance\_type.startswith(‘m5’) or ansible\_ec2\_instance\_type.startswith(‘r5’) }}”

and then use a condition like:

when: on\_nitro

to do the nvme-specific initialisation.

If you want to extract the actual volume id the way to go is to use something like this:  
VOL=$(nvme id-ctrl {{ disk.path }} | grep sn | awk ‘{print $3}’); echo “${VOL/vol/vol-}”

where disk path is something like /dev/nvme1n1, that gives you volume id. If you want the original letters you might have to parse it out of:

nvme id-ctrl /dev/nvme1n1 -v

more details here: [https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/nvme-ebs-volumes.html](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/nvme-ebs-volumes.html)

kind regards  
Pshem
