# AWS : determine EBS volume physical name in order to format it

**URL:** <https://forum.ansible.com/t/aws-determine-ebs-volume-physical-name-in-order-to-format-it/2510>\
**Category:** Get Help\
**Tags:** playbook, aws, collections\
**Created:** [November 22, 2023, 9:00am UTC](https://forum.ansible.com/t/aws-determine-ebs-volume-physical-name-in-order-to-format-it/2510 "2023-11-22T09:00:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![olafkewl](https://avatars.discourse-cdn.com/v4/letter/o/cab0a1/32.png) [@olafkewl](https://forum.ansible.com/u/olafkewl)\
**Post date:** [November 22, 2023, 9:00am UTC](https://forum.ansible.com/t/aws-determine-ebs-volume-physical-name-in-order-to-format-it/2510/1 "2023-11-22T09:00:26Z")

</div>

Here’s my situation : I’m working on different type of EC2 that will always have extra disks attached that I need to format and mount.  
Depending on the EC2 architecture, disk will appear as xdX or nvmeX (X is not even ordered)  
Let’s say I have an extra volume dedicated to DATA and identified as “vol-02a758d5dd2b3f387” by AWS.  
Ansible fact shows this way :

```auto
"ansible_device_links": {
            "ids": {
                "nvme3n1": [
                    "nvme-Amazon_Elastic_Block_Store_vol02a758d5dd2b3f387",
                    "nvme-nvme.1d0f-766f6c3032613735386435646432623366333837-416d617a6f6e20456c617374696320426c6f636b2053746f7265-00000001"
                ]

```

Great, but the info I want is “nvme3n1”, how can I determine this ID only with the AWS EBS volume ID ?

---

<div class="post-metadata">

**Author:** ![jrglynn2](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jrglynn2](https://forum.ansible.com/u/jrglynn2)\
**Post date:** [November 22, 2023, 3:21pm UTC](https://forum.ansible.com/t/aws-determine-ebs-volume-physical-name-in-order-to-format-it/2510/2 "2023-11-22T15:21:05Z")

</div>

Have you tried [amazon.aws.ec2\_vol\_info module – Gather information about EC2 volumes in AWS — Ansible Documentation](https://docs.ansible.com/ansible/latest/collections/amazon/aws/ec2_vol_info_module.html)? Looks like in the examples that it can gather info when you provide a `volume-id`…

---

<div class="post-metadata">

**Author:** ![olafkewl](https://avatars.discourse-cdn.com/v4/letter/o/cab0a1/32.png) [@olafkewl](https://forum.ansible.com/u/olafkewl)\
**Post date:** [November 22, 2023, 4:00pm UTC](https://forum.ansible.com/t/aws-determine-ebs-volume-physical-name-in-order-to-format-it/2510/3 "2023-11-22T16:00:24Z")

</div>

Yes, I did and it does give a lot a info but not the one I want.  
The craziest is when you attache a EBS volume to a EC2, you can supply a “device” value such as “/dev/sdX” but on the EC2 it will never show with this id, it arrvies as “/dev/nvmeXn1” → This is the value I want in order to format it.

I can retrieve this “device” information through the anazon.aws.ec2\_vol\_info module :

```json
"attachment_set": [
                    {
                        "attach_time": "2023-11-21T16:08:01+00:00",
                        "delete_on_termination": false,
                        "device": "/dev/sdf",
                        "instance_id": "i-XXXXXXXXXXXX",
                        "status": "attached"
                    }

```

But it’s useless for me because it does not appear this way on the system…

---

<div class="post-metadata">

**Author:** ![flowerysong](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/flowerysong/32/2305_2.png) [@flowerysong](https://forum.ansible.com/u/flowerysong)\
**Post date:** [November 22, 2023, 4:40pm UTC](https://forum.ansible.com/t/aws-determine-ebs-volume-physical-name-in-order-to-format-it/2510/4 "2023-11-22T16:40:10Z")

</div>

Do you actually need that information, or do you just need a path you can use to format and mount it?

Either way, `/dev/disk/by-id` is probably the easiest way to go.

```yaml
- hosts: localhost
  vars:
    ebs_id: vol0f4f7e914b7f7f53c
  tasks:
    - name: Format with XFS
      filesystem:
        dev: /dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_{{ ebs_id }}
        fstype: xfs
        force: false

    - name: Mount on /home
      ansible.posix.mount:
        name: /home
        src: /dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_{{ ebs_id }}
        fstype: xfs
        state: mounted

    - name: Figure out the pretty name for the volume
      ansible.builtin.stat:
        path: /dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_{{ ebs_id }}
      register: result

    - debug:
        msg: "{{ ebs_id }} is {{ result.stat.lnk_source }}"

```

```auto
PLAY [localhost] ***************************************************************

TASK [Format with XFS] *********************************************************
ok: [localhost]

TASK [Mount on /home] **********************************************************
ok: [localhost]

TASK [Figure out the pretty name for the volume] *******************************
ok: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =>
    msg: vol0f4f7e914b7f7f53c is /dev/nvme2n1

```

You can also install [amazon-ec2-utils](https://github.com/amazonlinux/amazon-ec2-utils) if you want the device names specified on attachment to actually be created.

---

<div class="post-metadata">

**Author:** ![olafkewl](https://avatars.discourse-cdn.com/v4/letter/o/cab0a1/32.png) [@olafkewl](https://forum.ansible.com/u/olafkewl)\
**Post date:** [November 23, 2023, 9:27am UTC](https://forum.ansible.com/t/aws-determine-ebs-volume-physical-name-in-order-to-format-it/2510/5 "2023-11-23T09:27:56Z")

</div>

thanks so much, this is exactly what I wanted to do and I did not look on this side !!!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [December 23, 2023, 9:28am UTC](https://forum.ansible.com/t/aws-determine-ebs-volume-physical-name-in-order-to-format-it/2510/6 "2023-12-23T09:28:03Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
