Debian Codegraph @

ansible_collections/cisco/nxos/docs/cisco.nxos.nxos_file_copy_module.rst

raw
1 .. _cisco.nxos.nxos_file_copy_module:
2
3
4 *************************
5 cisco.nxos.nxos_file_copy
6 *************************
7
8 **Copy a file to a remote NXOS device.**
9
10
11 Version added: 1.0.0
12
13 .. contents::
14 :local:
15 :depth: 1
16
17
18 Synopsis
19 --------
20 - This module supports two different workflows for copying a file to flash (or bootflash) on NXOS devices. Files can either be (1) pushed from the Ansible controller to the device or (2) pulled from a remote SCP file server to the device. File copies are initiated from the NXOS device to the remote SCP server. This module only supports the use of connection ``network_cli`` or ``Cli`` transport with connection ``local``.
21
22
23
24 Requirements
25 ------------
26 The below requirements are needed on the host that executes this module.
27
28 - paramiko or libssh (required when file_pull is False)
29 - scp (required when file_pull is False)
30
31
32 Parameters
33 ----------
34
35 .. raw:: html
36
37 <table border=0 cellpadding=0 class="documentation-table">
38 <tr>
39 <th colspan="1">Parameter</th>
40 <th>Choices/<font color="blue">Defaults</font></th>
41 <th width="100%">Comments</th>
42 </tr>
43 <tr>
44 <td colspan="1">
45 <div class="ansibleOptionAnchor" id="parameter-"></div>
46 <b>connect_ssh_port</b>
47 <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
48 <div style="font-size: small">
49 <span style="color: purple">integer</span>
50 </div>
51 </td>
52 <td>
53 <b>Default:</b><br/><div style="color: blue">22</div>
54 </td>
55 <td>
56 <div><b>Deprecated</b></div>
57 <div>This option has been deprecated and will be removed in a release after 2024-06-01.</div>
58 <div>To maintain backwards compatibility, this option will continue to override the value of <em>ansible_port</em> until removed.</div>
59 <div><hr/></div>
60 <div>SSH server port used for file transfer.</div>
61 <div>Only used when <em>file_pull</em> is <code>True</code>.</div>
62 </td>
63 </tr>
64 <tr>
65 <td colspan="1">
66 <div class="ansibleOptionAnchor" id="parameter-"></div>
67 <b>file_pull</b>
68 <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
69 <div style="font-size: small">
70 <span style="color: purple">boolean</span>
71 </div>
72 </td>
73 <td>
74 <ul style="margin: 0; padding: 0"><b>Choices:</b>
75 <li><div style="color: blue"><b>no</b>&nbsp;&larr;</div></li>
76 <li>yes</li>
77 </ul>
78 </td>
79 <td>
80 <div>When (False) file is copied from the Ansible controller to the NXOS device.</div>
81 <div>When (True) file is copied from a remote SCP server to the NXOS device. In this mode, the file copy is initiated from the NXOS device.</div>
82 <div>If the file is already present on the device it will be overwritten and therefore the operation is NOT idempotent.</div>
83 </td>
84 </tr>
85 <tr>
86 <td colspan="1">
87 <div class="ansibleOptionAnchor" id="parameter-"></div>
88 <b>file_pull_compact</b>
89 <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
90 <div style="font-size: small">
91 <span style="color: purple">boolean</span>
92 </div>
93 </td>
94 <td>
95 <ul style="margin: 0; padding: 0"><b>Choices:</b>
96 <li><div style="color: blue"><b>no</b>&nbsp;&larr;</div></li>
97 <li>yes</li>
98 </ul>
99 </td>
100 <td>
101 <div>When file_pull is True, this is used to compact nxos image files. This option can only be used with nxos image files.</div>
102 <div>When (file_pull is False), this is not used.</div>
103 </td>
104 </tr>
105 <tr>
106 <td colspan="1">
107 <div class="ansibleOptionAnchor" id="parameter-"></div>
108 <b>file_pull_kstack</b>
109 <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
110 <div style="font-size: small">
111 <span style="color: purple">boolean</span>
112 </div>
113 </td>
114 <td>
115 <ul style="margin: 0; padding: 0"><b>Choices:</b>
116 <li><div style="color: blue"><b>no</b>&nbsp;&larr;</div></li>
117 <li>yes</li>
118 </ul>
119 </td>
120 <td>
121 <div>When file_pull is True, this can be used to speed up file copies when the nxos running image supports the use-kstack option.</div>
122 <div>When (file_pull is False), this is not used.</div>
123 </td>
124 </tr>
125 <tr>
126 <td colspan="1">
127 <div class="ansibleOptionAnchor" id="parameter-"></div>
128 <b>file_pull_protocol</b>
129 <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
130 <div style="font-size: small">
131 <span style="color: purple">string</span>
132 </div>
133 </td>
134 <td>
135 <ul style="margin: 0; padding: 0"><b>Choices:</b>
136 <li><div style="color: blue"><b>scp</b>&nbsp;&larr;</div></li>
137 <li>sftp</li>
138 <li>ftp</li>
139 <li>http</li>
140 <li>https</li>
141 <li>tftp</li>
142 </ul>
143 </td>
144 <td>
145 <div>When file_pull is True, this can be used to define the transfer protocol for copying file from remote to the NXOS device.</div>
146 <div>When (file_pull is False), this is not used.</div>
147 </td>
148 </tr>
149 <tr>
150 <td colspan="1">
151 <div class="ansibleOptionAnchor" id="parameter-"></div>
152 <b>file_pull_timeout</b>
153 <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
154 <div style="font-size: small">
155 <span style="color: purple">integer</span>
156 </div>
157 </td>
158 <td>
159 <b>Default:</b><br/><div style="color: blue">300</div>
160 </td>
161 <td>
162 <div><b>Deprecated</b></div>
163 <div>This option has been deprecated and will be removed in a release after 2024-06-01.</div>
164 <div>To maintain backwards compatibility, this option will continue to override the value of <em>ansible_command_timeout</em> until removed.</div>
165 <div><hr/></div>
166 <div>Use this parameter to set timeout in seconds, when transferring large files or when the network is slow.</div>
167 <div>When (file_pull is False), this is not used.</div>
168 </td>
169 </tr>
170 <tr>
171 <td colspan="1">
172 <div class="ansibleOptionAnchor" id="parameter-"></div>
173 <b>file_system</b>
174 <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
175 <div style="font-size: small">
176 <span style="color: purple">string</span>
177 </div>
178 </td>
179 <td>
180 <b>Default:</b><br/><div style="color: blue">"bootflash:"</div>
181 </td>
182 <td>
183 <div>The remote file system on the nxos device. If omitted, devices that support a <em>file_system</em> parameter will use their default values.</div>
184 </td>
185 </tr>
186 <tr>
187 <td colspan="1">
188 <div class="ansibleOptionAnchor" id="parameter-"></div>
189 <b>local_file</b>
190 <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
191 <div style="font-size: small">
192 <span style="color: purple">path</span>
193 </div>
194 </td>
195 <td>
196 </td>
197 <td>
198 <div>When (file_pull is False) this is the path to the local file on the Ansible controller. The local directory must exist.</div>
199 <div>When (file_pull is True) this is the target file name on the NXOS device.</div>
200 </td>
201 </tr>
202 <tr>
203 <td colspan="1">
204 <div class="ansibleOptionAnchor" id="parameter-"></div>
205 <b>local_file_directory</b>
206 <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
207 <div style="font-size: small">
208 <span style="color: purple">path</span>
209 </div>
210 </td>
211 <td>
212 </td>
213 <td>
214 <div>When (file_pull is True) file is copied from a remote SCP server to the NXOS device, and written to this directory on the NXOS device. If the directory does not exist, it will be created under the file_system. This is an optional parameter.</div>
215 <div>When (file_pull is False), this is not used.</div>
216 </td>
217 </tr>
218 <tr>
219 <td colspan="1">
220 <div class="ansibleOptionAnchor" id="parameter-"></div>
221 <b>remote_file</b>
222 <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
223 <div style="font-size: small">
224 <span style="color: purple">path</span>
225 </div>
226 </td>
227 <td>
228 </td>
229 <td>
230 <div>When (file_pull is False) this is the remote file path on the NXOS device. If omitted, the name of the local file will be used. The remote directory must exist.</div>
231 <div>When (file_pull is True) this is the full path to the file on the remote SCP server to be copied to the NXOS device.</div>
232 </td>
233 </tr>
234 <tr>
235 <td colspan="1">
236 <div class="ansibleOptionAnchor" id="parameter-"></div>
237 <b>remote_scp_server</b>
238 <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
239 <div style="font-size: small">
240 <span style="color: purple">string</span>
241 </div>
242 </td>
243 <td>
244 </td>
245 <td>
246 <div>The remote scp server address when file_pull is True. This is required if file_pull is True.</div>
247 <div>When (file_pull is False), this is not used.</div>
248 </td>
249 </tr>
250 <tr>
251 <td colspan="1">
252 <div class="ansibleOptionAnchor" id="parameter-"></div>
253 <b>remote_scp_server_password</b>
254 <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
255 <div style="font-size: small">
256 <span style="color: purple">string</span>
257 </div>
258 </td>
259 <td>
260 </td>
261 <td>
262 <div>The remote scp server password when file_pull is True. This is required if file_pull is True.</div>
263 <div>When (file_pull is False), this is not used.</div>
264 </td>
265 </tr>
266 <tr>
267 <td colspan="1">
268 <div class="ansibleOptionAnchor" id="parameter-"></div>
269 <b>remote_scp_server_user</b>
270 <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
271 <div style="font-size: small">
272 <span style="color: purple">string</span>
273 </div>
274 </td>
275 <td>
276 </td>
277 <td>
278 <div>The remote scp server username when file_pull is True. This is required if file_pull is True.</div>
279 <div>When (file_pull is False), this is not used.</div>
280 </td>
281 </tr>
282 <tr>
283 <td colspan="1">
284 <div class="ansibleOptionAnchor" id="parameter-"></div>
285 <b>vrf</b>
286 <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
287 <div style="font-size: small">
288 <span style="color: purple">string</span>
289 </div>
290 </td>
291 <td>
292 <b>Default:</b><br/><div style="color: blue">"management"</div>
293 </td>
294 <td>
295 <div>The VRF used to pull the file. Useful when no vrf management is defined.</div>
296 <div>This option is not applicable for MDS switches.</div>
297 </td>
298 </tr>
299 </table>
300 <br/>
301
302
303 Notes
304 -----
305
306 .. note::
307 - Tested against NXOS 7.0(3)I2(5), 7.0(3)I4(6), 7.0(3)I5(3), 7.0(3)I6(1), 7.0(3)I7(3), 6.0(2)A8(8), 7.0(3)F3(4), 7.3(0)D1(1), 8.3(0), 9.2, 9.3
308 - Limited Support for Cisco MDS
309 - When pushing files (file_pull is False) to the NXOS device, feature scp-server must be enabled.
310 - When pulling files (file_pull is True) to the NXOS device, feature scp-server is not required.
311 - When pulling files (file_pull is True) to the NXOS device, no transfer will take place if the file is already present.
312 - Check mode will tell you if the file would be copied.
313 - For information on using CLI and NX-API see the :ref:`NXOS Platform Options guide <nxos_platform_options>`
314 - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide <network_guide>`
315 - For more information on using Ansible to manage Cisco devices see the `Cisco integration page <https://www.ansible.com/integrations/networks/cisco>`_.
316
317
318
319 Examples
320 --------
321
322 .. code-block:: yaml
323
324 # File copy from ansible controller to nxos device
325 - name: copy from server to device
326 cisco.nxos.nxos_file_copy:
327 local_file: ./test_file.txt
328 remote_file: test_file.txt
329
330 # Initiate file copy from the nxos device to transfer file from an SCP server back to the nxos device
331 - name: initiate file copy from device
332 cisco.nxos.nxos_file_copy:
333 file_pull: true
334 local_file: xyz
335 local_file_directory: dir1/dir2/dir3
336 remote_file: /mydir/abc
337 remote_scp_server: 192.168.0.1
338 remote_scp_server_user: myUser
339 remote_scp_server_password: myPassword
340 vrf: management
341
342 # Initiate file copy from the nxos device to transfer file from a ftp server back to the nxos device.
343 # remote_scp_server_user and remote_scp_server_password are used to login to the FTP server.
344 - name: initiate file copy from device
345 cisco.nxos.nxos_file_copy:
346 file_pull: true
347 file_pull_protocol: ftp
348 local_file: xyz
349 remote_file: /mydir/abc
350 remote_scp_server: 192.168.0.1
351 remote_scp_server_user: myUser
352 remote_scp_server_password: myPassword
353 vrf: management
354
355
356
357 Return Values
358 -------------
359 Common return values are documented `here <https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#common-return-values>`_, the following are the fields unique to this module:
360
361 .. raw:: html
362
363 <table border=0 cellpadding=0 class="documentation-table">
364 <tr>
365 <th colspan="1">Key</th>
366 <th>Returned</th>
367 <th width="100%">Description</th>
368 </tr>
369 <tr>
370 <td colspan="1">
371 <div class="ansibleOptionAnchor" id="return-"></div>
372 <b>changed</b>
373 <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
374 <div style="font-size: small">
375 <span style="color: purple">boolean</span>
376 </div>
377 </td>
378 <td>success</td>
379 <td>
380 <div>Indicates whether or not the file was copied.</div>
381 <br/>
382 <div style="font-size: smaller"><b>Sample:</b></div>
383 <div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">True</div>
384 </td>
385 </tr>
386 <tr>
387 <td colspan="1">
388 <div class="ansibleOptionAnchor" id="return-"></div>
389 <b>local_file</b>
390 <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
391 <div style="font-size: small">
392 <span style="color: purple">string</span>
393 </div>
394 </td>
395 <td>success</td>
396 <td>
397 <div>The path of the local file.</div>
398 <br/>
399 <div style="font-size: smaller"><b>Sample:</b></div>
400 <div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">/path/to/local/file</div>
401 </td>
402 </tr>
403 <tr>
404 <td colspan="1">
405 <div class="ansibleOptionAnchor" id="return-"></div>
406 <b>remote_file</b>
407 <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
408 <div style="font-size: small">
409 <span style="color: purple">string</span>
410 </div>
411 </td>
412 <td>success</td>
413 <td>
414 <div>The path of the remote file.</div>
415 <br/>
416 <div style="font-size: smaller"><b>Sample:</b></div>
417 <div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">/path/to/remote/file</div>
418 </td>
419 </tr>
420 <tr>
421 <td colspan="1">
422 <div class="ansibleOptionAnchor" id="return-"></div>
423 <b>remote_scp_server</b>
424 <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
425 <div style="font-size: small">
426 <span style="color: purple">string</span>
427 </div>
428 </td>
429 <td>success</td>
430 <td>
431 <div>The name of the scp server when file_pull is True.</div>
432 <br/>
433 <div style="font-size: smaller"><b>Sample:</b></div>
434 <div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">fileserver.example.com</div>
435 </td>
436 </tr>
437 <tr>
438 <td colspan="1">
439 <div class="ansibleOptionAnchor" id="return-"></div>
440 <b>transfer_status</b>
441 <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
442 <div style="font-size: small">
443 <span style="color: purple">string</span>
444 </div>
445 </td>
446 <td>success</td>
447 <td>
448 <div>Whether a file was transferred to the nxos device.</div>
449 <br/>
450 <div style="font-size: smaller"><b>Sample:</b></div>
451 <div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">Sent</div>
452 </td>
453 </tr>
454 </table>
455 <br/><br/>
456
457
458 Status
459 ------
460
461
462 Authors
463 ~~~~~~~
464
465 - Jason Edelman (@jedelman8)
466 - Gabriele Gerbino (@GGabriele)
467 - Rewritten as a plugin by (@mikewiebe)