Trouble with regex_replace

Hello,

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 ‘.’.

If you need further information about the usecase please ask!

Thank you very much!!

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 }}"