mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-26 22:51:23 -07:00
Streamline nxos_smu (#28030)
This commit is contained in:
parent
b9c3329950
commit
820d7e805a
1 changed files with 25 additions and 60 deletions
|
@ -51,60 +51,40 @@ options:
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
- nxos_smu:
|
- nxos_smu:
|
||||||
pkg: "nxos.CSCuz65185-n9k_EOR-1.0.0-7.0.3.I2.2d.lib32_n9000.rpm"
|
pkg: "nxos.CSCuz65185-n9k_EOR-1.0.0-7.0.3.I2.2d.lib32_n9000.rpm"
|
||||||
username: "{{ un }}"
|
|
||||||
password: "{{ pwd }}"
|
|
||||||
host: "{{ inventory_hostname }}"
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
file_system:
|
commands:
|
||||||
description: The remote file system of the device.
|
|
||||||
returned: always
|
|
||||||
type: string
|
|
||||||
sample: "bootflash:"
|
|
||||||
pkg:
|
|
||||||
description: Name of the remote package
|
|
||||||
type: string
|
|
||||||
returned: always
|
|
||||||
sample: "nxos.CSCuz65185-n9k_EOR-1.0.0-7.0.3.I2.2d.lib32_n9000.rpm"
|
|
||||||
updates:
|
|
||||||
description: commands sent to the device
|
description: commands sent to the device
|
||||||
returned: always
|
returned: always
|
||||||
type: list
|
type: list
|
||||||
sample: ["install add bootflash:nxos.CSCuz65185-n9k_EOR-1.0.0-7.0.3.I2.2d.lib32_n9000.rpm",
|
sample: ["install add bootflash:nxos.CSCuz65185-n9k_EOR-1.0.0-7.0.3.I2.2d.lib32_n9000.rpm",
|
||||||
"install activate bootflash:nxos.CSCuz65185-n9k_EOR-1.0.0-7.0.3.I2.2d.lib32_n9000.rpm force",
|
"install activate bootflash:nxos.CSCuz65185-n9k_EOR-1.0.0-7.0.3.I2.2d.lib32_n9000.rpm force",
|
||||||
"install commit bootflash:nxos.CSCuz65185-n9k_EOR-1.0.0-7.0.3.I2.2d.lib32_n9000.rpm"]
|
"install commit bootflash:nxos.CSCuz65185-n9k_EOR-1.0.0-7.0.3.I2.2d.lib32_n9000.rpm"]
|
||||||
changed:
|
|
||||||
description: check to see if a change was made on the device
|
|
||||||
returned: always
|
|
||||||
type: boolean
|
|
||||||
sample: true
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
import collections
|
||||||
|
import re
|
||||||
|
import time
|
||||||
|
|
||||||
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
from ansible.module_utils.nxos import get_config, load_config, run_commands
|
||||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
import time
|
|
||||||
import collections
|
|
||||||
|
|
||||||
import re
|
def execute_show_command(command, module):
|
||||||
|
|
||||||
def execute_show_command(command, module, command_type='cli_show'):
|
|
||||||
if command_type == 'cli_show_ascii':
|
|
||||||
cmds = [{
|
cmds = [{
|
||||||
'command': command,
|
'command': command,
|
||||||
'output': 'text',
|
'output': 'text',
|
||||||
}]
|
}]
|
||||||
else:
|
|
||||||
cmds = [command]
|
|
||||||
|
|
||||||
return run_commands(module, cmds)
|
return run_commands(module, cmds)
|
||||||
|
|
||||||
|
|
||||||
def remote_file_exists(module, dst, file_system='bootflash:'):
|
def remote_file_exists(module, dst, file_system='bootflash:'):
|
||||||
command = 'dir {0}/{1}'.format(file_system, dst)
|
command = 'dir {0}/{1}'.format(file_system, dst)
|
||||||
body = execute_show_command(command, module, command_type='cli_show_ascii')
|
body = execute_show_command(command, module)
|
||||||
if 'No such file' in body[0]:
|
if 'No such file' in body[0]:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
@ -122,18 +102,10 @@ def get_commands(module, pkg, file_system):
|
||||||
fixed_pkg = '.'.join(splitted_pkg[0:-1])
|
fixed_pkg = '.'.join(splitted_pkg[0:-1])
|
||||||
|
|
||||||
command = 'show install inactive'
|
command = 'show install inactive'
|
||||||
inactive_body = execute_show_command(
|
inactive_body = execute_show_command(command, module)
|
||||||
command,
|
|
||||||
module,
|
|
||||||
command_type='cli_show_ascii'
|
|
||||||
)
|
|
||||||
|
|
||||||
command = 'show install active'
|
command = 'show install active'
|
||||||
active_body = execute_show_command(
|
active_body = execute_show_command(command, module)
|
||||||
command,
|
|
||||||
module,
|
|
||||||
command_type='cli_show_ascii'
|
|
||||||
)
|
|
||||||
|
|
||||||
if fixed_pkg not in inactive_body[0] and fixed_pkg not in active_body[0]:
|
if fixed_pkg not in inactive_body[0] and fixed_pkg not in active_body[0]:
|
||||||
commands.append('install add {0}{1}'.format(file_system, pkg))
|
commands.append('install add {0}{1}'.format(file_system, pkg))
|
||||||
|
@ -154,9 +126,6 @@ def main():
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
pkg=dict(required=True),
|
pkg=dict(required=True),
|
||||||
file_system=dict(required=False, default='bootflash:'),
|
file_system=dict(required=False, default='bootflash:'),
|
||||||
include_defaults=dict(default=False),
|
|
||||||
config=dict(),
|
|
||||||
save=dict(type='bool', default=False)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
argument_spec.update(nxos_argument_spec)
|
argument_spec.update(nxos_argument_spec)
|
||||||
|
@ -166,11 +135,11 @@ def main():
|
||||||
|
|
||||||
warnings = list()
|
warnings = list()
|
||||||
check_args(module, warnings)
|
check_args(module, warnings)
|
||||||
|
results = {'changed': False, 'commands': [], 'warnings': warnings}
|
||||||
|
|
||||||
|
|
||||||
pkg = module.params['pkg']
|
pkg = module.params['pkg']
|
||||||
file_system = module.params['file_system']
|
file_system = module.params['file_system']
|
||||||
changed = False
|
|
||||||
remote_exists = remote_file_exists(module, pkg, file_system=file_system)
|
remote_exists = remote_file_exists(module, pkg, file_system=file_system)
|
||||||
|
|
||||||
if not remote_exists:
|
if not remote_exists:
|
||||||
|
@ -179,19 +148,15 @@ def main():
|
||||||
)
|
)
|
||||||
|
|
||||||
commands = get_commands(module, pkg, file_system)
|
commands = get_commands(module, pkg, file_system)
|
||||||
if not module.check_mode and commands:
|
if commands:
|
||||||
|
results['changed'] = True
|
||||||
|
if not module.check_mode:
|
||||||
apply_patch(module, commands)
|
apply_patch(module, commands)
|
||||||
changed = True
|
|
||||||
|
|
||||||
if 'configure' in commands:
|
if 'configure' in commands:
|
||||||
commands.pop(0)
|
commands.pop(0)
|
||||||
|
results['commands'] = commands
|
||||||
|
|
||||||
module.exit_json(
|
module.exit_json(**results)
|
||||||
changed=changed,
|
|
||||||
pkg=pkg,
|
|
||||||
file_system=file_system,
|
|
||||||
updates=commands
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue