* New: support mitigation for aws ec2 nvme random device name assignment

This commit is contained in:
Roxyrob
2021-03-16 19:41:37 +01:00
parent f1a54639c6
commit 34e4f08c31
5 changed files with 90 additions and 0 deletions

View File

@@ -61,3 +61,12 @@ lvm_groups: []
# Defines if LVM will be managed by role
# default is false to ensure nothing is changed by accident.
manage_lvm: false
### nvme to scsi device name map binary helper
ebsnvme_binary_helper_ver: '0.1.3'
ebsnvme_binary_helper_tmp: '/tmp'
ebsnvme_binary_helper_path: '/sbin/go-ebsnvme'
### nvme to scsi device name map script helper
ebsnvme_scrip_helper_path: '/usr/local/bin/ebsnvme-id'

View File

@@ -5,6 +5,65 @@
state: present
become: true
- name: centos | check for nvme devices
shell: cat /proc/partitions |awk '{print $4}' | grep -q nvme. ; echo $?
register: blkdev_nvme
changed_when: false
- name: centos | check for amazon ebs devices
shell: lsblk -O -J| grep -qi "amazon elastic block store" ; echo $?
register: blkdev_awsebs
changed_when: false
- name: centos | set flag for nvme subsystem
set_fact:
device_is_nvme: "{{ true if (blkdev_nvme.stdout == '0') else false }}"
- name: centos | set flag for aws ebs devices
set_fact:
device_is_awsebs: "{{ true if (blkdev_awsebs.stdout == '0') else false }}"
- name: Block to map renamed ec2 ebs nvmeXnY devices to their original sdX/xvdX names
when: device_is_nvme and device_is_awsebs|bool
become: true
block:
- name: centos | download nvme mapping binary helper
get_url:
url: "{{ ebsnvme_binary_helper_url }}"
dest: "{{ ebsnvme_binary_helper_tmp }}/"
changed_when: false
- name: centos | extract binary helper
unarchive:
src: "{{ ebsnvme_binary_helper_tmp }}/{{ ebsnvme_binary_helper_file }}"
dest: "{{ ebsnvme_binary_helper_tmp }}/"
remote_src: yes
changed_when: false
- name: centos | copy binary helper
copy:
src: "{{ ebsnvme_binary_helper_tmp }}/go-ebsnvme"
dest: "{{ ebsnvme_binary_helper_path }}"
mode: a+x
remote_src: yes
- name: centos | template script helper
template:
src: 'ebsnvme-id.j2'
dest: "{{ ebsnvme_scrip_helper_path }}"
mode: a+x
- name: centos | template udev rule
template:
src: '70-ec2-nvme-devices.rules.j2'
dest: '/etc/udev/rules.d/70-ec2-nvme-devices.rules'
register: udev_rule
- name: centos | reload and trigger udev rules
shell:
cmd: udevadm control --reload-rules && udevadm trigger
when: udev_rule.changed
- name: centos | installing sg3_utils
package:
name: sg3_utils

View File

@@ -0,0 +1,3 @@
# ebs nvme to scsi device naming mapping
KERNEL=="nvme[0-9]*n[0-9]*", ENV{DEVTYPE}=="disk", ATTRS{model}=="Amazon Elastic Block Store", PROGRAM="{{ ebsnvme_scrip_helper_path }} /dev/%k", SYMLINK+="%c"

15
templates/ebsnvme-id.j2 Normal file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
# This script uses go version of ebsnvme-id to provide
# SCSI Disk device name links for nvme devices
#
# links:
#
# https://www.logicworks.com/blog/2018/03/manage-aws-ebs-volumes-c5-m5-puppet-chef-ansible/
# https://github.com/mvisonneau/go-ebsnvme
# https://gist.github.com/lbernail/d851e5b06eb32180a4b8ead2ce4f45db
# and working forks like:
# (keenan-v1/ebsnvme-id) https://gist.github.com/keenan-v1/aee92cd7383ee02de2a817a004917a03
#
{{ ebsnvme_binary_helper_path }} -n $1 | awk -F '/' '{print $3}'

View File

@@ -1,2 +1,6 @@
---
# vars file for ansible-manage-lvm
ebsnvme_binary_helper_file: go-ebsnvme_{{ ebsnvme_binary_helper_ver }}_linux_amd64.tar.gz
ebsnvme_binary_helper_url: https://github.com/mvisonneau/go-ebsnvme/releases/download/{{ ebsnvme_binary_helper_ver }}/{{ ebsnvme_binary_helper_file }}