diff --git a/changelogs/fragments/10983-npm-param-mutex.yml b/changelogs/fragments/10983-npm-param-mutex.yml new file mode 100644 index 0000000000..14af07f385 --- /dev/null +++ b/changelogs/fragments/10983-npm-param-mutex.yml @@ -0,0 +1,2 @@ +minor_changes: + - npm - improve parameter validation using Ansible construct (https://github.com/ansible-collections/community.general/pull/10983). diff --git a/plugins/modules/npm.py b/plugins/modules/npm.py index 850384bd31..6d1469d91a 100644 --- a/plugins/modules/npm.py +++ b/plugins/modules/npm.py @@ -28,6 +28,7 @@ options: path: description: - The base path where to install the node.js libraries. + - When O(global=true), then O(path) is not used to install the packages. type: path required: false version: @@ -38,6 +39,7 @@ options: global: description: - Install the node.js library globally. + - When O(global=true), then O(path) is not used to install the packages. required: false default: false type: bool @@ -303,7 +305,10 @@ def main(): arg_spec['global'] = dict(default=False, type='bool') module = AnsibleModule( argument_spec=arg_spec, - required_if=[('state', 'absent', ['name'])], + required_if=[ + ('state', 'absent', ['name']), + ("global", False, ["path"]), + ], supports_check_mode=True, ) @@ -313,9 +318,6 @@ def main(): glbl = module.params['global'] state = module.params['state'] - if not path and not glbl: - module.fail_json(msg='path must be specified when not using global') - npm = Npm(module, name=name, path=path,