I am struggling below scenario:
In /etc/default/grub file, there is GRUB_CMDLINE_LINUX_DEFAULT stanza, I need to insert audit=1 at the end of the line if value is not there already (note that there is quote char at the end of line). If audit=0 is present change it to audit=1.
lineinfile ansible module does not work, especially with inserting before last quote (").
Original /etc/default/grub:
GRUB_TIMEOUT=5
GRUB_DEFAULT=saved
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="rootfstype=xfs quiet splash acpi_osi="
Optional /etc/default/grub:
GRUB_TIMEOUT=5
GRUB_DEFAULT=saved
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="rootfstype=xfs quiet splash acpi_osi= audit=0" # change audit=0 to audit=1
#OR:
#GRUB_CMDLINE_LINUX_DEFAULT="rootfstype=xfs quiet splash acpi_osi= audit=1" # audit=1 is already here, so no action needed
Desired /etc/default/grub:
GRUB_TIMEOUT=5
GRUB_DEFAULT=saved
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="rootfstype=xfs quiet splash acpi_osi= audit=1"