1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

fix nxos_system issues (#40347)

This commit is contained in:
saichint 2018-05-22 01:49:34 -07:00 committed by Trishna Guha
parent 7eb98660a4
commit 97070c9688
5 changed files with 208 additions and 59 deletions

View file

@ -36,14 +36,15 @@ description:
options: options:
hostname: hostname:
description: description:
- Configure the device hostname parameter. This option takes an ASCII string value. - Configure the device hostname parameter. This option takes an ASCII string value
or keyword 'default'
domain_name: domain_name:
description: description:
- Configures the default domain - Configures the default domain
name suffix to be used when referencing this node by its name suffix to be used when referencing this node by its
FQDN. This argument accepts either a list of domain names or FQDN. This argument accepts either a list of domain names or
a list of dicts that configure the domain name and VRF name. See a list of dicts that configure the domain name and VRF name or
examples. keyword 'default'. See examples.
domain_lookup: domain_lookup:
description: description:
- Enables or disables the DNS - Enables or disables the DNS
@ -55,17 +56,17 @@ options:
- Configures a list of domain - Configures a list of domain
name suffixes to search when performing DNS name resolution. name suffixes to search when performing DNS name resolution.
This argument accepts either a list of domain names or This argument accepts either a list of domain names or
a list of dicts that configure the domain name and VRF name. See a list of dicts that configure the domain name and VRF name or
examples. keyword 'default'. See examples.
name_servers: name_servers:
description: description:
- List of DNS name servers by IP address to use to perform name resolution - List of DNS name servers by IP address to use to perform name resolution
lookups. This argument accepts either a list of DNS servers or lookups. This argument accepts either a list of DNS servers or
a list of hashes that configure the name server and VRF name. See a list of hashes that configure the name server and VRF name or
examples. keyword 'default'. See examples.
system_mtu: system_mtu:
description: description:
- Specifies the mtu, must be an integer. - Specifies the mtu, must be an integer or keyword 'default'.
state: state:
description: description:
- State of the configuration - State of the configuration
@ -174,15 +175,26 @@ def map_obj_to_commands(want, have, module):
if state == 'present': if state == 'present':
if needs_update('hostname'): if needs_update('hostname'):
if want['hostname'] == 'default':
if have['hostname']:
commands.append('no hostname')
else:
commands.append('hostname %s' % want['hostname']) commands.append('hostname %s' % want['hostname'])
if needs_update('domain_lookup'): if want.get('domain_lookup') is not None:
if have.get('domain_lookup') != want.get('domain_lookup'):
cmd = 'ip domain-lookup' cmd = 'ip domain-lookup'
if want['domain_lookup'] is False: if want['domain_lookup'] is False:
cmd = 'no %s' % cmd cmd = 'no %s' % cmd
commands.append(cmd) commands.append(cmd)
if want['domain_name']: if want['domain_name']:
if want.get('domain_name')[0]['name'] == 'default':
if have['domain_name']:
for item in have['domain_name']:
cmd = 'no ip domain-name %s' % item['name']
remove(cmd, commands, item['vrf'])
else:
for item in difference(have, want, 'domain_name'): for item in difference(have, want, 'domain_name'):
cmd = 'no ip domain-name %s' % item['name'] cmd = 'no ip domain-name %s' % item['name']
remove(cmd, commands, item['vrf']) remove(cmd, commands, item['vrf'])
@ -191,6 +203,12 @@ def map_obj_to_commands(want, have, module):
add(cmd, commands, item['vrf']) add(cmd, commands, item['vrf'])
if want['domain_search']: if want['domain_search']:
if want.get('domain_search')[0]['name'] == 'default':
if have['domain_search']:
for item in have['domain_search']:
cmd = 'no ip domain-list %s' % item['name']
remove(cmd, commands, item['vrf'])
else:
for item in difference(have, want, 'domain_search'): for item in difference(have, want, 'domain_search'):
cmd = 'no ip domain-list %s' % item['name'] cmd = 'no ip domain-list %s' % item['name']
remove(cmd, commands, item['vrf']) remove(cmd, commands, item['vrf'])
@ -199,6 +217,12 @@ def map_obj_to_commands(want, have, module):
add(cmd, commands, item['vrf']) add(cmd, commands, item['vrf'])
if want['name_servers']: if want['name_servers']:
if want.get('name_servers')[0]['server'] == 'default':
if have['name_servers']:
for item in have['name_servers']:
cmd = 'no ip name-server %s' % item['server']
remove(cmd, commands, item['vrf'])
else:
for item in difference(have, want, 'name_servers'): for item in difference(have, want, 'name_servers'):
cmd = 'no ip name-server %s' % item['server'] cmd = 'no ip name-server %s' % item['server']
remove(cmd, commands, item['vrf']) remove(cmd, commands, item['vrf'])
@ -207,6 +231,10 @@ def map_obj_to_commands(want, have, module):
add(cmd, commands, item['vrf']) add(cmd, commands, item['vrf'])
if needs_update('system_mtu'): if needs_update('system_mtu'):
if want['system_mtu'] == 'default':
if have['system_mtu']:
commands.append('no system jumbomtu')
else:
commands.append('system jumbomtu %s' % want['system_mtu']) commands.append('system jumbomtu %s' % want['system_mtu'])
return commands return commands
@ -269,7 +297,7 @@ def parse_name_servers(config, vrf_config, vrfs):
def parse_system_mtu(config): def parse_system_mtu(config):
match = re.search(r'^system jumbomtu (\d+)', config, re.M) match = re.search(r'^system jumbomtu (\d+)', config, re.M)
if match: if match:
return int(match.group(1)) return match.group(1)
def map_config_to_obj(module): def map_config_to_obj(module):
@ -293,11 +321,6 @@ def map_config_to_obj(module):
} }
def validate_system_mtu(value, module):
if not 1500 <= value <= 9216:
module.fail_json(msg='system_mtu must be between 1500 and 9216')
def map_params_to_obj(module): def map_params_to_obj(module):
obj = { obj = {
'hostname': module.params['hostname'], 'hostname': module.params['hostname'],
@ -346,7 +369,7 @@ def main():
# { server: <str>; vrf: <str> } # { server: <str>; vrf: <str> }
name_servers=dict(type='list'), name_servers=dict(type='list'),
system_mtu=dict(type='int'), system_mtu=dict(type='str'),
state=dict(default='present', choices=['present', 'absent']) state=dict(default='present', choices=['present', 'absent'])
) )

