|
|
|
@ -16,10 +16,11 @@
|
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
|
|
|
|
ANSIBLE_METADATA = {
|
|
|
|
|
'metadata_version': '1.0',
|
|
|
|
|
'status': ['preview'],
|
|
|
|
|
'supported_by': 'community'}
|
|
|
|
|
|
|
|
|
|
'supported_by': 'community'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DOCUMENTATION = '''
|
|
|
|
|
---
|
|
|
|
@ -83,12 +84,11 @@ remote_file:
|
|
|
|
|
type: string
|
|
|
|
|
sample: '/path/to/remote/file'
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import re
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
import paramiko
|
|
|
|
|
|
|
|
|
|
from ansible.module_utils.nxos import run_commands
|
|
|
|
|
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
@ -100,31 +100,20 @@ except ImportError:
|
|
|
|
|
HAS_SCP = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def execute_show_command(command, module, command_type='cli_show'):
|
|
|
|
|
if module.params['transport'] == 'cli':
|
|
|
|
|
cmds = [command]
|
|
|
|
|
body = run_commands(module, cmds)
|
|
|
|
|
elif module.params['transport'] == 'nxapi':
|
|
|
|
|
cmds = [command]
|
|
|
|
|
body = run_commands(module, cmds)
|
|
|
|
|
|
|
|
|
|
return body
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def remote_file_exists(module, dst, file_system='bootflash:'):
|
|
|
|
|
command = 'dir {0}/{1}'.format(file_system, dst)
|
|
|
|
|
body = execute_show_command(command, module, command_type='cli_show_ascii')
|
|
|
|
|
if 'No such file' in body[0]:
|
|
|
|
|
body = run_commands(module, [command])[0]
|
|
|
|
|
if 'No such file' in body:
|
|
|
|
|
return False
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def verify_remote_file_exists(module, dst, file_system='bootflash:'):
|
|
|
|
|
command = 'dir {0}/{1}'.format(file_system, dst)
|
|
|
|
|
body = execute_show_command(command, module, command_type='cli_show_ascii')
|
|
|
|
|
if 'No such file' in body[0]:
|
|
|
|
|
body = run_commands(module, [command])[0]
|
|
|
|
|
if 'No such file' in body:
|
|
|
|
|
return 0
|
|
|
|
|
return body[0].split()[0].strip()
|
|
|
|
|
return body.split()[0].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def local_file_exists(module):
|
|
|
|
@ -133,9 +122,9 @@ def local_file_exists(module):
|
|
|
|
|
|
|
|
|
|
def get_flash_size(module):
|
|
|
|
|
command = 'dir {}'.format(module.params['file_system'])
|
|
|
|
|
body = execute_show_command(command, module, command_type='cli_show_ascii')
|
|
|
|
|
body = run_commands(module, [command])[0]
|
|
|
|
|
|
|
|
|
|
match = re.search(r'(\d+) bytes free', body[0])
|
|
|
|
|
match = re.search(r'(\d+) bytes free', body)
|
|
|
|
|
bytes_free = match.group(1)
|
|
|
|
|
|
|
|
|
|
return int(bytes_free)
|
|
|
|
@ -199,8 +188,7 @@ def main():
|
|
|
|
|
|
|
|
|
|
argument_spec.update(nxos_argument_spec)
|
|
|
|
|
|
|
|
|
|
module = AnsibleModule(argument_spec=argument_spec,
|
|
|
|
|
supports_check_mode=True)
|
|
|
|
|
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
|
|
|
|
|
|
|
|
|
|
if not HAS_SCP:
|
|
|
|
|
module.fail_json(
|
|
|
|
@ -210,7 +198,6 @@ def main():
|
|
|
|
|
|
|
|
|
|
warnings = list()
|
|
|
|
|
check_args(module, warnings)
|
|
|
|
|
|
|
|
|
|
results = dict(changed=False, warnings=warnings)
|
|
|
|
|
|
|
|
|
|
local_file = module.params['local_file']
|
|
|
|
|