Thanks for your reply. I don't want to use leading white space in the string mentioned in line. That is because there are multiple files and some may have leading white space before the string and some may not.
Ansible should be able to find a snippet which is part of one line in a multi-line file.
@Listing - I will eventually use grep and sed only buy I wish Ansible had a easy to use module for this. I have been using Ansible for sometime now and I'm not to close this gap.
AnsiNoob, what are you trying to achieve in the first place?
More specifically, what do you mean by: " # Below line's presence
needs to be checked" ?
lineinfile is meant to make sure (not "checking") a specific line is
in a file, optionally aware of the lines before and after.
But looking at your sample file, it looks like a more complex data structure.
Adding just a line at the bottom doesn't seem to make sense in this case?
In summary, can you be more clear and specific, possibly with more examples?
I’ve give some thought to this and I agree that lineinfile is meant to replace/add a line if not present and not for ‘just checking’ an entire line, a word, or few words.
You are right that my file is complex data structure. We have 100 such files and our job is to check for existence of specific string (another=myother is just an example) in all files. I thought I could use lineinfile module in dry run mode (check_mode: yes) so that lineinfile would just check for presence and not replace anything.
I do have a workaround now but would be interested to know how people use Ansible to perform simple greps to check for presence of specific settings/entries in different configuration files in order to generate reports.
When above is run in check mode then lineinfile outputs saying it did find the string in regexp and replaced it with string in line section but it actually does not as it was executed in check mode.
The ‘changed’ output in yellow is what I use to report that the string exists.
This is an assertion from my side, most people don't.
Ansible is a configuration management tool and not a reporting tool.
That means you tell it how you would like your server to be configured and Ansible do the job.