# lineinfile append to line?

**URL:** <https://forum.ansible.com/t/lineinfile-append-to-line/26050>\
**Category:** Ansible Project\
**Created:** [November 16, 2017, 9:42pm UTC](https://forum.ansible.com/t/lineinfile-append-to-line/26050 "2017-11-16T21:42:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![LeamHall](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/leamhall/32/9390_2.png) [@LeamHall](https://forum.ansible.com/u/LeamHall)\
**Post date:** [November 16, 2017, 9:42pm UTC](https://forum.ansible.com/t/lineinfile-append-to-line/26050/1 "2017-11-16T21:42:19Z")

</div>

Trying to edit grub.conf and add a phrase to the kernel lines.

**Sample stanza:**

| 

title CentOS (2.6.32-696.13.2.el6.x86\_64)

 |
|
| |

| 

root (hd0,0)

 |
|
| |

| 

kernel /vmlinuz-2.6.32-696.13.2.el6.x86\_64 ro root=/dev/mapper/vg\_root-lv\_root rd\_NO\_LUKS rd\_LVM\_LV=vg\_root/lv\_root LANG=en\_US.UTF-8 rd\_NO\_MD SYSFONT=latarcyrheb-sun16 console=ttyS0,115200n8 rd\_LVM\_LV=vg\_root/lv\_swap KEYBOARDTYPE=pc KEYTABLE=us crashkernel=auto rhgb quiet rd\_NO\_DM

 |
|
| |

initrd /initramfs-2.6.32-696.13.2.el6.x86\_64.img

Ansible playbook stanza that’s not working:

| 
- name: edit\_grub\_conf

 |
|
| |

| 

lineinfile:

 |
|
| |

| 

path: “/tmp/grub.conf”

 |
|
| |

| 

regexp: “^kernel(.\*)?”

 |
|
| |

| 

line: ‘kernel\1 transparent\_hugepage=never’

 |
|
| |

| 

state: present

 |
|
| |

| 

backrefs: true

 |
|
| |

mode: 0666

Error reported:

| 

TASK [edit\_grub\_conf] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

 |
|
| |

fatal: [leviticus]: FAILED! =\> {"changed": false, "failed": true, "module\_stderr": "Shared connection to leviticus closed.\r\n", "module\_stdout": "Traceback (most recent call last):\r\n File \"/tmp/ansible\_PUtMtv/ansible\_module\_lineinfile.py\", line 470, in \r\n main()\r\n File \"/tmp/ansible\_PUtMtv/ansible\_module\_lineinfile.py\", line 462, in main\r\n ins\_aft, ins\_bef, create, backup, backrefs)\r\n File \"/tmp/ansible\_PUtMtv/ansible\_module\_lineinfile.py\", line 261, in present\r\n bre\_m = re.compile(to\_bytes(regexp, errors='surrogate\_or\_strict'))\r\n File \"/usr/lib64/python2.6/re.py\", line 190, in compile\r\n return \_compile(pattern, flags)\r\n File \"/usr/lib64/python2.6/re.py\", line 245, in \_compile\r\n raise error, v # invalid expression\r\nsre\_constants.error: nothing to repeat\r\n", "msg": "MODULE FAILURE", "rc": 0}

What am I missing?

Thanks!

Leam

---

<div class="post-metadata">

**Author:** ![LeamHall](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/leamhall/32/9390_2.png) [@LeamHall](https://forum.ansible.com/u/LeamHall)\
**Post date:** [November 17, 2017, 10:22am UTC](https://forum.ansible.com/t/lineinfile-append-to-line/26050/2 "2017-11-17T10:22:26Z")

</div>

Interesting. I read [http://www.mydailytutorials.com/ansible-lineinfile-module-examples/](http://www.mydailytutorials.com/ansible-lineinfile-module-examples/) and used the example as a starting point. Found out lineinfile only works on one line in the file, not all of them. And just the last one.
