I'm trying to create an Ansible task that sets up trim/discards. I have a playbook that takes care of everything else (LVM, fstrim), but I can't figure out how to get crypttab
configured properly.
I'm trying to use the replace module to append discard
to the end of every line that doesn't have discard
present, but I can't seem to get the regex right (I think that's my problem anyway).
I have a /etc/crypttab
file that looks something like this:
luks-nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn UUID=nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn none discard
luks-nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn UUID=nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn none
And here's the task:
- name: ensure crypttab is configured to issue discards
replace: dest=/etc/crypttab backup=yes
regexp='^(.*(?! discard))$'
replace='\1 discard'