An Ansible module to map cloud-specific (AWS, GCP, Azure, LibVirt) block device names (e.g. /dev/sdf) with the volume provided to the OS.
lsblk
is run for options: NAME,TYPE,UUID,FSTYPE,MOUNTPOINT,MODEL,SERIAL,SIZE,HCTL (all of which are supported from CentOS7+ and Ubuntu1804+).- NAME is always the OS device name, although in some cases symlinked to a
xvd[\d]
name- For convenience, this is copied to a parameter
device_name_os
- For convenience, this is copied to a parameter
- A parameter
device_name_cloud
is created that relates to the name the cloud gives to the device when it is created.
- On AWS 'nitro' instances all EBS mappings are attached to the NVME controller. The nvme mapping is non-deterministic though, so the script uses ioctl commands to query the nvme controller (from a script by Amazon that is present on 'Amazon Linux' machines:
/sbin/ebsnvme-id
. See documentation: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/nvme-ebs-volumes). - For non-nitro EBS mapping, the script enumerates the mapping in the alphanumerical order of the disk device names. This is the correct order except for some very old RHEL/Centos AMIs, which are not supported.
- For ephemeral volume mapping, it uses the http://169.254.169.254/latest/meta-data/block-device-mapping/ endpoint.
- GCP device names are user-defined, and appear as entries in the
lsblk
SERIAL column (which is copied for consistency todevice_name_cloud
).
- Azure LUNs are user-defined, and appear as the last entry in the
lsblk
HCTL column, (which is copied for consistency todevice_name_cloud
).
- The script can be run as plain
lsblk
command, where the cloud provider does not include a mapping, and will return the information as a dictionary. For example, the bytes mapped to the NAME field could be cross-checked against the requested disk size to create a mapping.
This can be run as an Ansible module (needs root):
- name: Get block device map information for cloud
blockdevmap:
cloud_type: <gcp|aws|azure>
become: true
register: r__blockdevmap
- name: Get lsblk device map information
blockdevmap:
cloud_type: lsblk
become: true
register: r__blockdevmap
- name: debug blockdevmap
debug: msg={{r__blockdevmap}}
or from the console:
python3 ./blockdevmap.py console aws