On 26.01.2017 15:51, Yuval Mund wrote:
I'm having trouble parsing a string.
The situation:
- parameters:
full: ['hostname1:abcdefg1','hostname2:-vip2','hostname3:abc-vip3']
It is required of me to have a parameter/list of hostnames without the
rest
of the string
i.e
just_hostnames: ['hostname1','hostname2','hostname3']
I tried using using regex_replace like this
just_hostnames: "{{ full | regex_replace(':(?(?!'))*', '') }}"
But i got the error -
template error while templating string expected token 'end of print
statement', got '.'.
Because full is a list you can't do it like this since regex_replace
don't work with lists.
Bu you can do something like this.
- set_fact:
loop_item: "{{ item.split(':')[0] }}"
register: loop_result
with_items: "{{ full }}"
- set_fact:
just_hostnames: "{{ loop_result.results |
map(attribute='ansible_facts.loop_item') | list }}"
--
Kai Stian Olstad
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/233cca97fcefac95509d45701076e9b0%40olstad.com.
For more options, visit https://groups.google.com/d/optout.