I'm trying to fetch the names of host groups in Ansible that have a specific prefix. Right now, I'm trying to delegate a template task to servers under host groups with the prefix "config_".
I'm using json_query
which uses JMESPath expressions. The query however is incorrect. Can anyone guess what I'm missing?
- 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_`)]) }}"
Error msg:
FAILED! => {"failed": true, "msg": "template error while templating string: unexpected char u'?' at 22. String: {{ groups|json_query([?starts_with(@, `config_m`)]) }}"}
Eric Citaire :
You should simply use built-in patterns to select your target hosts.\n\n---\n- hosts: conf_*\n tasks:\n - name: Create configsvr config file \n template:\n src: mongod.conf.j2\n dest: \"{{ mongod.conf.path }}\"\n owner: mongod\n group: mongod\n mode: 0600\n",
2017-07-28T08:09:30