|
|
@ -101,15 +101,12 @@ changed:
|
|
|
|
|
|
|
|
|
|
|
|
from ansible.module_utils.network.nxos.nxos import load_config, run_commands
|
|
|
|
from ansible.module_utils.network.nxos.nxos import load_config, run_commands
|
|
|
|
from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, check_args
|
|
|
|
from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, check_args
|
|
|
|
|
|
|
|
from ansible.module_utils.network.nxos.nxos import get_capabilities
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
import re
|
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def execute_show_command(command, module, command_type='cli_show'):
|
|
|
|
def execute_show_command(command, module, output='json'):
|
|
|
|
if 'status' not in command:
|
|
|
|
|
|
|
|
output = 'json'
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
output = 'text'
|
|
|
|
|
|
|
|
cmds = [{
|
|
|
|
cmds = [{
|
|
|
|
'command': command,
|
|
|
|
'command': command,
|
|
|
|
'output': output,
|
|
|
|
'output': output,
|
|
|
@ -145,7 +142,7 @@ def get_vtp_config(module):
|
|
|
|
command = 'show vtp status'
|
|
|
|
command = 'show vtp status'
|
|
|
|
|
|
|
|
|
|
|
|
body = execute_show_command(
|
|
|
|
body = execute_show_command(
|
|
|
|
command, module)[0]
|
|
|
|
command, module, 'text')[0]
|
|
|
|
vtp_parsed = {}
|
|
|
|
vtp_parsed = {}
|
|
|
|
|
|
|
|
|
|
|
|
if body:
|
|
|
|
if body:
|
|
|
@ -174,15 +171,23 @@ def get_vtp_config(module):
|
|
|
|
|
|
|
|
|
|
|
|
def get_vtp_password(module):
|
|
|
|
def get_vtp_password(module):
|
|
|
|
command = 'show vtp password'
|
|
|
|
command = 'show vtp password'
|
|
|
|
body = execute_show_command(command, module)[0]
|
|
|
|
output = 'json'
|
|
|
|
try:
|
|
|
|
cap = get_capabilities(module)['device_info']['network_os_model']
|
|
|
|
password = body['passwd']
|
|
|
|
if re.search(r'Nexus 6', cap):
|
|
|
|
if password:
|
|
|
|
output = 'text'
|
|
|
|
return str(password)
|
|
|
|
|
|
|
|
else:
|
|
|
|
body = execute_show_command(command, module, output)[0]
|
|
|
|
return ""
|
|
|
|
|
|
|
|
except TypeError:
|
|
|
|
if output == 'json':
|
|
|
|
return ""
|
|
|
|
password = body.get('passwd', '')
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
password = ''
|
|
|
|
|
|
|
|
rp = r'VTP Password: (\S+)'
|
|
|
|
|
|
|
|
mo = re.search(rp, body)
|
|
|
|
|
|
|
|
if mo:
|
|
|
|
|
|
|
|
password = mo.group(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return str(password)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
@ -214,8 +219,8 @@ def main():
|
|
|
|
|
|
|
|
|
|
|
|
commands = []
|
|
|
|
commands = []
|
|
|
|
if state == 'absent':
|
|
|
|
if state == 'absent':
|
|
|
|
# if vtp_password is not set, some devices returns '\\'
|
|
|
|
# if vtp_password is not set, some devices returns '\\' or the string 'None'
|
|
|
|
if not existing['vtp_password'] or existing['vtp_password'] == '\\':
|
|
|
|
if not existing['vtp_password'] or existing['vtp_password'] == '\\' or existing['vtp_password'] == 'None':
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
elif vtp_password is not None:
|
|
|
|
elif vtp_password is not None:
|
|
|
|
if existing['vtp_password'] == proposed['vtp_password']:
|
|
|
|
if existing['vtp_password'] == proposed['vtp_password']:
|
|
|
|