Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - name: Replace fstab entries with gpt partlabel
- shell: |
- set -euo pipefail # strict mode
- INFO=$(blkid | grep "{{ item.1.name }}")
- BYPARTLABEL="/dev/disk/by-partlabel/{{ item.1.name }}"
- DEV=$(echo $INFO | perl -F: -lane 'print $F[0]')
- echo "*** BYPARTLABEL=${BYPARTLABEL}"
- echo "*** DEV=${DEV}"
- grep "${BYPARTLABEL}" /mnt/etc/fstab && {
- echo "OK=partlabel already in fstab"
- } || {
- # if partlabel exists and is a symlink
- [[ -h "${BYPARTLABEL}" ]] && {
- echo "*** ${BYPARTLABEL} exists"
- perl -i -ne '
- BEGIN { $changed=0; }
- if (s|^'"${DEV}"'|'"${BYPARTLABEL}"'|) {
- $changed=1;
- }
- print $_;
- END {
- if ($changed == 1) {
- print STDERR "CHANGED=partlabel changed in fstab\n";
- } else {
- print STDERR "OK\n";
- }
- }
- ' /mnt/etc/fstab
- } || {
- echo "Something went wrong. ${BYPARTLABEL} does not exist or is not a symlink"
- exit 1
- }
- }
- args:
- executable: /bin/bash
- register: partlabels
- changed_when: ( 'CHANGED=partlabel' in partlabels.stderr )
- with_indexed_items: "{{ disk_partitions }}"
- when: ( disk_part_scheme == 'gpt' and fstab_defined_by == 'label' )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement