[PR #6848/11406715 backport][stable-7] npm: replace test with required_if (#6856)

npm: replace test with required_if (#6848)

* npm: replace test with required_if

* add changelog frag

(cherry picked from commit 11406715f5)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2023-07-06 06:42:25 +02:00 committed by GitHub
parent 1c8fbed36c
commit 42cc5280d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 14 deletions

View file

@ -285,7 +285,8 @@ def main():
arg_spec['global'] = dict(default=False, type='bool')
module = AnsibleModule(
argument_spec=arg_spec,
supports_check_mode=True
required_if=[('state', 'absent', ['name'])],
supports_check_mode=True,
)
name = module.params['name']
@ -304,8 +305,6 @@ def main():
if not path and not glbl:
module.fail_json(msg='path must be specified when not using global')
if state == 'absent' and not name:
module.fail_json(msg='uninstalling a package is only available for named packages')
npm = Npm(module, name=name, path=path, version=version, glbl=glbl, production=production,
executable=executable, registry=registry, ignore_scripts=ignore_scripts,