# Lineinfile in v1.1

**URL:** <https://forum.ansible.com/t/lineinfile-in-v1-1/12625>\
**Category:** Ansible Project\
**Created:** [April 4, 2013, 3:29am UTC](https://forum.ansible.com/t/lineinfile-in-v1-1/12625 "2013-04-04T03:29:12Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kavin](https://avatars.discourse-cdn.com/v4/letter/k/ba8739/32.png) [@Kavin](https://forum.ansible.com/u/Kavin)\
**Post date:** [April 4, 2013, 3:29am UTC](https://forum.ansible.com/t/lineinfile-in-v1-1/12625/1 "2013-04-04T03:29:12Z")

</div>

Hi,

I followed lineinfile for sometime till will we had backrefs, but latest code seems to have changed so wanted to understand

will this still work if i want to comment a line out ?

```auto
 lineinfile dest=/tmp/grub.conf state=present regexp='^(splashimage=.*)$' line="#"

```

---

<div class="post-metadata">

**Author:** ![PhilEv](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@PhilEv](https://forum.ansible.com/u/PhilEv)\
**Post date:** [April 4, 2013, 7:37am UTC](https://forum.ansible.com/t/lineinfile-in-v1-1/12625/2 "2013-04-04T07:37:13Z")

</div>

with 1.1 you have to

- add backrefs=True when calling lineifile to activate the backrefs as the default is false.

- use double \

so your line should become:

```auto
lineinfile dest=/tmp/grub.conf backrefs=true state=present regexp='^(splashimage=.*)$' line="#\1"

```

HTH

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [April 4, 2013, 7:54am UTC](https://forum.ansible.com/t/lineinfile-in-v1-1/12625/3 "2013-04-04T07:54:50Z")

</div>

​This needs to be added to the docs.

Serge​

---

<div class="post-metadata">

**Author:** ![PhilEv](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@PhilEv](https://forum.ansible.com/u/PhilEv)\
**Post date:** [April 4, 2013, 8:56am UTC](https://forum.ansible.com/t/lineinfile-in-v1-1/12625/4 "2013-04-04T08:56:12Z")

</div>

Seen that being documented in the module code.

My understanding is the doc is being generated from the code, so it is a matter of refresh

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [April 4, 2013, 9:15am UTC](https://forum.ansible.com/t/lineinfile-in-v1-1/12625/5 "2013-04-04T09:15:03Z")

</div>

​Ah, I'm too quick, I already have trouble keeping up with the new  
features​ that are getting published in the docs 🙂

---

<div class="post-metadata">

**Author:** ![PhilEv](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@PhilEv](https://forum.ansible.com/u/PhilEv)\
**Post date:** [April 4, 2013, 9:44am UTC](https://forum.ansible.com/t/lineinfile-in-v1-1/12625/6 "2013-04-04T09:44:24Z")

</div>

fully understand ! same for me

not even mentionning that with backrefs I would like to see lineinfile doing the changes for all the matching lines in the target file and not just the latest 🙂

That would be terrific when used in remediation context.

Phil

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [April 4, 2013, 12:43pm UTC](https://forum.ansible.com/t/lineinfile-in-v1-1/12625/7 "2013-04-04T12:43:11Z")

</div>

"not even mentionning that with backrefs I would like to see  
lineinfile doing the changes for all the matching lines in the target  
file and not just the latest :-)"

At this point, it seems like you should just run sed against the file.

---

<div class="post-metadata">

**Author:** ![PhilEv](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@PhilEv](https://forum.ansible.com/u/PhilEv)\
**Post date:** [April 4, 2013, 12:58pm UTC](https://forum.ansible.com/t/lineinfile-in-v1-1/12625/8 "2013-04-04T12:58:51Z")

</div>

Yeap, considering this at the moment.

as patching lineinfile to replace all matching lines make sense only when using backrefs=True,

and would require significant change to the lineinfile module.

Or just come with a new linesinfile module just for this (note the additional ‘s’ in middle of the name)

thanks

Phil.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [April 4, 2013, 1:01pm UTC](https://forum.ansible.com/t/lineinfile-in-v1-1/12625/9 "2013-04-04T13:01:09Z")

</div>

The change of code isn’t the concern, but rather the purpose of the module is to make sure a given _line_ is in a file or not.

Thus I think it would be confusing if it did global replacements, as that is not the purpose of the module.

---

<div class="post-metadata">

**Author:** ![PhilEv](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@PhilEv](https://forum.ansible.com/u/PhilEv)\
**Post date:** [April 4, 2013, 1:43pm UTC](https://forum.ansible.com/t/lineinfile-in-v1-1/12625/10 "2013-04-04T13:43:50Z")

</div>

understood and agree

---

<div class="post-metadata">

**Author:** ![Marco\_Vito\_Moscarito](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@Marco\_Vito\_Moscarito](https://forum.ansible.com/u/Marco_Vito_Moscarito)\
**Post date:** [April 4, 2013, 4:00pm UTC](https://forum.ansible.com/t/lineinfile-in-v1-1/12625/11 "2013-04-04T16:00:43Z")

</div>

You can find update docs from code at [http://docs.ansible.agavee.com/](http://docs.ansible.agavee.com/)

Docs rebuild run each day

PDF + HTML + ebook will be relase ASAP.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [April 5, 2013, 9:04pm UTC](https://forum.ansible.com/t/lineinfile-in-v1-1/12625/12 "2013-04-05T21:04:41Z")

</div>

Ok, so absolute requirements for this is it must run from ‘make webdocs’.

It’s not acceptable for them to be hosted on an external site because then they can’t be accessed offline, nor is it easy to contribute to changes to the way the docs are presented.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [April 5, 2013, 11:43pm UTC](https://forum.ansible.com/t/lineinfile-in-v1-1/12625/13 "2013-04-05T23:43:30Z")

</div>

​Philippe,​

> "not even mentionning that with backrefs I would like to see  
> lineinfile doing the changes for all the matching lines in the target  
> file and not just the latest :-)"
> 
> At this point, it seems like you should just run sed against the file.

​As an excercise I started writing a simple plugin in Bash, here as a  
wrapper to "sed -e 's/regexp/replace/':

[https://github.com/sergevanginderachter/ansible-modules/blob/f01856c43cfb76bf4cf8e0ac61d02c5091b2ffc4/seds](https://github.com/sergevanginderachter/ansible-modules/blob/f01856c43cfb76bf4cf8e0ac61d02c5091b2ffc4/seds)

I tried to write the bash functions as modular as possible. I hope this  
might also evolve to a better boilerplate for bash modules 🙂

&nbsp;&nbsp;Serge  
.

---

<div class="post-metadata">

**Author:** ![PhilEv](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@PhilEv](https://forum.ansible.com/u/PhilEv)\
**Post date:** [April 6, 2013, 8:02am UTC](https://forum.ansible.com/t/lineinfile-in-v1-1/12625/14 "2013-04-06T08:02:12Z")

</div>

Cool !

will have a look an try in the coming days

Phil

---

<div class="post-metadata">

**Author:** ![Marco\_Vito\_Moscarito](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@Marco\_Vito\_Moscarito](https://forum.ansible.com/u/Marco_Vito_Moscarito)\
**Post date:** [April 6, 2013, 8:36am UTC](https://forum.ansible.com/t/lineinfile-in-v1-1/12625/15 "2013-04-06T08:36:20Z")

</div>

It is build from webdocs (make modulejs generate JS required in  
angular, code improvement are WIP). Myjenkis build just:

git update  
make modulejs  
mv docs/js/modules.js $WEBFOLDER

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [April 6, 2013, 6:24pm UTC](https://forum.ansible.com/t/lineinfile-in-v1-1/12625/16 "2013-04-06T18:24:25Z")

</div>

Ok, great, I’ll test shortly.

I would like this to become the default.

I think the next thing to do is probably to make a ‘category’ field in the DOCUMENTATION string such that it can sort or filter by category, and also (if not already to support the EXAMPLES documentation string).

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [April 6, 2013, 6:24pm UTC](https://forum.ansible.com/t/lineinfile-in-v1-1/12625/17 "2013-04-06T18:24:57Z")

</div>

BTW, a pull request to make that part of “make webdocs” seems like a good idea 🙂

---

<div class="post-metadata">

**Author:** ![Marco\_Vito\_Moscarito](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@Marco\_Vito\_Moscarito](https://forum.ansible.com/u/Marco_Vito_Moscarito)\
**Post date:** [April 7, 2013, 9:03am UTC](https://forum.ansible.com/t/lineinfile-in-v1-1/12625/18 "2013-04-07T09:03:48Z")

</div>

> Ok, great, I'll test shortly.

Nice!

> I would like this to become the default.

Maybe this is not the best solution, web spider do not find data in  
page, and don't execute HTML. I'm also working on a HTML page  
generation (separate html fragment for each module) to make possibile  
ajax crowlong ¹, this is partially working (on my local machine,  
sorry) but I need to find some days to refactor Ansible interface  
before make it public.

> I think the next thing to do is probably to make a 'category' field in the  
> DOCUMENTATION string such that it can sort or filter by category, and also  
> (if not already to support the EXAMPLES documentation string).

Add support to EXAMPLES can be easy to add, but I'm not sure if it can  
add in UI (parser can just consider all text as code, so have a wrong  
impact on page presentation).

Filter by category will add ASAP (when all module have category), in  
Issue #2194 I suggest to use "tags" inside "category" to have multiple  
tagging capabilities (eg: user, database, mysql) and make possible  
have "faceted search" on content... if you are agree i will work on  
this feature in the next weeks (category/tag + module tagging).

Now I'm working on coding standard in documentation fragment (as  
descrbed in a old mail).

Bye  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Marco

¹ [https://developers.google.com/webmasters/ajax-crawling/docs/specification](https://developers.google.com/webmasters/ajax-crawling/docs/specification)

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [April 7, 2013, 3:43pm UTC](https://forum.ansible.com/t/lineinfile-in-v1-1/12625/19 "2013-04-07T15:43:04Z")

</div>

Tags instead of category seems great, as for examples could we not  
just turn a new line into a BR tag?

-- Michael

---

<div class="post-metadata">

**Author:** ![Marco\_Vito\_Moscarito](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@Marco\_Vito\_Moscarito](https://forum.ansible.com/u/Marco_Vito_Moscarito)\
**Post date:** [April 7, 2013, 4:43pm UTC](https://forum.ansible.com/t/lineinfile-in-v1-1/12625/20 "2013-04-07T16:43:41Z")

</div>

> Tags instead of category seems great, as for examples could we not  
> just turn a new line into a BR tag?

What? Have all examples without \<pre\>/\<code\> tag? Having code without  
monospace font I think make docs inusable, have all text with  
monospace font mate text less readable. Having not separation in  
examples make (in my opinion) documentation a mess of text.

> -- Michael

Bye  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Marco

[Next page](https://forum.ansible.com/t/lineinfile-in-v1-1/12625.md?page=2)
