|
35 | 35 | file_location: |
36 | 36 | description: |
37 | 37 | - The download path and file name for a backup. |
38 | | - - When O(file_location) is specified, the backup will be created and automatically downloaded to the local machine at the designated path. |
39 | | - - Automatic download is not supported for the ND versions 3.2.1 and later. Use a following task with O(state=download) to download the backup. |
| 38 | + - When O(file_location) is specified, the backup will be created and automatically downloaded to the designated path. |
40 | 39 | aliases: [ local_path, path ] |
41 | 40 | type: str |
42 | 41 | backup_key: |
|
58 | 57 | remote_location: |
59 | 58 | description: |
60 | 59 | - The name of the remote storage location. |
61 | | - - Use O(remote_location="") to create local backup. |
| 60 | + - Use O(remote_location="") to create ND local backup. |
62 | 61 | - This parameter is only supported on ND v3.2.1 and later. |
63 | 62 | default: "" |
64 | 63 | type: str |
65 | 64 | state: |
66 | 65 | description: |
67 | | - - Use O(state=backup) for creating and downloading a backup of the cluster config for the ND versions less than 3.2.1. |
68 | | - - Use O(state=backup) to create a cluster configuration backup. Automatic download is not supported for the ND versions 3.2.1 and later. |
69 | | - - After creation, use O(state=download) to download the backup file. |
70 | | - - Use O(state=download) downloading a backup to the local machine, the O(state=download) is only supported on ND v3.2.1 and later. |
71 | 66 | - Use O(state=query) for listing all the backed up files. |
72 | 67 | - Use O(state=absent) for deleting a backup job. |
| 68 | + - For ND versions earlier than v3.2.1, use O(state=backup) for creating and automatically downloading a backup of the cluster config. |
| 69 | + - For ND versions later than v3.2.1, use O(state=backup) for creating a cluster configuration backup, |
| 70 | + use O(state=download) for downloading a backup to the designated path. |
| 71 | + - O(state=download) is only supported on ND v3.2.1 and later. |
73 | 72 | type: str |
74 | 73 | choices: [ backup, download, query, absent ] |
75 | 74 | default: backup |
|
79 | 78 | """ |
80 | 79 |
|
81 | 80 | EXAMPLES = r""" |
82 | | -- name: Create a backup for ND versions < 3.2.1 |
| 81 | +- name: Create a backup and automatically download it to file_location for ND versions < 3.2.1 |
83 | 82 | cisco.nd.nd_backup: |
84 | 83 | name: nexus |
85 | 84 | encryption_key: testtest |
|
93 | 92 | remote_location: remote_machine |
94 | 93 | state: backup |
95 | 94 |
|
96 | | -- name: Create a local backup for ND versions >= 3.2.1 |
| 95 | +- name: Create a ND local backup for ND versions >= 3.2.1 |
97 | 96 | cisco.nd.nd_backup: |
98 | 97 | name: nexus |
99 | 98 | encryption_key: testtest1 |
100 | 99 | state: backup |
101 | 100 |
|
102 | | -- name: Create a backup and download it to the local machine for ND versions >= 3.2.1 |
| 101 | +- name: Create a backup and download it to the designated path for ND versions >= 3.2.1 |
103 | 102 | cisco.nd.nd_backup: |
104 | 103 | name: nexus |
105 | 104 | file_location: ./nexus.tgz |
106 | 105 | encryption_key: testtest1 |
107 | 106 | state: backup |
108 | 107 |
|
109 | | -- name: Download a local/remote backup for ND versions >= 3.2.1 |
| 108 | +- name: Download an existing backup for ND versions >= 3.2.1 |
110 | 109 | cisco.nd.nd_backup: |
111 | 110 | name: nexus |
112 | 111 | state: download |
@@ -174,8 +173,8 @@ def main(): |
174 | 173 | backups = nd.query_obj("/api/config/class/exports") if nd.version < "3.2.1" else nd.query_obj(path) |
175 | 174 |
|
176 | 175 | if nd.version < "3.2.1": |
177 | | - if not file_location and state in ["backup", "download"]: |
178 | | - nd.fail_json("Parameter 'file_location' is required when state is 'backup|download' for ND versions < 3.2.1.") |
| 176 | + if not file_location and state in ["backup"]: |
| 177 | + nd.fail_json("Parameter 'file_location' is required when state is 'backup' for ND versions < 3.2.1.") |
179 | 178 |
|
180 | 179 | if encryption_key is not None and len(encryption_key) < 8: |
181 | 180 | nd.fail_json("Please provide a minimum of 8 characters for the encryption key.") |
@@ -255,6 +254,8 @@ def main(): |
255 | 254 | if not module.check_mode: |
256 | 255 | response = nd.request("{0}/{1}?action=download".format(path, name), method="GET", data=None, output_format="raw") |
257 | 256 | write_file(module, file_location, to_bytes(response)) |
| 257 | + elif state == "download" and nd.version < "3.2.1": |
| 258 | + nd.fail_json("The O(state=download) is only supported on ND v3.2.1 and later.") |
258 | 259 |
|
259 | 260 | nd.exit_json() |
260 | 261 |
|
|
0 commit comments