summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrishna Guha <trishnaguha17@gmail.com>2018-03-09 14:08:01 +0530
committerToshio Kuratomi <a.badger@gmail.com>2018-03-29 19:01:55 -0700
commit88bd45b354fd4b28bfcaf83eeed9d1897db9846b (patch)
tree36c6d0bcc2964f0a87b36b0dbaa54368b1879f4f
parent60c540c29b17be7a2f53068592ccc33b0f93cd92 (diff)
downloadansible-88bd45b354fd4b28bfcaf83eeed9d1897db9846b.tar.gz
fix required args for nxos_snapshot and docs improvement (#37232)
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> (cherry picked from commit a10df8b0b5a81aad096d1c7299edddfd0f4e3d14)
-rw-r--r--lib/ansible/modules/network/nxos/nxos_snapshot.py30
1 files changed, 6 insertions, 24 deletions
diff --git a/lib/ansible/modules/network/nxos/nxos_snapshot.py b/lib/ansible/modules/network/nxos/nxos_snapshot.py
index fef3e52b25..b989a7bfe9 100644
--- a/lib/ansible/modules/network/nxos/nxos_snapshot.py
+++ b/lib/ansible/modules/network/nxos/nxos_snapshot.py
@@ -69,7 +69,7 @@ options:
default: null
comparison_results_file:
description:
- - Name of the file where snapshots comparison will be store.
+ - Name of the file where snapshots comparison will be stored when C(action=compare).
required: false
default: null
compare_option:
@@ -353,6 +353,11 @@ def main():
argument_spec.update(nxos_argument_spec)
+ required_if = [("action", "compare", ["snapshot1", "snapshot2", "comparison_results_file"]),
+ ("action", "create", ["snapshot_name", "description"]),
+ ("action", "add", ["section", "show_command", "row_id", "element_key1"]),
+ ("action", "delete", ["snapshot_name"])]
+
module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)
@@ -362,33 +367,10 @@ def main():
action = module.params['action']
comparison_results_file = module.params['comparison_results_file']
- CREATE_PARAMS = ['snapshot_name', 'description']
- ADD_PARAMS = ['section', 'show_command', 'row_id', 'element_key1']
- COMPARE_PARAMS = ['snapshot1', 'snapshot2', 'comparison_results_file']
-
if not os.path.isdir(module.params['path']):
module.fail_json(msg='{0} is not a valid directory name.'.format(
module.params['path']))
- if action == 'create':
- for param in CREATE_PARAMS:
- if not module.params[param]:
- module.fail_json(msg='snapshot_name and description are '
- 'required when action=create')
- elif action == 'add':
- for param in ADD_PARAMS:
- if not module.params[param]:
- module.fail_json(msg='section, show_command, row_id '
- 'and element_key1 are required '
- 'when action=add')
- elif action == 'compare':
- for param in COMPARE_PARAMS:
- if not module.params[param]:
- module.fail_json(msg='snapshot1 and snapshot2 are required '
- 'when action=create')
- elif action == 'delete' and not module.params['snapshot_name']:
- module.fail_json(msg='snapshot_name is required when action=delete')
-
existing_snapshots = invoke('get_existing', module)
action_results = invoke('action_%s' % action, module, existing_snapshots)