-
Notifications
You must be signed in to change notification settings - Fork 141
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: issue with variable brackets inside any string in extra_vars #868
Conversation
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.
Instead of adding this jinja code, I'd prefer doing like follows:
regex_replace('(^[^:]*): (.*){{', '\1: !unsafe \2{{')
This is generating the following output, which should work as well, and leaves the generated yaml file more friendly:
cat example.yaml
---
- name: play all
hosts: a
gather_facts: false
vars:
input: !unsafe |
variable_name: 'https://{{ ip }}'
tasks:
- debug:
msg:
- "ORIGINAL: {{ input }}"
- |
MODIFIED: {{ input | regex_replace('(^[^:]*): (.*){{', '\1: !unsafe \2{{') }}
...
ansible-playbook -i inventory.yaml example.yaml
PLAY [play all] ******************************************************************************************************************************************************************************************************************************
TASK [debug] *********************************************************************************************************************************************************************************************************************************
ok: [hosta] => {
"msg": [
"ORIGINAL: variable_name: 'https://{{ ip }}'\n",
"MODIFIED: variable_name: !unsafe 'https://{{ ip }}'\n"
]
}
PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
hosta : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Ok, I've pushed the change to your suggestion. |
Add `multiline=True` to treat multiple lines
Add `multiline=True` to treat multiple lines
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.
LGTM
What does this PR do?
I am introducing this change to resolve the bug with brackets inside the extra_vars, I didn't find any other solution for this issue.
How should this be tested?
url: 'https://{{ ip }}'
Is there a relevant Issue open for this?
resolves #856
Other Relevant info, PRs, etc
N/A