# remapping fstab entries from LABEL to UUID --- how?

**URL:** <https://forum.ansible.com/t/remapping-fstab-entries-from-label-to-uuid-how/20945>\
**Category:** Ansible Project\
**Created:** [March 21, 2016, 3:18pm UTC](https://forum.ansible.com/t/remapping-fstab-entries-from-label-to-uuid-how/20945 "2016-03-21T15:18:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dayton\_Jones](https://avatars.discourse-cdn.com/v4/letter/d/22d042/32.png) [@Dayton\_Jones](https://forum.ansible.com/u/Dayton_Jones)\
**Post date:** [March 21, 2016, 3:18pm UTC](https://forum.ansible.com/t/remapping-fstab-entries-from-label-to-uuid-how/20945/1 "2016-03-21T15:18:21Z")

</div>

I’m trying to read fstab and update any entry that uses “LABEL=” to use the UUID instead…

I can get the proper UUID mappings, but I can’t seem to wrap my head around the actual replacement…

playbook:

- name: Gather UUID mappings  
shell: “blkid -s UUID -o value -t LABEL={{item}}”  
with\_items:

- “/home”

- “/var”

- “/”  
ignore\_errors: true  
register: “UUID”

- name: Convert fstab LABEL entries to UUID format  
replace:  
dest=/etc/fstab  
regexp=‘LABEL={{ item }}’  
replace=‘UUID={{UUID.item}}’  
backup=yes  
with\_items:

- “/”

- “/home”

- “/var”

For the highlighted lines, what should I be using - or is there a better way (I’ve looked at the mount module, but didn’t see a way to do this)

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [March 21, 2016, 5:16pm UTC](https://forum.ansible.com/t/remapping-fstab-entries-from-label-to-uuid-how/20945/2 "2016-03-21T17:16:49Z")

</div>

The issue is that with\_ loops puts results in a list, under ‘results’ key, so `UUID.item` won’t work, you need an index that matches, this might help.

[http://docs.ansible.com/ansible/playbooks\_loops.html#looping-over-a-list-with-an-index](http://docs.ansible.com/ansible/playbooks_loops.html#looping-over-a-list-with-an-index)

---

<div class="post-metadata">

**Author:** ![Uditha\_Desilva](https://avatars.discourse-cdn.com/v4/letter/u/f475e1/32.png) [@Uditha\_Desilva](https://forum.ansible.com/u/Uditha_Desilva)\
**Post date:** [March 21, 2016, 5:21pm UTC](https://forum.ansible.com/t/remapping-fstab-entries-from-label-to-uuid-how/20945/3 "2016-03-21T17:21:49Z")

</div>

I would suggest just getting the whole output of “blkid”, then filtering the lines you want with the “search” filter, and then using “regex\_replace” to get the bits you want, and finally passing those to the replace module.

Be aware, however, that “LABEL=/” is likely to match everything, so you probably want to put some whitespace around the regex.
