我正在尝试获取Ansible中具有特定前缀的主机组的名称 . 现在,我正在尝试将模板任务委托给主机组下的服务器,前缀为“config_” .
我正在使用 json_query
,它使用JMESPath表达式 . 但是查询不正确 . 谁能猜到我错过了什么?
- name: Create configsvr config file
template: src=mongod.conf.j2 dest={{ mongod.conf.path }} owner=mongod group=mongod mode=0600
delegate_to: "{{ groups|json_query([?starts_with(@, `config_`)]) }}"
错误消息:
FAILED! => {"failed": true, "msg": "template error while templating string: unexpected char u'?' at 22. String: {{ groups|json_query([?starts_with(@, `config_m`)]) }}"}
2 回答
您应该只使用内置的patterns来选择目标主机 .
您可以使用组来改善广告资源,例如:
然后在你的剧本中定位
conf
组: