I am using lineinfile to add multiple host details in a file but some details were the same only different in hosts. I am looking for a way to prevent lineinfile to skip same line. Is that possible ?
Asked
Active
Viewed 150 times
0
-
Welcome to SO. Maybe a better title woud be something like "How to prevent lineinfile to skip same lines" - And if possible, give some more details. – Andy A. Aug 30 '21 at 07:50
1 Answers
0
If you are looking to validate if lines are present before adding, maybe this would work. Regex is the string to search and state is set to absent to remove if the line is already present.
---
- hosts: localhost
tasks:
- name: Check if it is the file
become: yes
tags: example
lineinfile:
path: /path/to/file
regexp: "Hello World"
state: absent
backup: yes
-
Please add further details to expand on your answer, such as working code or documentation citations. – Community Sep 02 '21 at 06:20