Hello all, I am currently looking at a quote issue in an ansible nested variable and i cannot get it clear why it is not working. Can you help me out?
Some details: hostname: x55-n12 I want to get the first value (x55) with a regular expression: (.*?)(?=\-) and place this value in a file called rack. Ansible task file: --- - include_vars: default.yml - name: 'Place files' template: > src={{ item.src }} dest={{ item.dest }} owner=root group=root mode=0644 with_items: - { src: klaas/attributes/rack.j2 , dest: "/klaas/attributes/rack"} register: klaasconfig - name: Remove latest file and restart file: directory=/tmp/klaas/meta/slaves/latest/ state=absent when: klaasconfig.changed notify: restart klompendans *** rack.j2 file: {{ rack }} *** default.yml file: --- firewalld_zone: kees rack: "{{ ansible_hostname | regexp_replace(.*?)(?=\-) }}" **** Now the error: Note: The error may actually appear before this position: line 8, column 52 firewalld_zone: kees rack: "{{ ansible_hostname | regexp_replace(.*?)(?=\-) }}" ^ We could be wrong, but this one looks like it might be an issue with missing quotes. Always quote template expression brackets when they start a value. For instance: with_items: - {{ foo }} Should be written as: with_items: - "{{ foo }}" *** According to my git commits I have changed the regex to (and a couple more, but it shows i do not know how to handle this regex): rack: {{ ansible_hostname | regexp_replace(.*?)(?=\-) }} rack: {{ ansible_hostname | regexp_replace"(.*?)(?=\-)" }} rack: "{{ ansible_hostname | regexp_replace('(.*?)(?=\-)') }}" rack: {{ ansible_hostname | regexp_replace('(.*?)(?=\-)') }} rack: "{{ ansible_hostname | regexp_replace((.*?)(?=\-)) }}" The regex 'should' work because i have tried it a couple of times with sed and python/javascript Thanks so much for helping! Rogier -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/dbaec58f-3833-40a8-ab41-a1d597ee94df%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.