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
fix incorrect ansible_managed formatting #79129
Conversation
The test
|
This is probably mergeable with a changelog fragment and a test |
Added changelog and test. |
ready_for_review |
What should I do next? |
bot_status |
Componentschangelogs/fragments/79129-ansible-managed-filename-format.yaml lib/ansible/template/init.py test/integration/targets/template/ansible_managed_79129.yml test/integration/targets/template/runme.sh [test/integration/targets/template/templates/%necho Onii-chan help Im stuck;exit 1%n.j2](https://github.com/ansible/ansible/blob/devel/test/integration/targets/template/templates/%necho Onii-chan help Im stuck;exit 1%n.j2) Metadatawaiting_on: ansible |
ready_for_review |
@@ -103,7 +103,7 @@ def generate_ansible_template_vars(path, fullpath=None, dest_path=None): | |||
managed_str = managed_default.format( | |||
host=temp_vars['template_host'], | |||
uid=temp_vars['template_uid'], | |||
file=temp_vars['template_path'], | |||
file=temp_vars['template_path'].replace('%', '%%'), |
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.
This fix only addresses the %, it should escape any/all characters that would cause issues with templating
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.
according to docs only percent characters could cause unexpected result. I guess it's enough to replace them in in file path to sanitize input.
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.
{{
.. strftime is not the only 'templating' that happens
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.
oh. right
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.
Thank you!
I've updated PR and added test for this.
Ansible breaks configs if file name could be parsed as jinja template or contains `%` chars. Especially `%n`[ame%] which is a line break pattern according to [strftime (3)](https://manpages.debian.org/bullseye/manpages-dev/strftime.3.en.html)
ready_for_review |
SUMMARY
Ansible breaks configs if file name contains
%
chars.Especially
%n
[ame%]
which is a line break pattern according to strftime (3)ISSUE TYPE
COMPONENT NAME
generate_ansible_template_vars()
ADDITIONAL INFO
default value for
ansible_managed
isif you put
{{ansible_managed}}
in jinja template and save in file named like/etc/whatever/%name%.conf
it will split string to multiple lines and possibly break syntaxSimple test case: