I have a problem where a line that contains a certain space delimited string must exist in a file. The string can be anywhere in the line: start, middle, or end. If a line that contains that string does not exist, then a line with that string needs to be inserted into the file. I have been trying to use the lineinfile module to solve this, but so far I have been unsuccessful. Below is the code I have tried:
- lineinfile: dest: "/path/to/myfile" regexp: '^(.*)(\s*this_string_must_exist)(\s+.*)$' line: '\g<1> this_string_must_exist\g<3>' backrefs: true state: present I have tried many variations of the regular expression and line, but nothing I have tried totally achieves what I am looking for. I have verified that the regular expression can locate a line with the string regardless of where the string is within the line, and if such a line is located it is not modified. But I have not been successful in getting a new line inserted if it does not already exist. Does anyone have any suggestions? -Mark -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/29f4f9d7-44c0-40e8-bd08-4064f7bd3b13%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
