Blockinfile module in ansible

Ansible blockinfile module is used to insert/update/remove a block of lines in a file. This module will insert/update/remove a block of multi-line text surrounded by customizable marker lines.

Now by using the ansible blockinfile module we will add some lines to the file.
#cat blockinfile.yaml
- hosts: linux
- name: create file
path: /home/ansible/blockinfile
state: touch
- name: add block of lines to a file.
path: /home/ansible/blockinfile
block: |
Hi everyone
path: here we have to give the path of the file which you want to modify.
block: here you have to write your lines of code(content) which you want to add to the file

To run playbook,
# ansible-playbook blockinfile.yaml
PLAY [all] **************************************************************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************************************
ok: []

TASK [create file] ******************************************************************************************************************************************
changed: []

TASK [add block of lines to a file.] ************************************************************************************************************************
changed: []

PLAY RECAP ************************************************************************************************************************************************** : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

Recent Comments

No comments

Leave a Comment