Posts

Ansible the lineinfile, blockinfile and replace modules

Image
 Hello !! This post is for exploring the "lineinfile" vs 'blockinfile' and "replace" modules. The replace and the lineinfile use the path parameter to mark: The file to modify. lineinfile module is used to ensure[s] a particular line is in a file, or [to] replace an existing line using a back-referenced (backref) regular expression (regex). Use the replace module if you want to change multiple, similar lines The "dest" parameter is used for modules creating new files like template or copy modules. Just replace dest with path and both provided examples should work as expected. Adding lines in the file Adding a line in a file, if a file does not exist then it will create it. --- # Filename: adding_line.yml - name: testing LineInFile module hosts: localhost tasks: - name: Add a line to a file if the file does not exist lineinfile: path: /tmp/hosts line: 192.168.1.99 ansiblectl.devopshunter.com ctl cre...