Below regex is working perfectly for my requirement. Thanks a lot, Dick for your help.
- set_fact: ip_list: "{{ ip_addr.split() | ipaddr }}" - debug: var=ip_list - set_fact: host_list: "{{ ip_addr.split() | select('match','^([a-zA-Z].*)') | list }}" - debug: var=host_list On Tuesday, 25 June 2019 00:14:02 UTC+5:30, Dick Visser wrote: > > On Sun, 23 Jun 2019 at 20:08, Pandu jh <jhp...@gmail.com <javascript:>> > wrote: > > > > The error is > > > > TASK [set_fact] > ***************************************************************************************************** > > > > fatal: [lab1]: FAILED! => {"msg": "Unexpected templating type error > occurred on ({{ ip_addr.split(\n) | regex_search('^[a-z].*') }}): > expected string or buffer"} > > You didn't quote the newline. > But, you don't really need that as the default is to split by white space. > > For the literal IPv4 address it's indeed easy, as you can just use the > ipaddr filter. > For the hostname you can use the select() test, in combination with > some regular expression that needs to match. > Depending on how formal/exact you want to define "a hostname", the > regex can simple or really complex. > A simple example: > > tasks: > - set_fact: > ip_list: "{{ ip_addr.split() | ipaddr }}" > - debug: var=ip_list > - set_fact: > host_list: "{{ ip_addr.split() | select('match', > '^([a-zA-Z]+(-[a-zA-Z]+)*\\.)+[a-zA-Z]{2,}$') | list }}" > - debug: var=host_list > > > > This should give you some results. > > > Dick > > > > -- > Dick Visser > Trust & Identity Service Operations Manager > GÉANT > -- 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/5ddf6601-492d-48cc-ae52-46c8b81d8d18%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.