Skip to content

Commit

Permalink
Mark scp deprecated and add check_destination
Browse files Browse the repository at this point in the history
  • Loading branch information
KB-perByte committed Oct 18, 2024
1 parent 35be779 commit a50215f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
30 changes: 19 additions & 11 deletions plugins/action/net_put.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ def run(self, tmp=None, task_vars=None):
if mode is None:
mode = "binary"

# Check if the file is present in destination or not
check_destination = self._task.args.get("check_destination")
if check_destination is None:
check_destination = True

if mode == "text":
try:
self._handle_src_option(convert_data=False)
Expand Down Expand Up @@ -95,17 +100,19 @@ def run(self, tmp=None, task_vars=None):

if dest is None:
dest = src_file_path_name
try:
changed = self._handle_existing_file(conn, output_file, dest, proto, sock_timeout)
if changed is False:
result["changed"] = changed
result["destination"] = dest
if mode == "text":
# Cleanup tmp file expanded wih ansible vars
os.remove(output_file)
return result
except Exception as exc:
result["msg"] = "Warning: %s idempotency check failed. Check dest" % exc

if check_destination:
try:
changed = self._handle_existing_file(conn, output_file, dest, proto, sock_timeout)
if changed is False:
result["changed"] = changed
result["destination"] = dest
if mode == "text":
# Cleanup tmp file expanded wih ansible vars
os.remove(output_file)
return result
except Exception as exc:
result["msg"] = "Warning: %s idempotency check failed. Check dest" % exc

try:
conn.copy_file(
Expand All @@ -114,6 +121,7 @@ def run(self, tmp=None, task_vars=None):
proto=proto,
timeout=sock_timeout,
)
changed = True
except Exception as exc:
if to_text(exc) == "No response from server":
if network_os == "iosxr":
Expand Down
29 changes: 27 additions & 2 deletions plugins/modules/net_put.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,19 @@
protocol:
description:
- Protocol used to transfer file.
- The choice scp is deprecated, use sftp instead. The scp option would be removed
after 2028-01-01.
default: scp
choices:
- scp
- sftp
check_destination:
description:
- Enabling this check for the file in the destination if the file exists or not and
only copy the file if it does not exist.
type: bool
default: true
required: false
dest:
description:
- Specifies the destination file. The path to destination file can either be the
Expand Down Expand Up @@ -64,15 +73,31 @@
"""

EXAMPLES = """
- name: copy file from ansible controller to a network device
- name: Copy file from ansible controller to a network device (defaults to scp)
ansible.netcommon.net_put:
src: running_cfg_ios1.txt
- name: copy file at root dir of flash in slot 3 of sw1(ios)
# changed: [Appliance] => changed=true
# destination: running_cfg_sw1.txt
- name: Copy file at root dir of flash in slot 3 of sw1(ios)
ansible.netcommon.net_put:
src: running_cfg_sw1.txt
protocol: sftp
dest: flash3:/running_cfg_sw1.txt
# changed: [Appliance] => changed=true
# destination: running_cfg_sw1.txt
- name: Copy file from ansible controller to a network device (does not check destination)
ansible.netcommon.net_put:
src: running_cfg_sw1.txt
protocol: scp
dest: ios_running_cfg_sw1.txt
check_destination: false
# changed: [Appliance] => changed=true
# destination: ios_running_cfg_sw1.txt
"""

RETURN = """
Expand Down

0 comments on commit a50215f

Please sign in to comment.