I am trying to replace everything except a special block using Ansible blockinfile. It would be safe to assume that this special block to be at the beginning of the file.
File content before ansible run:
# BEGIN SPECIAL
blah
# END OF SPECIAL
... bunch of configs
Expected file content after ansible run:
# BEGIN SPECIAL
blah
# END OF SPECIAL
[MY REPLACED CONFIGS]
There are two problems with using blockinfile marker.
marker_startandmarker_enddo not support regex- Cannot specify EOF as
marker_end
My ansible task:
- name: testing replacing file
blockinfile:
path: /tmp/testfile
marker: "{mark}"
marker_begin: "# END OF SPECIAL"
marker_end: EOF
block: "[MY REPLACED CONFIGS]"
state: present
This does not seem to do the trick. Is there a way to achieve this with blockinfile?