<p>This blog post covers all of the methods:</p>

<em>excerpt - <a href="http://toroid.org/ansible-host-patterns" rel="nofollow noreferrer">Host names and patterns in Ansible 2</a></em>

<blockquote>
  <h3>Inventory hostnames</h3>
  
  <p>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.</p>
  
  <p>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].</p>
  
  <h3>IPv6 addresses</h3>
  
  <p>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).</p>
  
  <p>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.</p>
  
  <p>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.</p>
</blockquote>

<p>Therefore patterns such as these IPv6's would be allowed:</p>

<ul>
<li>fully specified 128 bit address</li>
<li>[addr]:port</li>
<li>hexadecimal ranges - 9876::[a:f]:2</li>
<li>various forms of compressing ranges - FF01::[1:6]</li>
</ul>

<p>Simplified examples:</p>

<pre><code># 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
</code></pre>

<h3>References</h3>

<ul>
<li><a href="https://www.dummies.com/programming/networking/cisco/network-basics-ipv6-address-simplified-notation/" rel="nofollow noreferrer">NETWORK BASICS: IPV6 ADDRESS SIMPLIFIED NOTATION</a></li>
</ul>

CC BY-SA 4.0
2018-08-08T14:34:50.990Z
2018-08-09T11:46:54.907Z
2018-08-09T11:46:54.907Z
slm
<p>I have a machine, that is accessible via ipv6 only. It is setup for ssh with rsa key. Now I'd like to manage it with ansible. Unfortunately, this is not covered in the <a href="https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html" rel="noreferrer">inventory documentation</a>. </p>

<p>So I tried the following permutations:</p>

<ul>
<li><code>docker_test ansible_host=fe80::88ea:e002:b409:4be0</code></li>
<li><code>docker_test ansible_host=[fe80::88ea:e002:b409:4be0]</code></li>
<li><code>docker_test ansible_host=\[fe80::88ea:e002:b409:4be0\]</code></li>
</ul>

<p>None of this worked out.</p>

<p>For comparison I add my <code>.ssh/config</code> entry:</p>

<pre><code>Host docker_host
    AddressFamily inet6
    HostName fe80::88ea:e002:b409:4be0
    BindAddress fe80::3e6b:335a:d2f7:3a75%enp3s0
</code></pre>

<p>I found two closed bug in the issue tracking system,which indicate the problem being at least partially solved: <a href="https://github.com/ansible/ansible/issues/3879" rel="noreferrer">3879</a>, <a href="https://github.com/ansible/ansible/issues/3888" rel="noreferrer">3888</a></p>

<p>Any advise on this topic is highly appreciated.</p>

CC BY-SA 4.0
2018-07-30T19:37:50.783Z
Did you try to use an inventory file? And please tell us the errors you get.
guntbert
CC BY-SA 4.0
2018-07-31T06:25:21.010Z
Yes, I did try using the inventory file. The three permutations posted originated from there. The exceptions are rather vague stating either a wrong format in the inventory file or a false argument for the ssh client.
tgr
CC BY-SA 4.0
2018-08-08T14:43:22.303Z
The IPv6 address is missing the mandatory scope ID. Of course you should avoid using link-local addresses whenever possible.
Michael Hampton
<ansible><ansible-inventory>
How to notate ipv6 addresses in inventory file?
tgr
# How to notate ipv6 addresses in inventory file?

(Asked by: username_0 on 2018-05-07)

I have a machine, that is accessible via ipv6 only. It is setup for ssh with rsa key. Now I'd like to manage it with ansible. Unfortunately, this is not covered in the inventory documentation. 
So I tried the following permutations:

docker_test ansible_host=fe80::88ea:e002:b409:4be0
docker_test ansible_host=[fe80::88ea:e002:b409:4be0]
docker_test ansible_host=\[fe80::88ea:e002:b409:4be0\]

None of this worked out.
For comparison I add my .ssh/config entry:
Host docker_host
    AddressFamily inet6
    HostName fe80::88ea:e002:b409:4be0
    BindAddress fe80::3e6b:335a:d2f7:3a75%enp3s0

I found two closed bug in the issue tracking system,which indicate the problem being at least partially solved: 3879, 3888
Any advise on this topic is highly appreciated.

**Tags:** ansible, ansible-inventory

> **Comments:**
> **username_1**: Did you try to use an inventory file? And please tell us the errors you get.  
> **username_0**: Yes, I did try using the inventory file. The three permutations posted originated from there. The exceptions are rather vague stating either a wrong format in the inventory file or a false argument for the ssh client.  
> **username_2**: The IPv6 address is missing the mandatory scope ID. Of course you should avoid using link-local addresses whenever possible.  

---

## 1 answers

### Answer by username_3 on 2018-08-08. Score: 6 | Accepted answer

This blog post covers all of the methods:
excerpt - Host names and patterns in Ansible 2

Inventory hostnames
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].
IPv6 addresses
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
[addr]:port
hexadecimal ranges - 9876::[a:f]:2
various forms of compressing ranges - FF01::[1:6]

Simplified examples:
# 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

References

NETWORK BASICS: IPV6 ADDRESS SIMPLIFIED NOTATION


---