View file

@ -2,7 +2,7 @@
- debug: msg="START cli/set_name_servers.yaml" - debug: msg="START cli/set_name_servers.yaml"
- name: setup - name: setup
nxos_config: nxos_config: &reset
lines: lines:
- no ip name-server 1.1.1.1 - no ip name-server 1.1.1.1
- no ip name-server 2.2.2.2 - no ip name-server 2.2.2.2
@ -76,12 +76,25 @@
- result.commands|length == 1 - result.commands|length == 1
- "'no ip name-server 3.3.3.3' in result.commands" - "'no ip name-server 3.3.3.3' in result.commands"
- name: default name server
nxos_system: &defns
name_servers: default
register: result
- assert:
that:
- result.changed == true
- name: Idempotent check
nxos_system: *defns
register: result
- assert:
that:
- result.changed == false
- name: teardown - name: teardown
nxos_config: nxos_config: *reset
lines:
- no ip lookup source-interface
match: none
ignore_errors: yes ignore_errors: yes
# FIXME Copied from iosxr, not sure what we need here
- debug: msg="END cli/set_name_servers.yaml" - debug: msg="END cli/set_name_servers.yaml"

View file

@ -4,28 +4,124 @@
when: ansible_connection == "local" when: ansible_connection == "local"
- block: - block:
- name: remove configuration
nxos_system: &remove
state: absent
register: result
ignore_errors: yes
- name: configure domain lookup
nxos_system: &dlo
domain_lookup: true
state: present
register: result
- name: configure hostname and domain-name - name: configure hostname and domain-name
nxos_system: &hostname nxos_system: &hostname
hostname: switch hostname: switch
domain_name: test.example.com domain_name: test.example.com
register: result
- name: remove configuration - assert: &true
nxos_system: that:
state: absent - "result.changed == true"
- name: Idempotence check
nxos_system: *hostname
register: result
- assert: &false
that:
- "result.changed == false"
- name: configure name servers - name: configure name servers
nxos_system: nxos_system: &ns
name_servers: name_servers:
- 8.8.8.8 - 8.8.8.8
- 8.8.4.4 - 8.8.4.4
register: result
- assert: *true
- name: Idempotence check
nxos_system: *ns
register: result
- assert: *false
- name: configure name servers with VRF support - name: configure name servers with VRF support
nxos_system: nxos_system: &nsv
name_servers: name_servers:
- { server: 8.8.8.8, vrf: management } - { server: 8.8.8.8, vrf: management }
- { server: 8.8.4.4, vrf: management } - { server: 8.8.4.4, vrf: management }
register: result
- assert: *true
- name: Idempotence check
nxos_system: *nsv
register: result
- assert: *false
- name: configure domain lookup1
nxos_system: &ndlo
domain_lookup: false
register: result
- assert: *true
- name: Idempotence check
nxos_system: *ndlo
register: result
- assert: *false
- name: configure domain lookup2
nxos_system: *dlo
register: result
- assert: *true
- name: Idempotence check
nxos_system: *dlo
register: result
- assert: *false
- name: configure system mtu
nxos_system: &sysmtu
system_mtu: 3000
register: result
- assert: *true
- name: Idempotence check
nxos_system: *sysmtu
register: result
- assert: *false
- name: default configuration
nxos_system: &default
hostname: default
domain_name: default
name_servers: default
system_mtu: default
register: result
- assert: *true
- name: Idempotence check
nxos_system: *default
register: result
- assert: *false
always: always:
- name: remove configuration
nxos_system: *remove
- name: Re-configure hostname - name: Re-configure hostname
nxos_system: *hostname nxos_system: *hostname

