This blog post covers all of the methods:
excerpt - Host names and patterns in Ansible 2
Ansible 2 requires inventory hostnames to be valid IPv4/IPv6 addresses or hostnames (i.e., x.example.com or x, but not x..example.com or x--). As an extension, it accepts Unicode word characters in hostname labels. Any mistakes result in specific parsing errors, not mysterious failures during execution.
Inventory hostnames may also use alphabetic or numeric ranges to define more than one host. For example, foo[1:3] defines foo1 through foo3, while foo[x:z:2] expands to fox and foz. Addresses may use numeric ranges: 192.0.2.[3:42].
A number of problems with the parsing of IPv6 addresses have also been fixed, and their behaviour has been made consistent across the inventory (.ini files) and in playbooks (e.g., in hosts: lines and with add_host).
All of the recommended IPv6 address notations (from spelling out all 128 bits to the various compressed forms) are supported. Addresses with port numbers must be written as [addr]:port. One can also use hexadecimal ranges to define multiple hosts in inventory files, e.g. 9876::[a:f]:2.
A couple of small but necessary bugfixes go hand-in-hand with the parsing changes, and fix problems with passing IPv6 addresses to ssh and to rsync. Taken together, these changes make it possible to use IPv6 in practice with Ansible.
Therefore patterns such as these IPv6's would be allowed:
- fully specified 128 bit address
- hexadecimal ranges - 9876::[a:f]:2
- various forms of compressing ranges - FF01::[1:6]
# IPv6 Address # Simplified Notation
- FF01:0000:0000:0000:0000:0000:0000:0001 - FF01::1
- 2031:0000:130F:0000:0000:09C0:876A:130B - 2031:0:130F::9C0:876A:130B
- 0000:0000:0000:0000:0000:0000:0000:0001 - ::1
- FE80:0000:0000:5EFE:0192.0168.0001.0123 - FE80::5EFE:192.168.1.123
- FE80:0000:0000:0000:1585:4868:495F:D521 - FE80::1585:4868:495F:D521