How to match regex tab?

Hi,

I am running ansible version 1.9. I am using replace module to add parameters to kernel line which starting with a in the grub.conf file

kernel /boot/vmlinuz-2.6.32-573.7.1.el6.x86_64 ro root=UUID=f360dd95-c0e6-49ff-b346-2dce04d6b433 rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us elevator=noop biosdevname=0 LANG=en_AU.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_NO_LVM rd_NO_DM console=ttyS0,115200n8 console=tty0 consoleblank=0 net.ifnames=0

I tried the regexp=“[1]kernel*\n$”, but ansible cannot detect the kernel line, the regexp=“[2]kernel” did not work either. No luck for lineinfile module either. What I could be missing here? Appreciate any clues.

Thank you.

  • j

  1. \t ↩︎

  2. \t ↩︎

Hi j,

Are you sure that that file contains a tab? Or does it just look like a tab, or, is your editor replacing tabs with spaces?

I tried this playbook

Hi Tim,

You are right, it works if I don’t use with_items (something wrong with my following statement). Anyway, the problem now is that rdblacklist=nouveau nouveau.modeset=0 is inserted to the end of file, not the kernel end of line. Is there any way to insert parameters to end of line, or it is impossible to insert things at the end of line in ansible? Sorry, I might have to post in another subject.

  • name “Insert nouveau at the end of the kernel line”
    lineinfile: dest=/boot/grub/grub.conf state=present backrefs=True regexp=“{{ item.regexp }}” line=“{{ item.insert }}”
    with_items:
  • { “regexp”: “[1]kernel”, “insert”: " rdblacklist=nouveau nouveau.modeset=0\n" }
    sudo: true

  1. \t ↩︎

Hey j,

Yes, you can append using the backrefs argument.

Here’s an example I tried on my box that works using an iterator

Hi Tim,

Thank you so much, indeed, that works well, greatly appreciate it.

Cheers.

  • j