-
Notifications
You must be signed in to change notification settings - Fork 341
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
ansible.builtin.search test fails with "bad escape" error if pattern contains backslash anywhere #1086
Comments
Files identified in the description: None If these files are incorrect, please update the |
This is effectively expected, and ultimately you need to use The string gets interpreted multiple times First by yaml, then by python, and finally by jinja2 as part of it's variable. Because it is processed by both python and jinja2, the backslash escaped characters get unescaped twice. This means that you normally have to use four backslashes to escape that. I assumed we had documentation that describes this, but I cannot find it. And actually as I am typing this, I remembered this issue: ansible/ansible#82523 I'll transfer this issue over to the docs repo. |
Thanks for your Ansible docs contribution! We talk about Ansible documentation on matrix at #docs:ansible.im and on libera IRC at #ansible-docs if you ever want to join us and chat about the docs! We meet there on Tuesdays (see the Ansible calendar) and welcome additions to our weekly agenda items - scroll down to find the upcoming agenda and add a comment to put something new on that agenda. |
Summary
consider the following task that I am trying to run in ansible:
I am trying to loop through a list and only want the task to run if an item in the list contains the string I have specified. While I have used the search test many, many times before, I have never used it with a pattern that contained a backslash, and when I attempt to run the above task in ansible, I get the below error:
I even tried doubling up the backslashes in the pattern to see if that would fix the issue:
but I received an almost identical error:
when I change the conditional so that the pattern will match a string in the list exactly and use "==", the task work perfectly:
So I am lead to conclude that this is an issue with either the ansible.builtin search test and backslashes or tests in general and backslashes.
Issue Type
Bug Report
Component Name
search
Ansible Version
Configuration
OS / Environment
Ubuntu 22.04.3 LTS
Steps to Reproduce
or
Try running either of the above tasks in a playbook
Expected Results
I would expect the search test to complete without error
Actual Results
Code of Conduct
The text was updated successfully, but these errors were encountered: