Skip to content

Commit 6331847

Browse files
BugFix: netbox_ip_address: normalize address to /32 if no cidr provided (#78)
1 parent 67f7739 commit 6331847

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

plugins/module_utils/netbox_ipam.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ def run(self):
147147
data = self.data
148148

149149
if self.endpoint == "ip_addresses":
150+
if data.get("address"):
151+
try:
152+
data["address"] = to_text(ipaddress.ip_network(data["address"]))
153+
except ValueError:
154+
pass
150155
name = data.get("address")
151156
elif self.endpoint in ["aggregates", "prefixes"]:
152157
name = data.get("prefix")

tests/integration/integration-tests.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@
432432
netbox_url: http://localhost.org:32768
433433
netbox_token: 0123456789abcdef0123456789abcdef01234567
434434
data:
435-
address: 192.168.1.10
435+
address: 192.168.1.10/30
436436
state: absent
437437
register: test_three
438438

@@ -442,7 +442,7 @@
442442
- test_three is changed
443443
- test_three['diff']['before']['state'] == "present"
444444
- test_three['diff']['after']['state'] == "absent"
445-
- test_three['msg'] == "ip_address 192.168.1.10 deleted"
445+
- test_three['msg'] == "ip_address 192.168.1.10/30 deleted"
446446

447447
- name: "4 - Create IP in global VRF - 192.168.1.20/30 - State: Present"
448448
netbox_ip_address:
@@ -687,6 +687,25 @@
687687
- test_fourteen['ip_address']['address'] == "10.188.1.100/24"
688688
- test_fourteen['ip_address']['family'] == 4
689689
- test_fourteen['ip_address']['interface'] == 3
690+
691+
- name: "15 - Create IP address with no mask - State: Present"
692+
netbox_ip_address:
693+
netbox_url: http://localhost.org:32768
694+
netbox_token: 0123456789abcdef0123456789abcdef01234567
695+
data:
696+
address: 10.120.10.1
697+
state: present
698+
register: test_fifteen
699+
700+
- name: "15 - ASSERT"
701+
assert:
702+
that:
703+
- test_fifteen is changed
704+
- test_fifteen['diff']['before']['state'] == "absent"
705+
- test_fifteen['diff']['after']['state'] == "present"
706+
- test_fifteen['msg'] == "ip_address 10.120.10.1/32 created"
707+
- test_fifteen['ip_address']['address'] == "10.120.10.1/32"
708+
690709
##
691710
##
692711
### NETBOX_PREFIX

0 commit comments

Comments
 (0)