我正在尝试使用正则表达式模式将主机与ansible匹配,但是它无法按预期工作。我的库存如下所示:
[group1]
hello1
world1
hello2
world2
[group2]
hello3
我的任务是:
- debug:
msg: "{{ item }}"
with_inventory_hostnames:
- ~hello*
从他们的文档:
Using regexes in patterns
You can specify a pattern as a regular expression by starting the pattern with ~:
~(web|db).*\.example\.com
当我执行任务时,没有输出。我的正则表达式是n00b,所以我的正则表达式有可能出错吗?
您需要使用hello\d+
来匹配所有以hello
开头且后跟至少一位数字的主机。
您可以使用this深入了解实际的正则表达式。