The lineinfile module of Ansible

While working with Ansible and files, like configuration files or default files for services, often it’s useful to just change one line than copy a template file. The lineinfile module provides functionality like sed. Usually I did like the example below with sed because I was more familiar with sed than with re of Python.

Converted for a playbook task entry

The below is a simple collection of the different use cases of the lineinfile module. It took me some time to figure out how the module works. insertafter and insertbefore with BOF/EOF do not work as expected

The test.conf file will look like this at the end.

This entry was posted in Configuration management. Bookmark the permalink.

2 Responses to The lineinfile module of Ansible

  1. Tapan says:

    Excellent…

  2. GrrrOby says:

    Thanks, helped me a lot!

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.