如何使用正则表达式在regex_search
参数中出现变量的Ansible Playbook中找到匹配项?
以下剧本找不到匹配项...当使用ansible-playbook playbook.yml
- hosts: localhost
gather_facts: no
tasks:
- set_fact:
pattern: "{{ 'foobar' | regex_search('foo') }}"
- set_fact:
m: "{{ 'beefoo' | regex_search('bee{{ pattern }}') }}"
- debug:
msg: "hi {{ m }}"
答案 0 :(得分:2)
取决于您使用的ansible
的版本。据我所知,您可以在高于2.4.0的版本中使用该表达式。对于较低版本,可以使用regex_search('^' + pattern | string)
。
所以您的代码将如下所示:
- hosts: localhost
gather_facts: no
tasks:
- set_fact:
pattern: "{{ 'foobar' | regex_search('foo') }}"
- set_fact:
m: "{{ 'beefoo' | regex_search('bee' + pattern | string) }}"
- debug:
msg: 'hi ' + m | string
答案 1 :(得分:1)
希望与积极的先行者,积极的先行者和在port
中可变的人分享我的复杂案例。
tunnel