# How to match regex tab?

**URL:** <https://forum.ansible.com/t/how-to-match-regex-tab/20014>\
**Category:** Ansible Project\
**Created:** [December 15, 2015, 4:13am UTC](https://forum.ansible.com/t/how-to-match-regex-tab/20014 "2015-12-15T04:13:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hce](https://avatars.discourse-cdn.com/v4/letter/h/c0e974/32.png) [@hce](https://forum.ansible.com/u/hce)\
**Post date:** [December 15, 2015, 4:13am UTC](https://forum.ansible.com/t/how-to-match-regex-tab/20014/1 "2015-12-15T04:13:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tim1](https://avatars.discourse-cdn.com/v4/letter/t/b782af/32.png) [@Tim1](https://forum.ansible.com/u/Tim1)\
**Post date:** [December 15, 2015, 5:56am UTC](https://forum.ansible.com/t/how-to-match-regex-tab/20014/2 "2015-12-15T05:56:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hce](https://avatars.discourse-cdn.com/v4/letter/h/c0e974/32.png) [@hce](https://forum.ansible.com/u/hce)\
**Post date:** [December 15, 2015, 10:07am UTC](https://forum.ansible.com/t/how-to-match-regex-tab/20014/3 "2015-12-15T10:07:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tim1](https://avatars.discourse-cdn.com/v4/letter/t/b782af/32.png) [@Tim1](https://forum.ansible.com/u/Tim1)\
**Post date:** [December 17, 2015, 4:57am UTC](https://forum.ansible.com/t/how-to-match-regex-tab/20014/4 "2015-12-17T04:57:09Z")

</div>

Hey j,

Yes, you can append using the backrefs argument.

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

---

<div class="post-metadata">

**Author:** ![hce](https://avatars.discourse-cdn.com/v4/letter/h/c0e974/32.png) [@hce](https://forum.ansible.com/u/hce)\
**Post date:** [December 21, 2015, 1:39am UTC](https://forum.ansible.com/t/how-to-match-regex-tab/20014/5 "2015-12-21T01:39:15Z")

</div>

Hi Tim,

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

Cheers.

- j
