# How to update or add string at the end of a line

**URL:** <https://forum.ansible.com/t/how-to-update-or-add-string-at-the-end-of-a-line/25525>\
**Category:** Ansible Project\
**Created:** [September 19, 2017, 11:41am UTC](https://forum.ansible.com/t/how-to-update-or-add-string-at-the-end-of-a-line/25525 "2017-09-19T11:41:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![phatak.salil](https://avatars.discourse-cdn.com/v4/letter/p/9fc29f/32.png) [@phatak.salil](https://forum.ansible.com/u/phatak.salil)\
**Post date:** [September 19, 2017, 11:41am UTC](https://forum.ansible.com/t/how-to-update-or-add-string-at-the-end-of-a-line/25525/1 "2017-09-19T11:41:55Z")

</div>

Hello Guys,

I want to add /append a line using anisble .How can this be achieved. I have tried the lineinfile module ,but it dosen’t seem to work .Is there a better way to do that ,Below is what I need to achieve

Regards,  
Salil

---

<div class="post-metadata">

**Author:** ![Soniya\_panwar](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@Soniya\_panwar](https://forum.ansible.com/u/Soniya_panwar)\
**Post date:** [September 21, 2017, 9:52am UTC](https://forum.ansible.com/t/how-to-update-or-add-string-at-the-end-of-a-line/25525/2 "2017-09-21T09:52:33Z")

</div>

Hello

> > Below is what I need to achieve

i think you forgot to give your requirements. if you can provide what exactly you need it will be easy to answer.

you can use blockinfile module if you want to insert/update/remove a block of lines in a file, for more understanding please follow this link: [http://docs.ansible.com/ansible/latest/blockinfile\_module.html](http://docs.ansible.com/ansible/latest/blockinfile_module.html)

or if you want to add a line after any line you can use these settings:

```auto
- lineinfile:
    path: <file path>
    regexp: '^your line '
    insertafter: '^#your line '
    line: 'your line'

```
