Regex Ansible:如何在使用搜索或匹配功能时处理点

Regex Ansible:如何在使用搜索或匹配功能时处理点,regex,ansible,Regex,Ansible,以下是两种情况,变量前缀只包含另一个字符串 1) 这项工作: when: ansible_hostname | search("{{ prefix }}-test-.*") 2) 这不起作用,可能是因为搜索字符串中有点 when: ansible_hostname | search("{{ prefix }}-test-.*.tin.com) 我甚至试着逃过一点也没有成功 when: ansible_hostname | search("{{ prefix }}-test-.*\.tin

以下是两种情况,变量前缀只包含另一个字符串

1) 这项工作:

 when: ansible_hostname | search("{{ prefix }}-test-.*")
2) 这不起作用,可能是因为搜索字符串中有点

 when: ansible_hostname | search("{{ prefix }}-test-.*.tin.com)
我甚至试着逃过一点也没有成功

when: ansible_hostname | search("{{ prefix }}-test-.*\.tin\.com)

最后,我了解到,
ansible\u hostname
将只提供部分fqdn,因此,由于我的正则表达式试图使用
.tin.com
查找fqdn,因此不匹配。目前,我将使用
groups['name']
在我的主机上迭代并获取fqdn。
注意:Ansible有
Ansible\u fqdn
来提供完整的主机名,但是只有在配置了DNS的情况下才能正常工作。

您能给出一些您正在处理的主机名的示例吗?所有3个正则表达式都是合法的,应该匹配类似
hst test suffix.domain.tin.com
。ansible_主机名示例是必需的。主机示例=bgl1-1-tin-more-001.company.com,我在ubuntu 14.04上的ansible 1.5.4上
bgl1-1-tin-more-001.company.com
无法匹配
{prefix}-test-.*.tin.com