How to update a line in /etc/default/grub using Ansible from ->
GRUB_CMDLINE_LINUX="audit=1 crashkernel=auto rhgb quiet"
to
GRUB_CMDLINE_LINUX="audit=1 crashkernel=auto rhgb quiet console=ttyS0,1100"
I tried the following -
- name: Updating of GRUB_CMDLINE_LINUX
lineinfile:
path: "/etc/default/grub"
regexp: "^(.*GRUB_CMDLINE_LINUX.*)$"
line: '\1 console=ttyS0,1100"'
but it just added console=ttyS0,1100" to the end of sentence leading to an extra " (from the existing sentence).
quiet" console=ttyS0,1100"
Any help?
In order to get at the commandline, use this regex to digest to the input:
This now gives you the actual value in
\1, so you can write the output as:Of course, you have to escape the double quotes properly for the format of the file you have there.