mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
parent
0752dc12b7
commit
bd9b8b422d
2 changed files with 127 additions and 111 deletions
|
@ -74,9 +74,14 @@ options:
|
|||
system_mode_maintenance_on_reload_reset_reason:
|
||||
description:
|
||||
- Boots the switch into maintenance mode automatically in the
|
||||
event of a specified system crash.
|
||||
event of a specified system crash. Note that not all reset
|
||||
reasons are applicable for all platforms. Also if reset
|
||||
reason is set to match_any, it is not idempotent as it turns
|
||||
on all reset reasons. If reset reason is match_any and state
|
||||
is absent, it turns off all the reset reasons.
|
||||
choices: ['hw_error','svc_failure','kern_failure','wdog_timeout',
|
||||
'fatal_error','lc_failure','match_any','manual_reload']
|
||||
'fatal_error','lc_failure','match_any','manual_reload',
|
||||
'any_other', 'maintenance']
|
||||
state:
|
||||
description:
|
||||
- Specify desired state of the resource.
|
||||
|
@ -159,23 +164,10 @@ from ansible.module_utils.network.nxos.nxos import get_capabilities, nxos_argume
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
def execute_show_command(command, module, command_type='cli_show_ascii'):
|
||||
cmds = [command]
|
||||
device_info = get_capabilities(module)
|
||||
network_api = device_info.get('network_api', 'nxapi')
|
||||
|
||||
if network_api == 'cliconf':
|
||||
body = run_commands(module, cmds)
|
||||
elif network_api == 'nxapi':
|
||||
body = run_commands(module, cmds)
|
||||
|
||||
return body
|
||||
|
||||
|
||||
def get_system_mode(module):
|
||||
command = 'show system mode'
|
||||
body = execute_show_command(command, module)[0]
|
||||
if 'normal' in body.lower():
|
||||
command = {'command': 'show system mode', 'output': 'text'}
|
||||
body = run_commands(module, [command])[0]
|
||||
if body and 'normal' in body.lower():
|
||||
mode = 'normal'
|
||||
else:
|
||||
mode = 'maintenance'
|
||||
|
@ -183,15 +175,15 @@ def get_system_mode(module):
|
|||
|
||||
|
||||
def get_maintenance_timeout(module):
|
||||
command = 'show maintenance timeout'
|
||||
body = execute_show_command(command, module)[0]
|
||||
command = {'command': 'show maintenance timeout', 'output': 'text'}
|
||||
body = run_commands(module, [command])[0]
|
||||
timeout = body.split()[4]
|
||||
return timeout
|
||||
|
||||
|
||||
def get_reset_reasons(module):
|
||||
command = 'show maintenance on-reload reset-reasons'
|
||||
body = execute_show_command(command, module)[0]
|
||||
command = {'command': 'show maintenance on-reload reset-reasons', 'output': 'text'}
|
||||
body = run_commands(module, [command])[0]
|
||||
return body
|
||||
|
||||
|
||||
|
@ -224,8 +216,13 @@ def get_commands(module, state, mode):
|
|||
commands.append('no system mode maintenance timeout {0}'.format(
|
||||
module.params['system_mode_maintenance_timeout']))
|
||||
|
||||
elif module.params['system_mode_maintenance_shutdown'] is True:
|
||||
elif (module.params['system_mode_maintenance_shutdown'] and
|
||||
mode == 'normal'):
|
||||
commands.append('system mode maintenance shutdown')
|
||||
elif (module.params[
|
||||
'system_mode_maintenance_shutdown'] is False and
|
||||
mode == 'maintenance'):
|
||||
commands.append('no system mode maintenance')
|
||||
|
||||
elif module.params['system_mode_maintenance_on_reload_reset_reason']:
|
||||
reset_reasons = get_reset_reasons(module)
|
||||
|
@ -259,7 +256,8 @@ def main():
|
|||
system_mode_maintenance_on_reload_reset_reason=dict(required=False,
|
||||
choices=['hw_error', 'svc_failure', 'kern_failure',
|
||||
'wdog_timeout', 'fatal_error', 'lc_failure',
|
||||
'match_any', 'manual_reload']),
|
||||
'match_any', 'manual_reload', 'any_other',
|
||||
'maintenance']),
|
||||
state=dict(choices=['absent', 'present', 'default'],
|
||||
default='present', required=False)
|
||||
)
|
||||
|
|
|
@ -1,101 +1,119 @@
|
|||
#---
|
||||
#- debug: msg="START connection={{ ansible_connection }} nxos_gir sanity test"
|
||||
---
|
||||
- debug: msg="START connection={{ ansible_connection }} nxos_gir sanity test"
|
||||
- debug: msg="Using provider={{ connection.transport }}"
|
||||
when: ansible_connection == "local"
|
||||
#
|
||||
|
||||
- set_fact: gir_run="true"
|
||||
- set_fact: gir_run="false"
|
||||
when: platform is search("N35")
|
||||
#- name: "Setup"
|
||||
# nxos_gir: &setup
|
||||
# system_mode_maintenance: false
|
||||
# provider: "{{ connection }}"
|
||||
# ignore_errors: yes
|
||||
#
|
||||
#- block:
|
||||
|
||||
- block:
|
||||
- name: "Put system in maintenance mode with reload reset reason"
|
||||
nxos_gir: &reset_reason
|
||||
system_mode_maintenance_on_reload_reset_reason: manual_reload
|
||||
provider: "{{ connection }}"
|
||||
register: result
|
||||
|
||||
- assert: &true
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
- name: "Check Idempotence"
|
||||
nxos_gir: *reset_reason
|
||||
register: result
|
||||
|
||||
- assert: &false
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
- name: "Remove reload reason"
|
||||
nxos_gir: &remove_reason
|
||||
system_mode_maintenance_on_reload_reset_reason: manual_reload
|
||||
state: absent
|
||||
provider: "{{ connection }}"
|
||||
register: result
|
||||
|
||||
- assert: *true
|
||||
|
||||
- name: "Check Idempotence"
|
||||
nxos_gir: *remove_reason
|
||||
register: result
|
||||
|
||||
- assert: *false
|
||||
|
||||
- name: "Put system in maintenance mode with timeout"
|
||||
nxos_gir: &mtime
|
||||
system_mode_maintenance_timeout: 30
|
||||
provider: "{{ connection }}"
|
||||
register: result
|
||||
|
||||
- assert: *true
|
||||
|
||||
- name: "Check Idempotence"
|
||||
nxos_gir: *mtime
|
||||
register: result
|
||||
|
||||
- assert: *false
|
||||
|
||||
- name: "Remove maintenance mode timeout"
|
||||
nxos_gir: &remove_timeout
|
||||
system_mode_maintenance_timeout: 30
|
||||
state: absent
|
||||
provider: "{{ connection }}"
|
||||
register: result
|
||||
|
||||
- assert: *true
|
||||
|
||||
- name: "Check Idempotence"
|
||||
nxos_gir: *remove_timeout
|
||||
register: result
|
||||
|
||||
- assert: *false
|
||||
|
||||
# - name: "Put system in maintenance mode"
|
||||
# nxos_gir: &configure_system_mode_maintenance
|
||||
# system_mode_maintenance: true
|
||||
# provider: "{{ connection }}"
|
||||
# register: result
|
||||
#
|
||||
# - assert: &true
|
||||
# that:
|
||||
# - "result.changed == true"
|
||||
#
|
||||
# - name: "Check Idempotence"
|
||||
# nxos_gir: *configure_system_mode_maintenance
|
||||
# register: result
|
||||
#
|
||||
# - assert: &false
|
||||
# that:
|
||||
# - "result.changed == false"
|
||||
#
|
||||
# - assert: *true
|
||||
|
||||
when: gir_run
|
||||
|
||||
rescue:
|
||||
|
||||
- debug: msg="connection={{ ansible_connection }} nxos_gir failure detected"
|
||||
|
||||
always:
|
||||
|
||||
- name: "Remove snapshots"
|
||||
nxos_snapshot:
|
||||
action: delete_all
|
||||
provider: "{{ connection }}"
|
||||
ignore_errors: yes
|
||||
|
||||
- name: "Remove other config1"
|
||||
nxos_config:
|
||||
lines: no configure maintenance profile normal-mode
|
||||
match: none
|
||||
provider: "{{ connection }}"
|
||||
ignore_errors: yes
|
||||
|
||||
- name: "Remove other config2"
|
||||
nxos_config:
|
||||
lines: no configure maintenance profile maintenance-mode
|
||||
match: none
|
||||
provider: "{{ connection }}"
|
||||
ignore_errors: yes
|
||||
|
||||
# - name: "Put system back in normal mode"
|
||||
# nxos_gir: *setup
|
||||
# register: result
|
||||
#
|
||||
# - assert: *true
|
||||
#
|
||||
# - name: "Check Idempotence"
|
||||
# nxos_gir: *setup
|
||||
# register: result
|
||||
#
|
||||
# - assert: *false
|
||||
#
|
||||
# - name: "Put system in maintenance mode with reload reset reason"
|
||||
# nxos_gir:
|
||||
# system_mode_maintenance: true
|
||||
# system_mode_maintenance_on_reload_reset_reason: manual_reload
|
||||
# register: result
|
||||
#
|
||||
# - assert: *true
|
||||
#
|
||||
# - name: "Remove reload reason"
|
||||
# nxos_gir: &remove_reason
|
||||
# system_mode_maintenance_on_reload_reset_reason: manual_reload
|
||||
# state: absent
|
||||
# register: result
|
||||
#
|
||||
# - assert: *true
|
||||
#
|
||||
# - name: "Check Idempotence"
|
||||
# nxos_gir: *remove_reason
|
||||
# register: result
|
||||
#
|
||||
# - assert: *false
|
||||
#
|
||||
# - name: "Put system in maintenance mode with timeout"
|
||||
# nxos_gir:
|
||||
# system_mode_maintenance: true
|
||||
# system_mode_maintenance_timeout: 30
|
||||
# register: result
|
||||
#
|
||||
# - assert: *true
|
||||
#
|
||||
# - name: "Remove maintenance mode timeout"
|
||||
# nxos_gir: &remove_timeout
|
||||
# system_mode_maintenance_timeout: 30
|
||||
# state: absent
|
||||
# register: result
|
||||
#
|
||||
# - assert: *true
|
||||
#
|
||||
# - name: "Check Idempotence"
|
||||
# nxos_gir: *remove_timeout
|
||||
# register: result
|
||||
#
|
||||
# - assert: *false
|
||||
#
|
||||
# - name: "Put system back in normal mode"
|
||||
# nxos_gir: *setup
|
||||
# register: result
|
||||
#
|
||||
# - assert: *true
|
||||
#
|
||||
# rescue:
|
||||
#
|
||||
# - debug: msg="connection={{ ansible_connection }} nxos_gir failure detected"
|
||||
#
|
||||
# always:
|
||||
#
|
||||
# - name: "Put system back in normal mode"
|
||||
# nxos_gir: *setup
|
||||
# register: result
|
||||
#
|
||||
# - debug: msg="END connection={{ ansible_connection }} nxos_gir sanity test"
|
||||
# ignore_errors: yes
|
||||
|
||||
- debug: msg="END connection={{ ansible_connection }} nxos_gir sanity test"
|
||||
|
|
Loading…
Reference in a new issue