I have an ansible playbook that runs for about 20 hosts. I'm trying to edit the pass option only for entries that are mounted as root ('/').
Here's what I had that changes every pass option that isn't '0', which I don't want.
- name: Modify mount options in /etc/fstab
replace:
path: /etc/fstab
regexp: '(\b)0 0(\b)'
replace: '\g<1>0 1\g<2>'
when: ansible_distribution == 'Ubuntu'
ChatGPT suggests something like this but adding my values doesn't work. All of my filesystems have different naming formats so not all start with UUID.
- name: Change pass option
lineinfile:
path: /etc/fstab
regexp: '^UUID=[a-f0-9-]+\s+/\s'
line: 'UUID=your_uuid / ext4 defaults,pass=new_pass_option 0 0'
For example, given the inventory
and the files /tmp/fstab (all the same) for testing
and fetch the files to the controller
This will create the files at the controller
gives
pass=new_pass_optionfor all/in all filesThis will change the file only. If you want to update the current mount point use
state: mounted. See state.Example of a complete playbook for testing