-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
ini_file - support optional spaces around section names #8075
ini_file - support optional spaces around section names #8075
Conversation
…rrounding brackets Some ini files have spaces between some of their section names and the brackets that enclose them. This is documented in the 'openssl.cnf(5)' man page. In order to manage files such as /etc/ssl/openssl.cnf with ini_file before now, one would have to include spaces in the section name like this: section: ' crypto_policy ' option: Options value: UnsafeLegacyRenegotiation This change implements matching section headers with such optional spaces. Existing tasks using the workaround above will continue to work, even in cases where spaces in section headers are subsequently removed.
I wonder whether this should better be configurable, since there could be INI parsers which consider |
(I have zero idea whether that's actually the case. It's just that there are so many flavors of INI files that I woudn't be surprised if that's the case...) |
I admit I had not considered the possibility that someone / something may be using outer spaces as a discriminator between otherwise identically named sections. But I would be extremely surprised. The point of ini files is to have a format that is
The latter point seems to exclude "significant leading/trailing spaces" shenanigans. Adding a flag later if necessary could be considered, but without evidence of such cases in the wild I don't think it's worthwhile bloating |
I should add that, with this change,
However, if it caused the creation of a section, that header would be exactly as specified:
in this case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there could be a slight improvement in the tests contents formatting, for readability's sake, but that is certainly not a show-stopper.
- name: Test-section_name_spaces 1 (does legacy workaround still work) - create test file | ||
ansible.builtin.copy: # noqa risky-file-permissions | ||
dest: "{{ output_file }}" | ||
content: "[ foo ]\n; bar=baz\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the sake of readability, I would suggest using:
content: "[ foo ]\n; bar=baz\n" | |
content: | | |
[ foo ] | |
; bar=baz |
- name: Test-section_name_spaces 1 - verify results | ||
vars: | ||
actual_content: "{{ output_content.content | b64decode }}" | ||
expected_content: "[ foo ]\nbar = frelt\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
conversely:
expected_content: "[ foo ]\nbar = frelt\n" | |
expected_content: | | |
[ foo ] | |
bar = frelt |
same in the similar situations below
I agree it's not very likely (and I hope nobody ever does that - but then, you never know ;) ). I think it's OK to merge this without making it configurable; in case someone actually needs this we can add a flag later to toggle the behavior. |
hi @utoddl I left a formatting suggestion on the test script. It's a minor thing but it would help with readability. Other than that, I think this is good to go. |
Backport to stable-8: 💚 backport PR created✅ Backport PR branch: Backported as #8135 🤖 @patchback |
* ini_file - support optional spaces between section names and their surrounding brackets Some ini files have spaces between some of their section names and the brackets that enclose them. This is documented in the 'openssl.cnf(5)' man page. In order to manage files such as /etc/ssl/openssl.cnf with ini_file before now, one would have to include spaces in the section name like this: section: ' crypto_policy ' option: Options value: UnsafeLegacyRenegotiation This change implements matching section headers with such optional spaces. Existing tasks using the workaround above will continue to work, even in cases where spaces in section headers are subsequently removed. * readability improvement in the test content expressions --------- Co-authored-by: Todd Lewis <[email protected]> (cherry picked from commit 4363f87)
…aces around section names (#8135) ini_file - support optional spaces around section names (#8075) * ini_file - support optional spaces between section names and their surrounding brackets Some ini files have spaces between some of their section names and the brackets that enclose them. This is documented in the 'openssl.cnf(5)' man page. In order to manage files such as /etc/ssl/openssl.cnf with ini_file before now, one would have to include spaces in the section name like this: section: ' crypto_policy ' option: Options value: UnsafeLegacyRenegotiation This change implements matching section headers with such optional spaces. Existing tasks using the workaround above will continue to work, even in cases where spaces in section headers are subsequently removed. * readability improvement in the test content expressions --------- Co-authored-by: Todd Lewis <[email protected]> (cherry picked from commit 4363f87) Co-authored-by: Todd Lewis <[email protected]>
…ections#8075) * ini_file - support optional spaces between section names and their surrounding brackets Some ini files have spaces between some of their section names and the brackets that enclose them. This is documented in the 'openssl.cnf(5)' man page. In order to manage files such as /etc/ssl/openssl.cnf with ini_file before now, one would have to include spaces in the section name like this: section: ' crypto_policy ' option: Options value: UnsafeLegacyRenegotiation This change implements matching section headers with such optional spaces. Existing tasks using the workaround above will continue to work, even in cases where spaces in section headers are subsequently removed. * readability improvement in the test content expressions --------- Co-authored-by: Todd Lewis <[email protected]>
ini_file - Support optional spaces between section names and their surrounding brackets
SUMMARY
Some ini files have spaces between some of their section names and the brackets that enclose them. This is documented in the
openssl.cnf(5)
man page. In order to manage files such asopenssl.cnf
with ini_file before now, one would have to include spaces in the section name like this:This change implements matching section headers with such optional spaces, removing the need to include those spaces in the task's
section:
parameter. Existing tasks using the workaround above will continue to work, even in cases where spaces in section headers are subsequently removed.ISSUE TYPE
COMPONENT NAME
ini_file
ADDITIONAL INFORMATION
Here's an actual "legacy" production
ini_file task
. Note the spaces in the section name. These spaces have been necessary because the target file has these spaces already.After this change, those spaces are no longer necessary. Furthermore, the above task will continue to work even if someone removes the spaces from the target file's
crypto_policy
section header.