On Sun, 23 Jun 2019 at 20:08, Pandu jh <jhpa...@gmail.com> 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/CAL8fbwPQW8dAZJPf%2BKFTg6hsAC%2B%2B4v3dKsT1FnYxcBP8AShD7g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to