-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
file.replace fails to append if repl string partially available #23294
Comments
That logic at L1155 shouldn't actually result in a match, so
|
I certainly have tried everything under the sun, quoting, you name it, no luck.
|
Oh I see, I misunderstood. Yes, that's behaving exactly as intended. 2015.2 introduces file.line, which may do what you need, as its intended to work on entire lines, where file.replace needs to be able to work on partial lines as well. That said, considering L1155 is determining whether to append/prepend the content as a new line, it may make sense to assume the search is for the entire line... |
Agreed. If prepend or append flag set, '^' should be added to the search content. I don't mind using file.line in the next release but this functionality either needs to be sorted or removed in favour of file.line, otherwise it just remains confusing. |
I went ahead and created a branch with a possible fix, but I can't test it effectively while at work (though I did make sure the code worked in a python shell). If you can test the file.py module in my branch to make sure it works the way you expect, I'll open the PR. Otherwise, I'll test it later when I get home. https://github.com/lorengordon/salt/tree/file.replace_assume_line |
@variia, @lorengordon, thanks for working on this. |
@lorengordon sure, can test it in couple of hours. Thanks |
Ok, the patch appears to work as intended. PR is #23350. |
Thanks a lot for the prompt action @lorengordon, I can also confirm that the fix is working on my production cluster. |
Hi,
I just managed to trigger a funny bug I need some input from you guys.
Target file:
The issue is that I want to manage my own /etc/resolv.conf file with salt hence I have no DNS specification in my interface config. Redhat manages /etc/resolv.conf by default with PEERDNS=yes resulting an empty resolv.conf file after reboot so I have to append PEERDNS=no to my interface config for BOTH IPV6 and IPV4 to avoid this. As you can see, the installer only added IPV6_PEERDNS so my search string is partially available in the file content.
funnybug is not part of the target file and the reason why the repl string is not appended is caused by the logic which is trying to check if it was already appended:
https://github.com/saltstack/salt/blob/2014.7/salt/modules/file.py#L1125
https://github.com/saltstack/salt/blob/2014.7/salt/modules/file.py#L1155
Even if I specified ^string to specifically indicate line start, it is not taken into account.
I would not know right now how I would tackle this sort of issue so if you guys think it is not something worth to fix, I just fall back to cmd.run solution.
Thanks,
Ivan
The text was updated successfully, but these errors were encountered: