fix nxos_static_route issues (#37614)
* fix nxos_static_route issues * remove nxos_static_route from ignorepull/4420/head
parent
0dcd8b598c
commit
0df5cfd41f
|
@ -52,13 +52,13 @@ options:
|
||||||
default: default
|
default: default
|
||||||
tag:
|
tag:
|
||||||
description:
|
description:
|
||||||
- Route tag value (numeric).
|
- Route tag value (numeric) or keyword 'default'.
|
||||||
route_name:
|
route_name:
|
||||||
description:
|
description:
|
||||||
- Name of the route. Used with the name parameter on the CLI.
|
- Name of the route or keyword 'default'. Used with the name parameter on the CLI.
|
||||||
pref:
|
pref:
|
||||||
description:
|
description:
|
||||||
- Preference or administrative difference of route (range 1-255).
|
- Preference or administrative difference of route (range 1-255) or keyword 'default'.
|
||||||
aliases:
|
aliases:
|
||||||
- admin_distance
|
- admin_distance
|
||||||
aggregate:
|
aggregate:
|
||||||
|
@ -67,8 +67,8 @@ options:
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- Manage the state of the resource.
|
- Manage the state of the resource.
|
||||||
required: true
|
|
||||||
choices: ['present','absent']
|
choices: ['present','absent']
|
||||||
|
default: 'present'
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
|
@ -105,11 +105,22 @@ def reconcile_candidate(module, candidate, prefix, w):
|
||||||
|
|
||||||
parents = []
|
parents = []
|
||||||
commands = []
|
commands = []
|
||||||
|
yrc = remove_command.replace('no ', '')
|
||||||
if w['vrf'] == 'default':
|
if w['vrf'] == 'default':
|
||||||
config = netcfg.get_section(set_command)
|
netcfg = str(netcfg).split('\n')
|
||||||
if config and state == 'absent':
|
ncfg = []
|
||||||
|
for line in netcfg:
|
||||||
|
# remove ip route commands of non-default vrfs from
|
||||||
|
# the running config just in case the same commands
|
||||||
|
# exist in default and non-default vrfs
|
||||||
|
if ' ip route' not in line:
|
||||||
|
ncfg.append(line)
|
||||||
|
if any(yrc in s for s in ncfg) and state == 'absent':
|
||||||
commands = [remove_command]
|
commands = [remove_command]
|
||||||
elif not config and state == 'present':
|
elif set_command not in ncfg and state == 'present':
|
||||||
|
if any(yrc in s for s in ncfg):
|
||||||
|
commands = [remove_command, set_command]
|
||||||
|
else:
|
||||||
commands = [set_command]
|
commands = [set_command]
|
||||||
else:
|
else:
|
||||||
parents = ['vrf context {0}'.format(w['vrf'])]
|
parents = ['vrf context {0}'.format(w['vrf'])]
|
||||||
|
@ -117,54 +128,18 @@ def reconcile_candidate(module, candidate, prefix, w):
|
||||||
if not isinstance(config, list):
|
if not isinstance(config, list):
|
||||||
config = config.split('\n')
|
config = config.split('\n')
|
||||||
config = [line.strip() for line in config]
|
config = [line.strip() for line in config]
|
||||||
if set_command in config and state == 'absent':
|
if any(yrc in s for s in config) and state == 'absent':
|
||||||
commands = [remove_command]
|
commands = [remove_command]
|
||||||
elif set_command not in config and state == 'present':
|
elif set_command not in config and state == 'present':
|
||||||
|
if any(yrc in s for s in config):
|
||||||
|
commands = [remove_command, set_command]
|
||||||
|
else:
|
||||||
commands = [set_command]
|
commands = [set_command]
|
||||||
|
|
||||||
if commands:
|
if commands:
|
||||||
candidate.add(commands, parents=parents)
|
candidate.add(commands, parents=parents)
|
||||||
|
|
||||||
|
|
||||||
def fix_prefix_to_regex(prefix):
|
|
||||||
prefix = prefix.replace('.', r'\.').replace('/', r'\/')
|
|
||||||
return prefix
|
|
||||||
|
|
||||||
|
|
||||||
def get_existing(module, prefix, warnings):
|
|
||||||
key_map = ['tag', 'pref', 'route_name', 'next_hop']
|
|
||||||
netcfg = CustomNetworkConfig(indent=2, contents=get_config(module))
|
|
||||||
parents = 'vrf context {0}'.format(module.params['vrf'])
|
|
||||||
prefix_to_regex = fix_prefix_to_regex(prefix)
|
|
||||||
|
|
||||||
route_regex = r'.*ip\sroute\s{0}\s(?P<next_hop>\S+)(\sname\s(?P<route_name>\S+))?(\stag\s(?P<tag>\d+))?(\s(?P<pref>\d+))?.*'.format(prefix_to_regex)
|
|
||||||
|
|
||||||
if module.params['vrf'] == 'default':
|
|
||||||
config = str(netcfg)
|
|
||||||
else:
|
|
||||||
config = netcfg.get_section(parents)
|
|
||||||
|
|
||||||
if config:
|
|
||||||
try:
|
|
||||||
match_route = re.match(route_regex, config, re.DOTALL)
|
|
||||||
group_route = match_route.groupdict()
|
|
||||||
|
|
||||||
for key in key_map:
|
|
||||||
if key not in group_route:
|
|
||||||
group_route[key] = ''
|
|
||||||
group_route['prefix'] = prefix
|
|
||||||
group_route['vrf'] = module.params['vrf']
|
|
||||||
except (AttributeError, TypeError):
|
|
||||||
group_route = {}
|
|
||||||
else:
|
|
||||||
group_route = {}
|
|
||||||
msg = ("VRF {0} didn't exist.".format(module.params['vrf']))
|
|
||||||
if msg not in warnings:
|
|
||||||
warnings.append(msg)
|
|
||||||
|
|
||||||
return group_route
|
|
||||||
|
|
||||||
|
|
||||||
def remove_route_command(prefix, w):
|
def remove_route_command(prefix, w):
|
||||||
return 'no ip route {0} {1}'.format(prefix, w['next_hop'])
|
return 'no ip route {0} {1}'.format(prefix, w['next_hop'])
|
||||||
|
|
||||||
|
@ -172,11 +147,12 @@ def remove_route_command(prefix, w):
|
||||||
def set_route_command(prefix, w):
|
def set_route_command(prefix, w):
|
||||||
route_cmd = 'ip route {0} {1}'.format(prefix, w['next_hop'])
|
route_cmd = 'ip route {0} {1}'.format(prefix, w['next_hop'])
|
||||||
|
|
||||||
if w['route_name']:
|
if w['route_name'] and w['route_name'] != 'default':
|
||||||
route_cmd += ' name {0}'.format(w['route_name'])
|
route_cmd += ' name {0}'.format(w['route_name'])
|
||||||
if w['tag']:
|
if w['tag']:
|
||||||
|
if w['tag'] != 'default' and w['tag'] != '0':
|
||||||
route_cmd += ' tag {0}'.format(w['tag'])
|
route_cmd += ' tag {0}'.format(w['tag'])
|
||||||
if w['pref']:
|
if w['pref'] and w['pref'] != 'default':
|
||||||
route_cmd += ' {0}'.format(w['pref'])
|
route_cmd += ' {0}'.format(w['pref'])
|
||||||
|
|
||||||
return route_cmd
|
return route_cmd
|
||||||
|
|
|
@ -1,2 +1,5 @@
|
||||||
---
|
---
|
||||||
testcase: "*"
|
testcase: "*"
|
||||||
|
vrfs:
|
||||||
|
- default
|
||||||
|
- myvrf
|
||||||
|
|
|
@ -11,8 +11,9 @@
|
||||||
route_name: testing
|
route_name: testing
|
||||||
pref: 100
|
pref: 100
|
||||||
tag: 5500
|
tag: 5500
|
||||||
vrf: testing
|
vrf: "{{ item }}"
|
||||||
provider: "{{ connection }}"
|
provider: "{{ connection }}"
|
||||||
|
with_items: "{{ vrfs }}"
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert: &true
|
- assert: &true
|
||||||
|
@ -21,28 +22,51 @@
|
||||||
|
|
||||||
- name: "Conf Idempotence"
|
- name: "Conf Idempotence"
|
||||||
nxos_static_route: *configure
|
nxos_static_route: *configure
|
||||||
|
with_items: "{{ vrfs }}"
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert: &false
|
- assert: &false
|
||||||
that:
|
that:
|
||||||
- "result.changed == false"
|
- "result.changed == false"
|
||||||
|
|
||||||
|
- name: change static route
|
||||||
|
nxos_static_route: &configure1
|
||||||
|
prefix: "192.168.20.64/24"
|
||||||
|
next_hop: "3.3.3.3"
|
||||||
|
route_name: default
|
||||||
|
pref: 10
|
||||||
|
tag: default
|
||||||
|
vrf: "{{ item }}"
|
||||||
|
provider: "{{ connection }}"
|
||||||
|
with_items: "{{ vrfs }}"
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert: *true
|
||||||
|
|
||||||
|
- name: "Conf1 Idempotence"
|
||||||
|
nxos_static_route: *configure1
|
||||||
|
with_items: "{{ vrfs }}"
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert: *false
|
||||||
|
|
||||||
- name: remove static route
|
- name: remove static route
|
||||||
nxos_static_route: &remove
|
nxos_static_route: &remove
|
||||||
prefix: "192.168.20.64/24"
|
prefix: "192.168.20.64/24"
|
||||||
next_hop: "3.3.3.3"
|
next_hop: "3.3.3.3"
|
||||||
route_name: testing
|
route_name: testing
|
||||||
pref: 100
|
pref: 100
|
||||||
tag: 5500
|
vrf: "{{ item }}"
|
||||||
vrf: testing
|
|
||||||
state: absent
|
state: absent
|
||||||
provider: "{{ connection }}"
|
provider: "{{ connection }}"
|
||||||
|
with_items: "{{ vrfs }}"
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert: *true
|
- assert: *true
|
||||||
|
|
||||||
- name: "Remove Idempotence"
|
- name: "Remove Idempotence"
|
||||||
nxos_static_route: *remove
|
nxos_static_route: *remove
|
||||||
|
with_items: "{{ vrfs }}"
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert: *false
|
- assert: *false
|
||||||
|
@ -96,9 +120,10 @@
|
||||||
route_name: testing
|
route_name: testing
|
||||||
pref: 100
|
pref: 100
|
||||||
tag: 5500
|
tag: 5500
|
||||||
vrf: testing
|
vrf: "{{ item }}"
|
||||||
state: absent
|
state: absent
|
||||||
provider: "{{ connection }}"
|
provider: "{{ connection }}"
|
||||||
|
with_items: "{{ vrfs }}"
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
|
|
||||||
- name: remove static route aggregate
|
- name: remove static route aggregate
|
||||||
|
|
|
@ -1287,7 +1287,6 @@ lib/ansible/modules/network/nxos/nxos_pim_interface.py E326
|
||||||
lib/ansible/modules/network/nxos/nxos_pim_rp_address.py E326
|
lib/ansible/modules/network/nxos/nxos_pim_rp_address.py E326
|
||||||
lib/ansible/modules/network/nxos/nxos_reboot.py E325
|
lib/ansible/modules/network/nxos/nxos_reboot.py E325
|
||||||
lib/ansible/modules/network/nxos/nxos_smu.py E324
|
lib/ansible/modules/network/nxos/nxos_smu.py E324
|
||||||
lib/ansible/modules/network/nxos/nxos_static_route.py E324
|
|
||||||
lib/ansible/modules/network/nxos/nxos_system.py E325
|
lib/ansible/modules/network/nxos/nxos_system.py E325
|
||||||
lib/ansible/modules/network/nxos/nxos_vpc.py E324
|
lib/ansible/modules/network/nxos/nxos_vpc.py E324
|
||||||
lib/ansible/modules/network/nxos/nxos_vpc_interface.py E325
|
lib/ansible/modules/network/nxos/nxos_vpc_interface.py E325
|
||||||
|
|
Loading…
Reference in New Issue