-
Notifications
You must be signed in to change notification settings - Fork 24k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update lineinfile.py: uniq option added #80678
base: devel
Are you sure you want to change the base?
Conversation
uniq option: if set to yes/true, leaves only one (first) LINE in file, removing all other same lines.
The test
The test
The test
|
The test
The test
|
The test
|
aside from missing tests and changelog, wouldn't the replace module do a better job? |
on Changelog, i can see diff at https://github.com/ansible/ansible/pull/80678/files , can you? Why i wanted this new feature: sometimes people use wrong regexp in lineinfile, that lead to warnings during 'verify' or 'restart notifiers' in most cases, leaving number of duplicate lines in target 'path' config file after number of lineinfile runs. But in some cases that duplicates could brake application. Of course, usage of 'uniq' could brake those configs where dups are intentionally used - thats why default is 'no' for 'uniq' |
Sorry for silence. Is there any obstacles that prevents include this PR into main branch? |
The test
|
uniq option: if set to yes/true, leaves only one (first) LINE in file, removing all other same lines.
SUMMARY
In some cases duplicate lines appears in target 'path' file after applying wrong regexp-based lineinfile tasks.
This 'uniq' option removes all duplicates of 'line' in b_lines array before writing to the 'path'.
ISSUE TYPE
COMPONENT NAME
lineinfile
ADDITIONAL INFORMATION
'uniq' option added to DESCRIPTION, to the modules options, to the present()-function arguments.
Rewrites b_lines array if 'uniq' set to true, makes msg to 'made line unique' and 'changed' to true, right before check for module._diff .