diff --git a/changelogs/fragments/fix_virtual_ip_facts_issue.yaml b/changelogs/fragments/fix_virtual_ip_facts_issue.yaml new file mode 100644 index 000000000..b968b3387 --- /dev/null +++ b/changelogs/fragments/fix_virtual_ip_facts_issue.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - Fix secondary ip address parsing. diff --git a/plugins/module_utils/network/eos/facts/l3_interfaces/l3_interfaces.py b/plugins/module_utils/network/eos/facts/l3_interfaces/l3_interfaces.py index 4cf1f07f9..8648ed1aa 100644 --- a/plugins/module_utils/network/eos/facts/l3_interfaces/l3_interfaces.py +++ b/plugins/module_utils/network/eos/facts/l3_interfaces/l3_interfaces.py @@ -100,10 +100,10 @@ def render_config(self, spec, conf): for match in matches: address, dummy, remainder = match.partition(" ") if address == "virtual": - ipv4 = {"virtual": True, "address": remainder} + ipv4 = {"virtual": True, "address": remainder.split(" ")[0]} else: ipv4 = {"address": address} - if remainder == "secondary": + if "secondary" in remainder: ipv4["secondary"] = True config["ipv4"].append(ipv4) diff --git a/tests/unit/modules/network/eos/test_eos_l3_interfaces.py b/tests/unit/modules/network/eos/test_eos_l3_interfaces.py index 364c12d8e..a7970455e 100644 --- a/tests/unit/modules/network/eos/test_eos_l3_interfaces.py +++ b/tests/unit/modules/network/eos/test_eos_l3_interfaces.py @@ -294,6 +294,8 @@ def test_eos_l3_interfaces_parsed(self): "ip address 198.51.100.14/24", "interface Ethernet2", "ip address 203.0.113.27/24", + "interface Vlan100", + "ip address virtual 192.13.45.13/24 secondary", ] parsed_str = "\n".join(commands) set_module_args(dict(running_config=parsed_str, state="parsed")) @@ -301,6 +303,10 @@ def test_eos_l3_interfaces_parsed(self): parsed_list = [ {"name": "Ethernet1", "ipv4": [{"address": "198.51.100.14/24"}]}, {"name": "Ethernet2", "ipv4": [{"address": "203.0.113.27/24"}]}, + { + "name": "Vlan100", + "ipv4": [{"address": "192.13.45.13/24", "secondary": True, "virtual": True}], + }, ] self.assertEqual(parsed_list, result["parsed"])