lineinfile module
The module that makes sure one particular line is present in, or absent from, a text file.
In more detail
Unlike appending with >>, it checks the file first and adds the line only if it is missing, so running it twice leaves one copy. With create set to true it also creates the file. For whole files, prefer copy or template.
Related terms
- idempotency — The property of an operation that gives the same result whether you run it once or many times, because a repeat run finds nothing left to do.
- redirection — Sending a command's output into a file instead of the terminal: > replaces the file, >> appends to the end of it.
- copy module — The module that puts a file on a host, either copied from the control node or written from content given in the task.
- template module — The module that fills in a Jinja template with variables and writes the result to a file on each host.
Taught in
- What Configuration Management Is — Ansible Configuration Management at Scale
- Forty Servers By Teatime: Ansible Playbooks, Inventories And Puppet Manifests — CompTIA Linux+ (XK0-006) Exam Prep
- Privilege Escalation: sudo Rules And become — RHCE in Ansible (EX294): Automate Red Hat Systems
- Deploying Files: file, copy, lineinfile And blockinfile — RHCE in Ansible (EX294): Automate Red Hat Systems
- Handlers And Failure: notify, block, rescue And always — RHCE in Ansible (EX294): Automate Red Hat Systems