Junior — Middle
Explain what the lineinfile module in Ansible does and in what cases it is used.
sobes.tech AI
Answer from AI
The lineinfile module in Ansible is used to manage the content of individual lines in text files. It allows searching for lines by pattern and replacing them, adding new lines if they are missing, or deleting lines.
Main use cases:
- Updating configuration files where a specific line needs to be changed or added.
- Automating edits in files without completely overwriting them.
Example usage:
- name: Add or update a line in a file
ansible.builtin.lineinfile:
path: /etc/example.conf
regexp: '^option='
line: 'option=value'