diff --git a/docs/ansible.netcommon.net_put_module.rst b/docs/ansible.netcommon.net_put_module.rst
index 470e94056..619d23e1a 100644
--- a/docs/ansible.netcommon.net_put_module.rst
+++ b/docs/ansible.netcommon.net_put_module.rst
@@ -39,6 +39,25 @@ Parameters
Choices/Defaults |
Comments |
+
+ |
+
+ check_destination
+
+
+ boolean
+
+ |
+
+
+ |
+
+ 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.
+ |
+
|
@@ -91,6 +110,7 @@ Parameters
|
Protocol used to transfer file.
+ The choice scp is deprecated, use sftp instead. The scp option would be removed after 2028-01-01.
|
@@ -129,16 +149,32 @@ Examples
.. code-block:: yaml
- - 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
+
diff --git a/plugins/action/net_put.py b/plugins/action/net_put.py
index 4ff3f2737..4dc1565db 100644
--- a/plugins/action/net_put.py
+++ b/plugins/action/net_put.py
@@ -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)
@@ -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(
@@ -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":
diff --git a/plugins/modules/net_put.py b/plugins/modules/net_put.py
index a095eb60f..feda951fc 100644
--- a/plugins/modules/net_put.py
+++ b/plugins/modules/net_put.py
@@ -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
@@ -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 = """