I wan´t to split the hostname of my inventory hostnames. The hostnames have two or three subdomains. For Exampel “host.sub1.sub2.domain”
I need two splits. One bevor the first dot (in our example: host) and one after the first dot. (sub1.sub2.domain).
I tried with {{ HOST.split(“.”)[0] }}, but there will be split after every dot.
this give me the result host.sub1.hostname but not host.sub1.sub2.hostname. For Hostnames with one subdomain it works fine, but not for Domains with more subdomains.
I'm not exactly sure what you are trying to accomplish, but I would
like to point out that `split()` has an optional parameter `maxsplit`
that limits the number of splits that are actually done. Shouldn't
that help to solve your problem?
In [11]: s='host.sub1.sub2.example.com'
In [12]: s.split('.', 2)
Out[12]: ['host', 'sub1', 'sub2.example.com']
In [13]: s.split('.', 3)
Out[13]: ['host', 'sub1', 'sub2', 'example.com']