How to detect AWS instance type

9 views
Skip to first unread message

Frank Dias

unread,
Feb 25, 2019, 11:56:48 PM2/25/19
to Ansible Project
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?

Pshem Kowalczyk

unread,
Feb 26, 2019, 4:40:56 AM2/26/19
to Ansible Project
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 


kind regards
Pshem


--
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/92c7d8a0-ad32-4120-a9b5-3a3bf0f7c438%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages