# Need help in updating /etc/grub.conf file to disable THP in linux server using Ansible

**URL:** <https://forum.ansible.com/t/need-help-in-updating-etc-grub-conf-file-to-disable-thp-in-linux-server-using-ansible/27529>\
**Category:** Ansible Project\
**Created:** [May 15, 2018, 6:23am UTC](https://forum.ansible.com/t/need-help-in-updating-etc-grub-conf-file-to-disable-thp-in-linux-server-using-ansible/27529 "2018-05-15T06:23:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Padmesh\_Singh](https://avatars.discourse-cdn.com/v4/letter/p/0ea827/32.png) [@Padmesh\_Singh](https://forum.ansible.com/u/Padmesh_Singh)\
**Post date:** [May 15, 2018, 6:23am UTC](https://forum.ansible.com/t/need-help-in-updating-etc-grub-conf-file-to-disable-thp-in-linux-server-using-ansible/27529/1 "2018-05-15T06:23:49Z")

</div>

I need help in updating /etc/grub.conf file to disable THP in Linux servers. I used below Ansible lineinfile module but it updates the kernel line everytime when I run it, I need which runs and updates every line of kernel in /etc/fstab file. Please suggest.

name: disable THP (RedHat)  
&nbsp;&nbsp;lineinfile: dest=/boot/grub/grub.conf  
&nbsp;&nbsp;backup=True  
&nbsp;&nbsp;backrefs=True  
&nbsp;&nbsp;state=present  
&nbsp;&nbsp;regexp='(^\s+kernel(\s+(?!transparent\_hugepage=never)[\w=/\-\.\,\_]+)\*)\s\*$'  
&nbsp;&nbsp;line='\1 transparent\_hugepage=never'

Each time I run the play it will add "transparent\_hugepage=never" to a single line where it is not found, instead of every line that starts with kernel. Please suggest how to update this string in all the line that starts with Kernel.

Thanks

---

<div class="post-metadata">

**Author:** ![Richard\_Hector](https://avatars.discourse-cdn.com/v4/letter/r/db5fbb/32.png) [@Richard\_Hector](https://forum.ansible.com/u/Richard_Hector)\
**Post date:** [May 15, 2018, 6:55am UTC](https://forum.ansible.com/t/need-help-in-updating-etc-grub-conf-file-to-disable-thp-in-linux-server-using-ansible/27529/2 "2018-05-15T06:55:52Z")

</div>

Perhaps you want 'replace' rather than 'lineinfile'? Being careful that  
your regexp doesn't match the line if it's already correct.

Richard

---

<div class="post-metadata">

**Author:** ![Padmesh\_Singh](https://avatars.discourse-cdn.com/v4/letter/p/0ea827/32.png) [@Padmesh\_Singh](https://forum.ansible.com/u/Padmesh_Singh)\
**Post date:** [May 15, 2018, 7:29am UTC](https://forum.ansible.com/t/need-help-in-updating-etc-grub-conf-file-to-disable-thp-in-linux-server-using-ansible/27529/3 "2018-05-15T07:29:03Z")

</div>

Please suggest how to do that.

Thanks
