diff options
author | James Cammarata <jimi@sngx.net> | 2016-01-27 16:34:03 -0500 |
---|---|---|
committer | James Cammarata <jimi@sngx.net> | 2016-01-27 16:34:03 -0500 |
commit | 39b41178167b8e38299ed90afaf7f9e0412d5718 (patch) | |
tree | 2f6a79039246506e5ca987bb258395920e348354 | |
parent | a928465c9ee9bf742729ac22078b07d420b20c91 (diff) | |
parent | 326ae2108913e275388d8a0867512a120c66ccbd (diff) | |
download | ansible-39b41178167b8e38299ed90afaf7f9e0412d5718.tar.gz |
Merge pull request #14153 from oneswig/doc-ipaddr-add-subnet-masks
Details on how to convert subnet masks into CIDR
-rw-r--r-- | docsite/rst/playbooks_filters_ipaddr.rst | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/docsite/rst/playbooks_filters_ipaddr.rst b/docsite/rst/playbooks_filters_ipaddr.rst index ce5cdaa021..d5f9391db8 100644 --- a/docsite/rst/playbooks_filters_ipaddr.rst +++ b/docsite/rst/playbooks_filters_ipaddr.rst @@ -283,6 +283,37 @@ If needed, you can extract subnet and prefix information from 'host/prefix' valu # {{ host_prefix | ipaddr('host/prefix') | ipaddr('prefix') }} [64, 24] +Converting subnet masks to CIDR notation +---------------------------------------- + +Given a subnet in the form of network address and subnet mask, it can be converted into CIDR notation using ``ipaddr()``. This can be useful for converting Ansible facts gathered about network configuration from subnet masks into CIDR format:: + + ansible_default_ipv4: { + address: "192.168.0.11", + alias: "eth0", + broadcast: "192.168.0.255", + gateway: "192.168.0.1", + interface: "eth0", + macaddress: "fa:16:3e:c4:bd:89", + mtu: 1500, + netmask: "255.255.255.0", + network: "192.168.0.0", + type: "ether" + } + +First concatenate network and netmask:: + + net_mask = "{{ ansible_default_ipv4.network }}/{{ ansible_default_ipv4.netmask }}" + '192.168.0.0/255.255.255.0' + +This result can be canonicalised with ``ipaddr()`` to produce a subnet in CIDR format:: + + # {{ net_mask | ipaddr('prefix') }} + '24' + + # {{ net_mask | ipaddr('net') }} + '192.168.0.0/24' + IP address conversion --------------------- |