diff --git a/changelogs/fragments/62498-ce_static_route-to-fix-bugs.yml b/changelogs/fragments/62498-ce_static_route-to-fix-bugs.yml new file mode 100644 index 00000000000..3d1f5dc9cfd --- /dev/null +++ b/changelogs/fragments/62498-ce_static_route-to-fix-bugs.yml @@ -0,0 +1,2 @@ +bugfixes: +- ce_static_route - update to fix some bugs - Add some update statements. (https://github.com/ansible/ansible/pull/62498) diff --git a/lib/ansible/modules/network/cloudengine/ce_static_route.py b/lib/ansible/modules/network/cloudengine/ce_static_route.py index 9f82126af28..079a4069a17 100644 --- a/lib/ansible/modules/network/cloudengine/ce_static_route.py +++ b/lib/ansible/modules/network/cloudengine/ce_static_route.py @@ -471,8 +471,10 @@ class StaticRoute(object): if not self.changed: return if self.aftype == "v4": + aftype = "ip" maskstr = self.convert_len_to_mask(self.mask) else: + aftype = "ipv6" maskstr = self.mask if self.next_hop is None: next_hop = '' @@ -493,38 +495,38 @@ class StaticRoute(object): if self.state == "present": if self.vrf != "_public_": if self.destvrf != "_public_": - self.updates_cmd.append('ip route-static vpn-instance %s %s %s vpn-instance %s %s' - % (vrf, self.prefix, maskstr, destvrf, next_hop)) + self.updates_cmd.append('%s route-static vpn-instance %s %s %s vpn-instance %s %s' + % (aftype, vrf, self.prefix, maskstr, destvrf, next_hop)) else: - self.updates_cmd.append('ip route-static vpn-instance %s %s %s %s %s' - % (vrf, self.prefix, maskstr, nhp_interface, next_hop)) + self.updates_cmd.append('%s route-static vpn-instance %s %s %s %s %s' + % (aftype, vrf, self.prefix, maskstr, nhp_interface, next_hop)) elif self.destvrf != "_public_": - self.updates_cmd.append('ip route-static %s %s vpn-instance %s %s' - % (self.prefix, maskstr, self.destvrf, next_hop)) + self.updates_cmd.append('%s route-static %s %s vpn-instance %s %s' + % (aftype, self.prefix, maskstr, self.destvrf, next_hop)) else: - self.updates_cmd.append('ip route-static %s %s %s %s' - % (self.prefix, maskstr, nhp_interface, next_hop)) + self.updates_cmd.append('%s route-static %s %s %s %s' + % (aftype, self.prefix, maskstr, nhp_interface, next_hop)) if self.pref: - self.updates_cmd.append(' preference %s' % (self.pref)) + self.updates_cmd[0] += ' preference %s' % (self.pref) if self.tag: - self.updates_cmd.append(' tag %s' % (self.tag)) + self.updates_cmd[0] += ' tag %s' % (self.tag) if self.description: - self.updates_cmd.append(' description %s' % (self.description)) + self.updates_cmd[0] += ' description %s' % (self.description) if self.state == "absent": if self.vrf != "_public_": if self.destvrf != "_public_": - self.updates_cmd.append('undo ip route-static vpn-instance %s %s %s vpn-instance %s %s' - % (vrf, self.prefix, maskstr, destvrf, next_hop)) + self.updates_cmd.append('undo %s route-static vpn-instance %s %s %s vpn-instance %s %s' + % (aftype, vrf, self.prefix, maskstr, destvrf, next_hop)) else: - self.updates_cmd.append('undo ip route-static vpn-instance %s %s %s %s %s' - % (vrf, self.prefix, maskstr, nhp_interface, next_hop)) + self.updates_cmd.append('undo %s route-static vpn-instance %s %s %s %s %s' + % (aftype, vrf, self.prefix, maskstr, nhp_interface, next_hop)) elif self.destvrf != "_public_": - self.updates_cmd.append('undo ip route-static %s %s vpn-instance %s %s' - % (self.prefix, maskstr, self.destvrf, self.next_hop)) + self.updates_cmd.append('undo %s route-static %s %s vpn-instance %s %s' + % (aftype, self.prefix, maskstr, self.destvrf, self.next_hop)) else: - self.updates_cmd.append('undo ip route-static %s %s %s %s' - % (self.prefix, maskstr, nhp_interface, next_hop)) + self.updates_cmd.append('undo %s route-static %s %s %s %s' + % (aftype, self.prefix, maskstr, nhp_interface, next_hop)) def operate_static_route(self, version, prefix, mask, nhp_interface, next_hop, vrf, destvrf, state): """operate ipv4 static route"""