ansible blockinfile disable marker
The markers are actually used to identify the block.
That means if you remove the markers, blockinfile
will no longer be able to identify the block, which will result in the module to add the block to the file every time you run the task.
So the markers before and after the written block are a requirement by the module and cannot be removed.
If this is a one-time playbook that will never be executed again you could run the lineinfile
module with the state: absent
option afterwards.
i did something like this...
- name: Insert someline in somefile.sh
blockinfile:
path: /usr/share/somefile.sh
block: -sometext
insertafter: '-XX:originaltext'
marker: ""
backup: yes
- name: Remove blank lines blockinfile put in
lineinfile :
path: /usr/share/somefile.sh
state: absent
regexp: '^$'
- marker "" will insert blank lines into the file
- lineinfile will remove them (along with all other blank lines) so beware !!