|
|
|
@ -61,43 +61,21 @@ EXAMPLES = '''
|
|
|
|
|
nxos_vrf_interface:
|
|
|
|
|
vrf: ntc
|
|
|
|
|
interface: Ethernet1/1
|
|
|
|
|
host: 68.170.147.165
|
|
|
|
|
state: present
|
|
|
|
|
|
|
|
|
|
- name: Ensure ntc VRF does not exist on Eth1/1
|
|
|
|
|
nxos_vrf_interface:
|
|
|
|
|
vrf: ntc
|
|
|
|
|
interface: Ethernet1/1
|
|
|
|
|
host: 68.170.147.165
|
|
|
|
|
state: absent
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
RETURN = '''
|
|
|
|
|
proposed:
|
|
|
|
|
description: k/v pairs of parameters passed into module
|
|
|
|
|
returned: always
|
|
|
|
|
type: dict
|
|
|
|
|
sample: {"interface": "loopback16", "vrf": "ntc"}
|
|
|
|
|
existing:
|
|
|
|
|
description: k/v pairs of existing vrf on the interface
|
|
|
|
|
returned: always
|
|
|
|
|
type: dict
|
|
|
|
|
sample: {"interface": "loopback16", "vrf": ""}
|
|
|
|
|
end_state:
|
|
|
|
|
description: k/v pairs of vrf after module execution
|
|
|
|
|
returned: always
|
|
|
|
|
type: dict
|
|
|
|
|
sample: {"interface": "loopback16", "vrf": "ntc"}
|
|
|
|
|
updates:
|
|
|
|
|
commands:
|
|
|
|
|
description: commands sent to the device
|
|
|
|
|
returned: always
|
|
|
|
|
type: list
|
|
|
|
|
sample: ["interface loopback16", "vrf member ntc"]
|
|
|
|
|
changed:
|
|
|
|
|
description: check to see if a change was made on the device
|
|
|
|
|
returned: always
|
|
|
|
|
type: boolean
|
|
|
|
|
sample: true
|
|
|
|
|
'''
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
|
@ -106,10 +84,7 @@ from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WARNINGS = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def execute_show_command(command, module, command_type='cli_show'):
|
|
|
|
|
def execute_show_command(command, module):
|
|
|
|
|
if 'show run' not in command:
|
|
|
|
|
output = 'json'
|
|
|
|
|
else:
|
|
|
|
@ -118,8 +93,7 @@ def execute_show_command(command, module, command_type='cli_show'):
|
|
|
|
|
'command': command,
|
|
|
|
|
'output': output,
|
|
|
|
|
}]
|
|
|
|
|
body = run_commands(module, cmds)
|
|
|
|
|
return body
|
|
|
|
|
return run_commands(module, cmds)[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_interface_type(interface):
|
|
|
|
@ -145,7 +119,7 @@ def get_interface_mode(interface, intf_type, module):
|
|
|
|
|
mode = 'unknown'
|
|
|
|
|
|
|
|
|
|
if intf_type in ['ethernet', 'portchannel']:
|
|
|
|
|
body = execute_show_command(command, module)[0]
|
|
|
|
|
body = execute_show_command(command, module)
|
|
|
|
|
interface_table = body['TABLE_interface']['ROW_interface']
|
|
|
|
|
mode = str(interface_table.get('eth_mode', 'layer3'))
|
|
|
|
|
if mode == 'access' or mode == 'trunk':
|
|
|
|
@ -158,7 +132,7 @@ def get_interface_mode(interface, intf_type, module):
|
|
|
|
|
def get_vrf_list(module):
|
|
|
|
|
command = 'show vrf all'
|
|
|
|
|
vrf_list = []
|
|
|
|
|
body = execute_show_command(command, module)[0]
|
|
|
|
|
body = execute_show_command(command, module)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
vrf_table = body['TABLE_vrf']['ROW_vrf']
|
|
|
|
@ -179,8 +153,7 @@ def get_interface_info(interface, module):
|
|
|
|
|
vrf_regex = ".*vrf\s+member\s+(?P<vrf>\S+).*"
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
body = execute_show_command(command, module,
|
|
|
|
|
command_type='cli_show_ascii')[0]
|
|
|
|
|
body = execute_show_command(command, module)
|
|
|
|
|
match_vrf = re.match(vrf_regex, body, re.DOTALL)
|
|
|
|
|
group_vrf = match_vrf.groupdict()
|
|
|
|
|
vrf = group_vrf["vrf"]
|
|
|
|
@ -194,8 +167,7 @@ def is_default(interface, module):
|
|
|
|
|
command = 'show run interface {0}'.format(interface)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
body = execute_show_command(command, module,
|
|
|
|
|
command_type='cli_show_ascii')[0]
|
|
|
|
|
body = execute_show_command(command, module)
|
|
|
|
|
raw_list = body.split('\n')
|
|
|
|
|
if raw_list[-1].startswith('interface'):
|
|
|
|
|
return True
|
|
|
|
@ -210,20 +182,16 @@ def main():
|
|
|
|
|
argument_spec = dict(
|
|
|
|
|
vrf=dict(required=True),
|
|
|
|
|
interface=dict(type='str', required=True),
|
|
|
|
|
state=dict(default='present', choices=['present', 'absent'],
|
|
|
|
|
required=False),
|
|
|
|
|
include_defaults=dict(default=False),
|
|
|
|
|
config=dict(),
|
|
|
|
|
save=dict(type='bool', default=False)
|
|
|
|
|
state=dict(default='present', choices=['present', 'absent'], required=False),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
argument_spec.update(nxos_argument_spec)
|
|
|
|
|
|
|
|
|
|
module = AnsibleModule(argument_spec=argument_spec,
|
|
|
|
|
supports_check_mode=True)
|
|
|
|
|
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
|
|
|
|
|
|
|
|
|
|
warnings = list()
|
|
|
|
|
check_args(module, warnings)
|
|
|
|
|
results = {'changed': False, 'commands': [], 'warnings': warnings}
|
|
|
|
|
|
|
|
|
|
vrf = module.params['vrf']
|
|
|
|
|
interface = module.params['interface'].lower()
|
|
|
|
@ -231,7 +199,7 @@ def main():
|
|
|
|
|
|
|
|
|
|
current_vrfs = get_vrf_list(module)
|
|
|
|
|
if vrf not in current_vrfs:
|
|
|
|
|
WARNINGS.append("The VRF is not present/active on the device. "
|
|
|
|
|
warnings.append("The VRF is not present/active on the device. "
|
|
|
|
|
"Use nxos_vrf to fix this.")
|
|
|
|
|
|
|
|
|
|
intf_type = get_interface_type(interface)
|
|
|
|
@ -287,16 +255,9 @@ def main():
|
|
|
|
|
if 'configure' in commands:
|
|
|
|
|
commands.pop(0)
|
|
|
|
|
|
|
|
|
|
results = {}
|
|
|
|
|
results['proposed'] = proposed
|
|
|
|
|
results['existing'] = existing
|
|
|
|
|
results['end_state'] = end_state
|
|
|
|
|
results['updates'] = commands
|
|
|
|
|
results['commands'] = commands
|
|
|
|
|
results['changed'] = changed
|
|
|
|
|
|
|
|
|
|
if WARNINGS:
|
|
|
|
|
results['warnings'] = WARNINGS
|
|
|
|
|
|
|
|
|
|
module.exit_json(**results)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|