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
This commit is contained in:
Mike Wiebe 2019-05-10 01:24:51 -04:00 committed by Trishna Guha
parent dd0b0ae47b
commit d55c0cf8dc
6 changed files with 101 additions and 50 deletions

View file

@ -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 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,
@ -119,7 +116,7 @@ def flatten_list(command_lists):
def get_vtp_config(module): 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:
@ -148,15 +145,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():

View file

@ -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']:

View file

@ -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 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 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,
@ -117,7 +111,7 @@ def flatten_list(command_lists):
def get_vtp_config(module): 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:
@ -146,15 +140,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():

View file

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

View file

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

View file

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