From 7e8e8948a3de5d435c0826bbafcbce8139918bb4 Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Thu, 30 Oct 2025 05:42:51 +1300 Subject: [PATCH] npm: improve parameter validation (#10983) * npm: improve parameter validation * add changelog frag * add required_if clause * fix required_if, add required_one_of, add docs * Update plugins/modules/npm.py * Update plugins/modules/npm.py * Update plugins/modules/npm.py Co-authored-by: Felix Fontein * Update plugins/modules/npm.py Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein --- changelogs/fragments/10983-npm-param-mutex.yml | 2 ++ plugins/modules/npm.py | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/10983-npm-param-mutex.yml 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,