我期待与netbios域名和反斜杠的用户列表。到目前为止,这是我能想到的最好的方法:
- hosts: servers
vars:
mylist:
- Alice
- Bob
- Carol
mystring: test
mylist2: "{{ mylist | map('regex_replace', '^', mystring + '\' ) | list }}"
tasks:
- debug: var=mylist2错误消息如下:
The offending line appears to be:
mystring: test
mylist2: "{{ mylist | map('regex_replace', '^', mystring + '\' ) | list }}"
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"我正面临着将反斜杠连接到我的变量的问题,因为ansible认为我试图转义某些东西,但没有放入我想转义的东西。我也曾尝试使用双反斜杠,但无济于事。
有没有人能建议一下这里有什么可行的方法,或者另一种方法。
发布于 2021-03-25 07:38:45
简化表达式并将regex_replace参数放入变量中,例如
- hosts: localhost
vars:
mylist:
- Alice
- Bob
- Carol
mystring: test
mylist2: "{{ mylist|map('regex_replace', _my_regex, _my_replace)|list }}"
_my_regex: '^(.*)$'
_my_replace: '{{ mystring ~ "\\" ~ "\1" }}'
tasks:
- debug:
var: mylist2可能会给你想要的
mylist2:
- test\Alice
- test\Bob
- test\Carolhttps://stackoverflow.com/questions/66790617
复制相似问题