nxos_vtp_*: Fixes n6k issues (#55737)

* Add n6k support for nxos_vtp_domain

* Add n6k support for nxos_vtp_version

* Add n6k support for nxos_vtp_password

* Fix shippable error
pull/56288/head
Mike Wiebe 6 years ago committed by Trishna Guha
parent dd0b0ae47b
commit d55c0cf8dc

@ -89,15 +89,12 @@ changed:
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 get_capabilities
from ansible.module_utils.basic import AnsibleModule
import re
def execute_show_command(command, module, command_type='cli_show'):
if 'status' not in command:
output = 'json'
else:
output = 'text'
def execute_show_command(command, module, output='json'):
cmds = [{
'command': command,
'output': output,
@ -119,7 +116,7 @@ def flatten_list(command_lists):
def get_vtp_config(module):
command = 'show vtp status'
body = execute_show_command(
command, module)[0]
command, module, 'text')[0]
vtp_parsed = {}
if body:
@ -148,15 +145,23 @@ def get_vtp_config(module):
def get_vtp_password(module):
command = 'show vtp password'
body = execute_show_command(command, module)[0]
try:
password = body['passwd']
if password:
return str(password)
else:
return ""
except TypeError:
return ""
output = 'json'
cap = get_capabilities(module)['device_info']['network_os_model']
if re.search(r'Nexus 6', cap):
output = 'text'
body = execute_show_command(command, module, output)[0]
if output == 'json':
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():

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

@ -84,18 +84,12 @@ changed:
'''
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 get_capabilities
from ansible.module_utils.basic import AnsibleModule
import re
import re
def execute_show_command(command, module, command_type='cli_show'):
if 'status' not in command:
output = 'json'
else:
output = 'text'
def execute_show_command(command, module, output='json'):
cmds = [{
'command': command,
'output': output,
@ -117,7 +111,7 @@ def flatten_list(command_lists):
def get_vtp_config(module):
command = 'show vtp status'
body = execute_show_command(
command, module)[0]
command, module, 'text')[0]
vtp_parsed = {}
if body:
@ -146,15 +140,23 @@ def get_vtp_config(module):
def get_vtp_password(module):
command = 'show vtp password'
body = execute_show_command(command, module)[0]
try:
password = body['passwd']
if password:
return str(password)
else:
return ""
except TypeError:
return ""
output = 'json'
cap = get_capabilities(module)['device_info']['network_os_model']
if re.search(r'Nexus 6', cap):
output = 'text'
body = execute_show_command(command, module, output)[0]
if output == 'json':
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():

@ -3,7 +3,18 @@
- debug: msg="Using provider={{ connection.transport }}"
when: ansible_connection == "local"
- set_fact: vtp_run="true"
- set_fact: vtp_run="false"
when: platform is search('N3K-F|N9K-F')
- block:
- name: disable feature vtp
nxos_feature:
feature: vtp
provider: "{{ connection }}"
state: disabled
ignore_errors: yes
- name: enable feature vtp
nxos_feature:
feature: vtp
@ -28,6 +39,8 @@
that:
- "result.changed == false"
when: vtp_run
always:
- name: disable feature vtp
nxos_feature:

@ -3,7 +3,18 @@
- debug: msg="Using provider={{ connection.transport }}"
when: ansible_connection == "local"
- set_fact: vtp_run="true"
- set_fact: vtp_run="false"
when: platform is search('N3K-F|N9K-F')
- block:
- name: disable feature vtp
nxos_feature:
feature: vtp
provider: "{{ connection }}"
state: disabled
ignore_errors: yes
- name: enable feature vtp
nxos_feature:
feature: vtp
@ -49,6 +60,8 @@
- assert: *false
when: vtp_run
always:
- name: disable feature vtp
nxos_feature:

@ -3,7 +3,18 @@
- debug: msg="Using provider={{ connection.transport }}"
when: ansible_connection == "local"
- set_fact: vtp_run="true"
- set_fact: vtp_run="false"
when: platform is search('N3K-F|N9K-F')
- block:
- name: disable feature vtp
nxos_feature:
feature: vtp
provider: "{{ connection }}"
state: disabled
ignore_errors: yes
- name: enable feature vtp
nxos_feature:
feature: vtp
@ -28,6 +39,8 @@
that:
- "result.changed == false"
when: vtp_run
always:
- name: disable feature vtp
nxos_feature:

Loading…
Cancel
Save