Blockinfile - how to delete text

I have this text file and I was trying to delete some text that I had just added. Not sure how I would go about deleting

  1. The entire text tree and the wrappers #BEGIN ANSIBLE MANAGED BLOCK

  2. Just deleting the text tree

Can anyone explain? Thanks

The delete functionality is not functioning as expected

(ansible 2.3.0)

textfile -

giraffe

This is my text to add

Noooooooooooooo

penguin

robot

#BEGIN ANSIBLE MANAGED BLOCK

tree

#BEGIN ANSIBLE MANAGED BLOCK

Tried the following playbook and it just deleted the last wrapper

Playbook


  • hosts: local

tasks:

  • name: Use blockinfile

blockinfile:

path: /home/ansible/blockexample.txt

marker: “#BEGIN ANSIBLE MANAGED BLOCK”

block :

tree

state: absent

Outcome -

The problem is that the start marker and end marker is the same and
blockinfile doesn't now where to start and stop.

If you take a look at the blockinfile documentation under marker you will see
that it contain the template sign {mark} that will be changed for START or END

That way the start and end marker differ.

Just run your test without marker: and you'll see how it work since marker has
a default value that only need to be changed if your are using more than one
blockinfile on a file.