How can I escape a colon in an Ansible host name?

Viewed 188

The colon : is a special character in an ansible playbook hosts value that indicates separation in a list of hostname match patterns. I would like to have a host with a : in the name. Is there a way to escape the : in the hosts field so that it will be interpreted as one name?

Ex in my playbook yaml file:

- name: Do stuff
  hosts: "my:host"
...

This will be interpreted as 2 hosts named my and host, but I'd like to have it be interpreted as one host named my:host.

1 Answers

To accommodate patterns containing IPv6 addresses Ansible allows , as an alternate separator:

- name: Do stuff
  hosts: my:host,

However, your life will be easier if you just use valid hostnames instead of trying to work out ways of addressing invalid ones.

Related