daily pastebin goal
28%
SHARE
TWEET

Untitled

a guest Feb 21st, 2018 15 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - name: Replace fstab entries with gpt partlabel
  2.   shell: |
  3.    set -euo pipefail # strict mode
  4.  
  5.     INFO=$(blkid | grep "{{ item.1.name }}")
  6.     BYPARTLABEL="/dev/disk/by-partlabel/{{ item.1.name }}"
  7.     DEV=$(echo $INFO | perl -F: -lane 'print $F[0]')
  8.     echo "*** BYPARTLABEL=${BYPARTLABEL}"
  9.     echo "*** DEV=${DEV}"
  10.  
  11.     grep "${BYPARTLABEL}" /mnt/etc/fstab && {
  12.       echo "OK=partlabel already in fstab"
  13.     } || {
  14.  
  15.       # if partlabel exists and is a symlink
  16.       [[ -h "${BYPARTLABEL}" ]] && {
  17.         echo "*** ${BYPARTLABEL} exists"
  18.  
  19.         perl -i -ne '    
  20.           BEGIN { $changed=0; }
  21.  
  22.           if (s|^'"${DEV}"'|'"${BYPARTLABEL}"'|) {
  23.             $changed=1;
  24.           }
  25.  
  26.           print $_;
  27.  
  28.           END {
  29.             if ($changed == 1) {
  30.               print STDERR "CHANGED=partlabel changed in fstab\n";
  31.             } else {
  32.               print STDERR "OK\n";
  33.             }
  34.           }
  35.         ' /mnt/etc/fstab
  36.  
  37.       } || {
  38.         echo "Something went wrong.  ${BYPARTLABEL} does not exist or is not a symlink"
  39.         exit 1
  40.       }
  41.     }
  42.  
  43.   args:
  44.     executable: /bin/bash
  45.   register: partlabels
  46.   changed_when: ( 'CHANGED=partlabel' in partlabels.stderr )
  47.   with_indexed_items: "{{ disk_partitions }}"
  48.   when: ( disk_part_scheme == 'gpt' and fstab_defined_by == 'label' )
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top