Ansible – Disable Marker in Blockinfile

ansible

I'm new to ansible, however I was able to successfully use the blockinfile function. However I can't figure out how to prevent markers from being inserted. I read the documentation but it didn't appear to describe it.

This is what shows up in every file that blockinfile writes to.

# BEGIN ANSIBLE MANAGED BLOCK
# END ANSIBLE MANAGED BLOCK

Best Answer

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.