Ansible: split string

To split some string in the Ansible you can use split filter. For example, used default Ansible variable ansible_nodename that contains current host hostname like example.com

{{  ansible_nodename.split(".")[0] }}

Output: example

{{  ansible_nodename.split(".")[1] }}

Output: com

Leave a Reply

Your email address will not be published. Required fields are marked *