mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[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:
parent
1c8fbed36c
commit
42cc5280d9
3 changed files with 6 additions and 14 deletions
2
changelogs/fragments/6848-npm-required-if.yml
Normal file
2
changelogs/fragments/6848-npm-required-if.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- npm - minor improvement on parameter validation (https://github.com/ansible-collections/community.general/pull/6848).
|
|
@ -285,7 +285,8 @@ def main():
|
||||||
arg_spec['global'] = dict(default=False, type='bool')
|
arg_spec['global'] = dict(default=False, type='bool')
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=arg_spec,
|
argument_spec=arg_spec,
|
||||||
supports_check_mode=True
|
required_if=[('state', 'absent', ['name'])],
|
||||||
|
supports_check_mode=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
name = module.params['name']
|
name = module.params['name']
|
||||||
|
@ -304,8 +305,6 @@ def main():
|
||||||
|
|
||||||
if not path and not glbl:
|
if not path and not glbl:
|
||||||
module.fail_json(msg='path must be specified when not using global')
|
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,
|
npm = Npm(module, name=name, path=path, version=version, glbl=glbl, production=production,
|
||||||
executable=executable, registry=registry, ignore_scripts=ignore_scripts,
|
executable=executable, registry=registry, ignore_scripts=ignore_scripts,
|
||||||
|
|
|
@ -12,10 +12,10 @@
|
||||||
# sample: node-v8.2.0-linux-x64.tar.xz
|
# sample: node-v8.2.0-linux-x64.tar.xz
|
||||||
node_path: '{{ remote_dir }}/{{ nodejs_path }}/bin'
|
node_path: '{{ remote_dir }}/{{ nodejs_path }}/bin'
|
||||||
package: 'iconv-lite'
|
package: 'iconv-lite'
|
||||||
block:
|
|
||||||
- shell: npm --version
|
|
||||||
environment:
|
environment:
|
||||||
PATH: '{{ node_path }}:{{ ansible_env.PATH }}'
|
PATH: '{{ node_path }}:{{ ansible_env.PATH }}'
|
||||||
|
block:
|
||||||
|
- shell: npm --version
|
||||||
register: npm_version
|
register: npm_version
|
||||||
|
|
||||||
- debug:
|
- debug:
|
||||||
|
@ -24,11 +24,8 @@
|
||||||
- name: 'Install simple package without dependency'
|
- name: 'Install simple package without dependency'
|
||||||
npm:
|
npm:
|
||||||
path: '{{ remote_dir }}'
|
path: '{{ remote_dir }}'
|
||||||
executable: '{{ node_path }}/npm'
|
|
||||||
state: present
|
state: present
|
||||||
name: '{{ package }}'
|
name: '{{ package }}'
|
||||||
environment:
|
|
||||||
PATH: '{{ node_path }}:{{ ansible_env.PATH }}'
|
|
||||||
register: npm_install
|
register: npm_install
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
|
@ -39,11 +36,8 @@
|
||||||
- name: 'Reinstall simple package without dependency'
|
- name: 'Reinstall simple package without dependency'
|
||||||
npm:
|
npm:
|
||||||
path: '{{ remote_dir }}'
|
path: '{{ remote_dir }}'
|
||||||
executable: '{{ node_path }}/npm'
|
|
||||||
state: present
|
state: present
|
||||||
name: '{{ package }}'
|
name: '{{ package }}'
|
||||||
environment:
|
|
||||||
PATH: '{{ node_path }}:{{ ansible_env.PATH }}'
|
|
||||||
register: npm_reinstall
|
register: npm_reinstall
|
||||||
|
|
||||||
- name: Check there is no change
|
- name: Check there is no change
|
||||||
|
@ -60,11 +54,8 @@
|
||||||
- name: 'reinstall simple package'
|
- name: 'reinstall simple package'
|
||||||
npm:
|
npm:
|
||||||
path: '{{ remote_dir }}'
|
path: '{{ remote_dir }}'
|
||||||
executable: '{{ node_path }}/npm'
|
|
||||||
state: present
|
state: present
|
||||||
name: '{{ package }}'
|
name: '{{ package }}'
|
||||||
environment:
|
|
||||||
PATH: '{{ node_path }}:{{ ansible_env.PATH }}'
|
|
||||||
register: npm_fix_install
|
register: npm_fix_install
|
||||||
|
|
||||||
- name: Check result is changed and successful
|
- name: Check result is changed and successful
|
||||||
|
|
Loading…
Reference in a new issue