I want to add the line "*{My-Dept$2}" in file.yaml after *{My-Dept$1} this on every finding, I was able to find a line that starts with *{My-Dept$1} and inserted only one time, and ended with this trouble.
I have this in Multiple lines in the file and wanted to insert after "*{My-Dept$1}".
The reference are below:
Infrastructure:
- *{My-Dept$0}
- *{My-Dept$1}
Applications:
- *{My-Dept$1}
- *{My-Dept$3}
- *{My-Dept$4}
Database:
- *{My-Dept$0}
- *{My-Dept$1}
- *{My-Dept$3}
With the below code i was able to add the line "- *{My-Dept$2}" after only in the last "Database arry " entry.
- name: Add missing Dept
lineinfile:
dest: ./file.yaml
insertafter: '[*{]My-Dept[$]1[}]' #
line: ' - *{My-Dept$2}'
and the Output:
Infrastructure:
- *{My-Dept$0}
- *{My-Dept$1}
Applications:
- *{My-Dept$1}
- *{My-Dept$3}
- *{My-Dept$4}
Database:
- *{My-Dept$0}
- *{My-Dept$1}
- *{My-Dept$2}
- *{My-Dept$3}
I wish to get "*{My-Dept$2}" on every next line of each of the findings of *{My-Dept$1} entries. Most of the search find talks about replace, but my requirement is to insert multiple times on each finding.