Search⌘ K
AI Features

Editing a Text File

Explore how to automate text file editing with Ansible's lineinfile module. Understand parameters like path, line, regex, and state to insert, update, or remove lines in config files, using a practical example for OpenSSH password authentication.

Editing configuration files is a day-to-day task for every system administrator. It can be a service configuration file, enabling options, or Unix parameters. All of these use cases require editing a text file.

Ansible lineinfile module

The ansible.builtin.lineinfile module in Ansible serves the purpose of editing text files, enabling users to insert, update, or remove a single line of text within the file. Being included in the collection of builtin modules, it comes shipped with every Ansible installation. This is designed to support a wide range of operating systems.

Parameters

There are many parameters for the lineinfile ...