I have a situation where I would like to include an existing line in a text file into a new block.
line 1
line 2
line in block
line 3
line 4
should become
line 1
line 2
line 3
line 4
# BEGIN MyBlock
line in block
other line in block
# END MyBlock
Creating the block of course involves the blockinfile module:
- blockinfile:
path: /etc/myfile
marker: "# {mark} MyBlock"
block: |
line in block
other line in block
The lineinfile could be used to remove a line:
- lineinfile:
path: /etc/myfile
line: 'line in block'
state: absent
But this solution may remove the line within the block, instead of the original one.