# Append {{item}} to existing line

**URL:** <https://forum.ansible.com/t/append-item-to-existing-line/25486>\
**Category:** Ansible Project\
**Created:** [September 14, 2017, 4:25pm UTC](https://forum.ansible.com/t/append-item-to-existing-line/25486 "2017-09-14T16:25:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [September 14, 2017, 4:25pm UTC](https://forum.ansible.com/t/append-item-to-existing-line/25486/1 "2017-09-14T16:25:28Z")

</div>

I need to update the grub.conf, for example, with some custom parameters. The kernel line in the grub.conf will vary on each server; therefore, I just wish to append to the line if it doesn’t already contain the parameter. Can this appending be done with lineinfile or some other module? Any examples?

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [September 14, 2017, 9:53pm UTC](https://forum.ansible.com/t/append-item-to-existing-line/25486/2 "2017-09-14T21:53:48Z")

</div>

Turns out someone already did this. You can do it with a monster regexp, which I wont even to pretend to understand.

I found out someone had exactly what I needed on ansible-galaxy. I downloaded it and call the role. WORKS PERFECTLY!  
[https://galaxy.ansible.com/jtyr/grub\_cmdline/](https://galaxy.ansible.com/jtyr/grub_cmdline/)

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [September 14, 2017, 9:54pm UTC](https://forum.ansible.com/t/append-item-to-existing-line/25486/3 "2017-09-14T21:54:22Z")

</div>

I should also note that if going the regexp route you need backrefs enabled (for lineinfile)
