1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

npm: replace test with required_if (#6848)

* npm: replace test with required_if

* add changelog frag
This commit is contained in:
Alexei Znamensky 2023-07-06 08:07:58 +12:00 committed by GitHub
parent c34a22717e
commit 11406715f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 14 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- npm - minor improvement on parameter validation (https://github.com/ansible-collections/community.general/pull/6848).

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,

View file

@ -12,10 +12,10 @@
# sample: node-v8.2.0-linux-x64.tar.xz
node_path: '{{ remote_dir }}/{{ nodejs_path }}/bin'
package: 'iconv-lite'
environment:
PATH: '{{ node_path }}:{{ ansible_env.PATH }}'
block:
- shell: npm --version
environment:
PATH: '{{ node_path }}:{{ ansible_env.PATH }}'
register: npm_version
- debug:
@ -24,11 +24,8 @@
- name: 'Install simple package without dependency'
npm:
path: '{{ remote_dir }}'
executable: '{{ node_path }}/npm'
state: present
name: '{{ package }}'
environment:
PATH: '{{ node_path }}:{{ ansible_env.PATH }}'
register: npm_install
- assert:
@ -39,11 +36,8 @@
- name: 'Reinstall simple package without dependency'
npm:
path: '{{ remote_dir }}'
executable: '{{ node_path }}/npm'
state: present
name: '{{ package }}'
environment:
PATH: '{{ node_path }}:{{ ansible_env.PATH }}'
register: npm_reinstall
- name: Check there is no change
@ -60,11 +54,8 @@
- name: 'reinstall simple package'
npm:
path: '{{ remote_dir }}'
executable: '{{ node_path }}/npm'
state: present
name: '{{ package }}'
environment:
PATH: '{{ node_path }}:{{ ansible_env.PATH }}'
register: npm_fix_install
- name: Check result is changed and successful