The ansible collection Jonny007MKD.interfaces
meta | ||
roles/gather_ip_interfaces/tasks | ||
.gitignore | ||
galaxy.yml | ||
README.md |
Ansible Collection - Jonny007MKD.interfaces
Role gather_ip_interfaces
Ansible facts contain information about the IP configuration in a non-optimal way (IMO). This role restructures the facts and sets new variables:
interfaces
A list of dicts containing the configuration of each network interfaces. The specific content comes from the ansible variables; this is only an aggregate of all interface dictionaries.
ok: [localhost] => {
"interfaces": [
{
"active": true,
"device": "lo",
"features": {
"esp_hw_offload": "off [fixed]",
"esp_tx_csum_hw_offload": "off [fixed]",
"fcoe_mtu": "off [fixed]",
"generic_receive_offload": "on",
"generic_segmentation_offload": "on",
...
},
"hw_timestamp_filters": [],
"ipv4": {
"address": "127.0.0.1",
"broadcast": "",
"netmask": "255.0.0.0",
"network": "127.0.0.0",
"prefix": "8"
},
"ipv6": [
{
"address": "::1",
"prefix": "128",
"scope": "host"
}
],
"mtu": 65536,
"promisc": false,
"timestamping": [],
"type": "loopback"
},
{
"active": true,
"device": "wlo1",
"features": {
"esp_hw_offload": "off [fixed]",
"esp_tx_csum_hw_offload": "off [fixed]",
"fcoe_mtu": "off [fixed]",
"generic_receive_offload": "on",
"generic_segmentation_offload": "off [requested on]",
...
},
"hw_timestamp_filters": [],
"ipv4": {
"address": "192.168.1.100",
"broadcast": "192.168.1.255",
"netmask": "255.255.255.0",
"network": "192.168.1.0",
"prefix": "9"
},
"ipv6": [
{
"address": "fddc:ffeb:2910::206",
"prefix": "128",
"scope": "global"
},
{
"address": "fddc:ffeb:2910:0:18c7:c3ff:efa6:35ae",
"prefix": "64",
"scope": "global"
}
],
"macaddress": "18:c7:c3:a6:35:ae",
"module": "rtw88_8821ce",
"mtu": 1500,
"pciid": "0000:01:00.0",
"promisc": false,
"timestamping": [],
"type": "ether"
}
]
}
all_ipv4_addresses
A list of dicts with the information about this machine's IPv4 networks
ok: [localhost] => {
"all_ipv4_addresses": [
{
"interface": "lo",
"address": "127.0.0.1",
"address_prefix": "127.0.0.1/8",
"broadcast": "",
"netmask": "255.0.0.0",
"network": "127.0.0.0",
"network_prefix": "127.0.0.0/8",
"prefix": "8"
},
{
"interface": "wlo1",
"address": "192.168.1.100",
"address_prefix": "192.168.1.100/24",
"broadcast": "192.168.1.255",
"netmask": "255.255.255.0",
"network": "192.168.1.0",
"network_prefix": "192.168.1.0/24",
"prefix": "24"
}
]
}
all_ipv6_addresses
A list of dicts with the information about this machine's IPv6 networks
ok: [localhost] => {
"all_ipv6_addresses": [
{
"address": "::1",
"address_prefix": "::1/128",
"interface": "lo",
"prefix": "128",
"scope": "host"
},
{
"address": "fddc:ffeb:2910::206",
"address_prefix": "fddc:ffeb:2910::206/128",
"interface": "wlo1",
"prefix": "128",
"scope": "global"
},
{
"address": "fddc:ffeb:2910:0:18c7:c3ff:efa6:35ae",
"address_prefix": "fddc:ffeb:2910:0:18c7:c3ff:efa6:35ae/64",
"interface": "wlo1",
"prefix": "64",
"scope": "global"
},
]
}
Usage
Simply include the role in your playbook:
---
- name: My playbook
hosts: localhost
connection: local
roles:
- Jonny007MKD.interfaces.gather_ip_interfaces
Or include it in your role when you need it:
- name: Gather IP facts on servers
ansible.builtin.import_role:
name: Jonny007MKD.interfaces.gather_ip_interfaces