Reputation: 811
You can insert a line at the end of a file or before/after some regex with lineinfile
. But how do I insert a line at the start of a file?
Upvotes: 8
Views: 12524
Reputation: 68639
From the link to the module manual you included in the question:
insertbefore
Used withstate=present
. If specified, the line will be inserted before the last match of specified regular expression. A value is available;BOF
for inserting the line at the beginning of the file. If specified regular expression has no matches, the line will be inserted at the end of the file. May not be used withbackrefs
.
So:
- lineinfile:
path: path/to/file
insertbefore: BOF
line: my_line
Upvotes: 15