View file

@ -6,7 +6,7 @@
- block: - block:
- name: setup - name: setup
nxos_config: nxos_config:
lines: hostname switch lines: "hostname {{ inventory_hostname }}"
match: none match: none
- name: configure hostname - name: configure hostname
@ -30,7 +30,7 @@
always: always:
- name: teardown - name: teardown
nxos_config: nxos_config:
lines: hostname switch lines: "hostname {{ inventory_hostname }}"
match: none match: none

View file

@ -5,7 +5,7 @@
# nxapi will error if you try and remove a non-existent entry, # nxapi will error if you try and remove a non-existent entry,
# Therefore we do this as a with_items loop with ignore_errors # Therefore we do this as a with_items loop with ignore_errors
- name: setup - name: setup
nxos_config: nxos_config: &reset
lines: lines:
- no ip name-server {{ item }} - no ip name-server {{ item }}
match: none match: none
@ -82,12 +82,29 @@
- result.commands|length == 1 - result.commands|length == 1
- "'no ip name-server 3.3.3.3' in result.commands" - "'no ip name-server 3.3.3.3' in result.commands"
- name: default name server
nxos_system: &defns
name_servers: default
register: result
- assert:
that:
- result.changed == true
- name: Idempotent check
nxos_system: *defns
register: result
- assert:
that:
- result.changed == false
- name: teardown - name: teardown
nxos_config: nxos_config: *reset
lines: with_items:
- no ip lookup source-interface - 1.1.1.1
match: none - 2.2.2.2
- 3.3.3.3
ignore_errors: yes ignore_errors: yes
# FIXME Copied from iosxr, not sure what we need here
- debug: msg="END nxapi/set_name_servers.yaml" - debug: msg="END nxapi/set_name_servers.yaml"