diff --git a/changelogs/fragments/61168-ce_evpn_bgp_rrl-to-fix-bugs.yml b/changelogs/fragments/61168-ce_evpn_bgp_rrl-to-fix-bugs.yml new file mode 100644 index 00000000000..fe65b0d9262 --- /dev/null +++ b/changelogs/fragments/61168-ce_evpn_bgp_rrl-to-fix-bugs.yml @@ -0,0 +1,2 @@ +bugfixes: +- ce_evpn_bgp_rr - update to fix some bugs - Modify the configured query statement and replace get_config with exec_command. (https://github.com/ansible/ansible/pull/61168) diff --git a/lib/ansible/modules/network/cloudengine/ce_evpn_bgp_rr.py b/lib/ansible/modules/network/cloudengine/ce_evpn_bgp_rr.py index 41079e09ceb..ce1992be1ac 100644 --- a/lib/ansible/modules/network/cloudengine/ce_evpn_bgp_rr.py +++ b/lib/ansible/modules/network/cloudengine/ce_evpn_bgp_rr.py @@ -169,7 +169,7 @@ changed: import re from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.cloudengine.ce import get_config, load_config, ce_argument_spec +from ansible.module_utils.network.cloudengine.ce import exec_command, load_config, ce_argument_spec def is_config_exist(cmp_cfg, test_cfg): @@ -259,19 +259,17 @@ class EvpnBgpRr(object): def get_config_in_bgp_view(self): """Get configuration in BGP view""" - flags = list() - exp = " | section include" + cmd = "display current-configuration | section include" if self.as_number: if self.bgp_instance: - exp += " bgp %s instance %s" % (self.as_number, + cmd += " bgp %s instance %s" % (self.as_number, self.bgp_instance) else: - exp += " bgp %s" % self.as_number - - flags.append(exp) - config = get_config(self.module, flags) - cmd = 'display current-configuration ' + exp - config = config.strip() if config else "" + cmd += " bgp %s" % self.as_number + rc, out, err = exec_command(self.module, cmd) + if rc != 0: + self.module.fail_json(msg=err) + config = out.strip() if out else "" if cmd == config: return '' @@ -423,27 +421,27 @@ class EvpnBgpRr(object): self.cli_add_command(view_cmd) if self.bgp_evpn_enable == 'disable': - self.cli_add_command(" undo l2vpn-family evpn") + self.cli_add_command("undo l2vpn-family evpn") else: - self.cli_add_command(" l2vpn-family evpn") + self.cli_add_command("l2vpn-family evpn") if self.reflect_client and self.reflect_client != self.cur_config['reflect_client']: if self.reflect_client == 'enable': - self.cli_add_command(" peer %s enable" % self.peer) + self.cli_add_command("peer %s enable" % self.peer) self.cli_add_command( - " peer %s reflect-client" % self.peer) + "peer %s reflect-client" % self.peer) else: self.cli_add_command( - " undo peer %s reflect-client" % self.peer) - self.cli_add_command(" undo peer %s enable" % self.peer) + "undo peer %s reflect-client" % self.peer) + self.cli_add_command("undo peer %s enable" % self.peer) if self.cur_config['bgp_evpn_enable'] == 'enable': if self.policy_vpn_target and self.policy_vpn_target != self.cur_config['policy_vpn_target']: if self.policy_vpn_target == 'enable': - self.cli_add_command(" policy vpn-target") + self.cli_add_command("policy vpn-target") else: - self.cli_add_command(" undo policy vpn-target") + self.cli_add_command("undo policy vpn-target") else: if self.policy_vpn_target and self.policy_vpn_target == 'disable': - self.cli_add_command(" undo policy vpn-target") + self.cli_add_command("undo policy vpn-target") if self.commands: self.cli_load_config(self.commands)