subnet address facts module

Hi All,

I’ve created a facts module to calculate subnet block addresses.

This is helpful when creating new subnets on for instance Amazon EC2.

Example usage:

  • name: get subnet blocks
    local_action:
    module: subnet_block_facts
    start_address: 183.0.0.0
    prefix: 16
    subnet_prefix: 22

Which returns this:

{
“ansible_facts”: {
“subnet_addresses”: {
“blocks”: [
{
“block_address”: “183.0.0.0/22”,
“first_address”: “183.0.0.0”,
“last_address”: “183.0.3.255”
},

{
“block_address”: “183.0.252.0/22”,
“first_address”: “183.0.252.0”,
“last_address”: “183.0.255.255”
}
],
“first_address”: “183.0.0.0”,
“max_number_subnets”: 64,
“subnet_prefix”: 22,
“subnet_size”: 1024,
“total_block”: “183.0.0.0/16”,
“total_prefix”: 16
}
},
“changed”: false
}

Now I have 2 questions:

1: Would the Ansible community be interested in adding this to the distribution ?
2: If so, would this be the best way of naming things ?

regards,
Paul Siegmann

Will this support IPv6?

Hi Matt,

I will not add it, as AWS does not support IPV6 and I don’t have any experience with it.

I’ll accept patches though :slight_smile:

You may be interested in the ipaddr filter plugin that drybjed has written and submitted to devel

https://github.com/ansible/ansible/blob/devel/lib/ansible/runner/filter_plugins/ipaddr.py

and the docs are here:

https://github.com/ansible/ansible/blob/devel/docsite/rst/playbooks_filters_ipaddr.rst