Dennis_M
(Dennis M)
August 30, 2021, 8:37am
1
Hi,
I’m studying how to use regexp, and just follow documented examples,
{{ ‘foo\nBAR’ | regex_search(“^bar”, multiline=True, ignorecase=True) }}
expected result is: “bar”.
Instead of “bar” it gets an empty string.
Is it a bug, or do I miss an important setting?
Thanks,
Dennis
See https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html
#searching-strings-with-regular-expressions
and pay careful attention to details such as punctuation and case:
1. The example is:
{{ 'foo\nBAR' | regex_search('^bar', multiline=True, ignorecase=True) }}
instead, you used:
{{ 'foo\nBAR' | regex_search("^bar", multiline=True, ignorecase=True) }}
2. The expected result is:
# => 'BAR'
whereas you say:
expected result is: "bar".
Try exactly what the example shows, and let us know if it does not produce
what the example should produce.
Antony.
Dennis_M
(Dennis M)
August 31, 2021, 6:43am
3
Hi,
BTW, ansible-2.9.24-2.el7.
“bar” instead of “BAR” was just a mistype.
Double quote instead of single quote plays no role, i.e. this YAML:
produces same output:
ok: [monitor1p] => {
“msg”: "Debug> "
}
Regards,
понедельник, 30 августа 2021 г. в 11:50:44 UTC+3, Antony Stone:
You need to quote the entire jinja expression itself (including the
curlies) if you use it as a yaml value.
Because the single quotes are already using inside the expression,
you;'d have to use the double quotes:
tasks:
- debug:
msg: "Debug> {{ 'foo\nBAR' | regex_search('^bar',
multiline=True, ignorecase=True) }}"