|
|
|
|
@ -38,6 +38,8 @@ notes:
|
|
|
|
|
- If the file is already present (md5 sums match), no transfer will
|
|
|
|
|
take place.
|
|
|
|
|
- Check mode will tell you if the file would be copied.
|
|
|
|
|
requirements:
|
|
|
|
|
- paramiko
|
|
|
|
|
options:
|
|
|
|
|
local_file:
|
|
|
|
|
description:
|
|
|
|
|
@ -52,7 +54,7 @@ options:
|
|
|
|
|
file_system:
|
|
|
|
|
description:
|
|
|
|
|
- The remote file system of the device. If omitted,
|
|
|
|
|
devices that support a file_system parameter will use
|
|
|
|
|
devices that support a I(file_system) parameter will use
|
|
|
|
|
their default values.
|
|
|
|
|
required: false
|
|
|
|
|
default: null
|
|
|
|
|
@ -93,11 +95,17 @@ remote_file:
|
|
|
|
|
import os
|
|
|
|
|
import re
|
|
|
|
|
import time
|
|
|
|
|
import paramiko
|
|
|
|
|
|
|
|
|
|
from ansible.module_utils.network.nxos.nxos import run_commands
|
|
|
|
|
from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, check_args
|
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
import paramiko
|
|
|
|
|
HAS_PARAMIKO = True
|
|
|
|
|
except ImportError:
|
|
|
|
|
HAS_PARAMIKO = False
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
from scp import SCPClient
|
|
|
|
|
HAS_SCP = True
|
|
|
|
|
@ -126,7 +134,7 @@ def local_file_exists(module):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_flash_size(module):
|
|
|
|
|
command = 'dir {}'.format(module.params['file_system'])
|
|
|
|
|
command = 'dir {0}'.format(module.params['file_system'])
|
|
|
|
|
body = run_commands(module, {'command': command, 'output': 'text'})[0]
|
|
|
|
|
|
|
|
|
|
match = re.search(r'(\d+) bytes free', body)
|
|
|
|
|
@ -165,7 +173,7 @@ def transfer_file(module, dest):
|
|
|
|
|
password=password,
|
|
|
|
|
port=port)
|
|
|
|
|
|
|
|
|
|
full_remote_path = '{}{}'.format(module.params['file_system'], dest)
|
|
|
|
|
full_remote_path = '{0}{1}'.format(module.params['file_system'], dest)
|
|
|
|
|
scp = SCPClient(ssh.get_transport())
|
|
|
|
|
try:
|
|
|
|
|
scp.put(module.params['local_file'], full_remote_path)
|
|
|
|
|
@ -197,6 +205,12 @@ def main():
|
|
|
|
|
|
|
|
|
|
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
|
|
|
|
|
|
|
|
|
|
if not HAS_PARAMIKO:
|
|
|
|
|
module.fail_json(
|
|
|
|
|
msg='library paramiko is required but does not appear to be '
|
|
|
|
|
'installed. It can be installed using `pip install paramiko`'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if not HAS_SCP:
|
|
|
|
|
module.fail_json(
|
|
|
|
|
msg='library scp is required but does not appear to be '
|
|
|
|
|
@ -216,7 +230,7 @@ def main():
|
|
|
|
|
results['file_system'] = file_system
|
|
|
|
|
|
|
|
|
|
if not local_file_exists(module):
|
|
|
|
|
module.fail_json(msg="Local file {} not found".format(local_file))
|
|
|
|
|
module.fail_json(msg="Local file {0} not found".format(local_file))
|
|
|
|
|
|
|
|
|
|
dest = remote_file or os.path.basename(local_file)
|
|
|
|
|
remote_exists = remote_file_exists(module, dest, file_system=file_system)
|
|
|
|
|
|