Reputation: 161
The below playbook works fine, but if i run lsscsi command, /u01 is always LUN 0 (/dev/sdc) and /ora01 should be LUN1 (/dev/sdd) and /data should be LUN2 (/dev/sde). The problem here is sometimes it gets swapped. that is /ora01 will be LUN2 & /data will be LUN1. Please advice on this..
tasks:
- name: vgcreate
lvg:
vg: "{{ item.vgname }}"
pvs: "{{ item.pvsdisk }}"
with_items:
- { vgname: u01, pvsdisk: /dev/sdc }
- { vgname: ora01, pvsdisk: /dev/sdd }
- { vgname: data, pvsdisk: /dev/sde }
- name: lvcreate
lvol:
vg: "{{ item.vgname }}"
lv: "{{ item.lvname }}"
size: 100%VG
with_items:
- { vgname: u01, lvname: lgvol_1 }
- { vgname: ora01, lvname: lgvol_2 }
- { vgname: data, lvname: lgvol_3 }
- name: create file system
filesystem:
fstype: ext4
dev: /dev/{{ item.vgname }}/{{ item.lvname }}
with_items:
- { vgname: u01, lvname: lgvol_1 }
- { vgname: ora01, lvname: lgvol_2 }
- { vgname: data, lvname: lgvol_3 }
- name: mount logical volume
mount:
name: /{{ item.vgname }}
src: /dev/{{ item.vgname }}/{{ item.lvname }}
fstype: ext4
state: mounted
with_items:
- { vgname: u01, lvname: lgvol_1 }
- { vgname: ora01, lvname: lgvol_2 }
- { vgname: data, lvname: lgvol_3 }
Upvotes: 1
Views: 470
Reputation: 7917
It's not Ansible. The problem you encounter is that device names '/dev/sda', etc are not permanent. They are allocated in the order of appearance, so if this order is different, devices are listed with different names. IRL there are even more issues with 'sda' approach, f.e. if some device was disconnected because of error (timeout in case of ISCSI), and then reconnected later, it can gain a new name (f.e. /dev/sdg
). Deeply in kernel internals there going to be /dev/sda (invisible but occupied) and /dev/sdg - the same device with different name.
TL;DR; Do not rely on /dev/sd* notation if order is important for you. Think it as a 'set' of disks with random names assigned.
If you need to choose specific device you need to find invariant (something which device have for sure). Few options:
Some of those identification is possible through /dev/disk/by-*:
Some require very thoughtful search process (probing with identification). You may want to look into output of few tools:
Or even peek into /sys/block and symlinks in each device.
Basically, the problem is almost the same as if some guy randomly plug your drives into some new computer. Which drive is what for?
Upvotes: 1