2012-08-30 04:13:12 +02:00
.. _lineinfile:
lineinfile
2012-09-28 14:21:33 +02:00
`` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ``
2012-08-30 04:13:12 +02:00
2012-08-31 00:50:10 +02:00
.. versionadded :: 0.7
2012-09-28 03:33:55 +02:00
This module will search a file for a line, and ensure that it is present or absent.
This is primarily useful when you want to change a single line in a file only. For other cases, see the `` copy `` or `` template `` modules.
.. raw :: html
<table>
<tr>
2012-09-28 14:21:33 +02:00
<th class="head">parameter</th>
<th class="head">required</th>
<th class="head">default</th>
<th class="head">choices</th>
<th class="head">comments</th>
2012-09-28 03:33:55 +02:00
</tr>
2012-10-04 02:58:27 +02:00
<tr>
2012-09-28 03:33:55 +02:00
<td>state</td>
2012-10-04 02:58:27 +02:00
<td>no</td>
2012-09-28 03:33:55 +02:00
<td>present</td>
<td><ul><li>present</li><li>absent</li></ul></td>
<td>Whether the line should be there or not.</td>
</tr>
2012-10-04 02:58:27 +02:00
<tr>
2012-09-28 03:33:55 +02:00
<td>name</td>
2012-10-04 02:58:27 +02:00
<td>yes</td>
2012-09-28 03:33:55 +02:00
<td></td>
<td><ul></ul></td>
<td>The file to modify</td>
</tr>
2012-10-04 02:58:27 +02:00
<tr>
2012-09-28 03:33:55 +02:00
<td>insertafter</td>
2012-10-04 02:58:27 +02:00
<td>no</td>
2012-09-28 03:33:55 +02:00
<td>EOF</td>
<td><ul><li>BOF</li><li>EOF</li></ul></td>
2012-10-04 02:58:27 +02:00
<td>Used with <code>state=present</code>. If specified, the line will be inserted after the specified regular expression. Two special values are available; <code>BOF</code> for inserting the line at the beginning of the file, and <code>EOF</code> for inserting the line at the end of the file.</td>
2012-09-28 03:33:55 +02:00
</tr>
2012-10-04 02:58:27 +02:00
<tr>
2012-09-28 03:33:55 +02:00
<td>regexp</td>
2012-10-04 02:58:27 +02:00
<td>yes</td>
2012-09-28 03:33:55 +02:00
<td></td>
<td><ul></ul></td>
2012-10-04 02:58:27 +02:00
<td>The regular expression to look for in the file. For <code>state=present</code>, the pattern to replace. For <code>state=absent</code>, the pattern of the line to remove.</td>
2012-09-28 03:33:55 +02:00
</tr>
2012-10-04 02:58:27 +02:00
<tr>
2012-09-28 03:33:55 +02:00
<td>line</td>
2012-10-04 02:58:27 +02:00
<td>no</td>
2012-09-28 03:33:55 +02:00
<td></td>
<td><ul></ul></td>
2012-10-04 02:58:27 +02:00
<td>Required for <code>state=present</code>. The line to insert/replace into the file. Must match the value given to <code>regexp</code>.</td>
2012-09-28 03:33:55 +02:00
</tr>
2012-10-04 02:58:27 +02:00
<tr>
2012-09-28 03:33:55 +02:00
<td>backup</td>
2012-10-04 02:58:27 +02:00
<td>no</td>
<td></td>
2012-09-28 03:33:55 +02:00
<td><ul></ul></td>
<td>Create a backup file including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly.</td>
</tr>
2012-10-04 02:58:27 +02:00
</table>
2012-09-28 03:33:55 +02:00
.. raw :: html
2012-10-04 02:58:27 +02:00
<p><pre>
lineinfile name=/etc/selinux/config regexp=^SELINUX= line=SELINUX=disabled
</pre></p>
<p><pre>
lineinfile name=/etc/sudoers state=absent regexp="^%wheel"
</pre></p>
2012-09-28 03:33:55 +02:00
<br/>
2012-08-31 00:42:45 +02:00