Answer the question
In order to leave comments, you need to log in
How can I use Ansible's lineinfile module to replace the first match after a given line?
Hello.
Can you tell me if it is possible, using the Ansible lineinfile module, to replace the first match after a given line and how?
There is such a file
[abc]
enabled=0
[abc-1]
enabled=0
[abc-2]
enabled=0
[abc-test]
enabled=0
[abc-debuginfo]
enabled=0
- lineinfile: dest=/path/to/file regexp="^Enabled=" insertafter="^\[abc\]" line="Enabled=1"
- lineinfile: dest=/path/to/file regexp="^Enabled=" insertafter="^\[abc-2\]" line="Enabled=1"
- command: "sed -i '/^\[abc\]/,/\[.*\]/ { s/^enabled=.*/enabled=1/g }; /^\[abc-2\]]/,/\[.*\]/ { s/^enabled=.*/enabled=1/g }' /path/to/file"
Answer the question
In order to leave comments, you need to log in
apparently you are trying to enable the repository, there are standard commands for this, and not some kind of inline file
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question