【发布时间】:2020-02-05 22:15:24
【问题描述】:
我正在尝试使用带有 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*匹配hell+ 0 个或多个o。你想要hello.*。 regular-expressions.info/quickstart.html 应该为您提供入门所需的基础知识。 -
有 2 票可以结束此问题。他们认为这是题外话,信息不足。我认为他们都错了。它涵盖了software tools commonly used by programmers; and is a practical, answerable problem that is unique to software development,并且有足够的信息来回答它。看我的回答。
标签: regex ansible ansible-inventory ansible-bug