I am playing with lineinfile
target file before
1 line 1
2 line 2
3 line 3
4 line 4
5 line 5
6 byebye
My playboook
---
- name: insert multi-line something
hosts: "{{ targets | default('postgres') }}"
tasks:
- name: Insert multi-line content into a file
lineinfile:
path: /home/postgres/somefile_231011
regexp: '^line 3'
line: |
this is my
multi line
content
become: true
become_user: postgres
target after 1st run
(as expected)
1 line 1
2 line 2
3 this is my
4 multi line
5 content
6 line 4
7 line 5
8 byebye
target file after second run
(this should be identical from the above, but adds my 3 lines plus an additional empty line at the bottom)
1 line 1
2 line 2
3 this is my
4 multi line
5 content
6 line 4
7 line 5
8 byebye
9 this is my
10 multi line
11 content
12
what am I missing?
- I though the
regexpwould make this idempotent (but apparently doesn’t work) - Do I need additionally
insertberfore/insertafter?