[PR #8885/38479ee9 backport][stable-9] npm: Add force flag (#8893)

npm: Add force flag (#8885)

* Add force flag for nmp module

* Add CHANGELOG fragment

* Add force to cmdrunner

* Update CHANGELOG

* Add comma

(cherry picked from commit 38479ee9ff)

Co-authored-by: alexander <79072457+abakanovskii@users.noreply.github.com>
pull/8896/head
patchback[bot] 2024-09-21 10:42:31 +03:00 committed by GitHub
parent 57277e0661
commit eae0c4f92b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 2 deletions

View File

@ -0,0 +1,2 @@
minor_changes:
- npm - add ``force`` parameter to allow ``--force`` (https://github.com/ansible-collections/community.general/pull/8885).

View File

@ -96,6 +96,12 @@ options:
type: bool
default: false
version_added: 2.5.0
force:
description:
- Use the C(--force) flag when installing.
type: bool
default: false
version_added: 9.5.0
requirements:
- npm installed in bin path (recommended /usr/local/bin)
'''
@ -117,6 +123,11 @@ EXAMPLES = r'''
name: coffee-script
global: true
- name: Force Install "coffee-script" node.js package.
community.general.npm:
name: coffee-script
force: true
- name: Remove the globally package "coffee-script".
community.general.npm:
name: coffee-script
@ -167,6 +178,7 @@ class Npm(object):
self.state = kwargs['state']
self.no_optional = kwargs['no_optional']
self.no_bin_links = kwargs['no_bin_links']
self.force = kwargs['force']
if kwargs['executable']:
self.executable = kwargs['executable'].split(' ')
@ -191,6 +203,7 @@ class Npm(object):
registry=cmd_runner_fmt.as_opt_val('--registry'),
no_optional=cmd_runner_fmt.as_bool('--no-optional'),
no_bin_links=cmd_runner_fmt.as_bool('--no-bin-links'),
force=cmd_runner_fmt.as_bool('--force'),
)
)
@ -212,7 +225,7 @@ class Npm(object):
params['name_version'] = self.name_version if add_package_name else None
with self.runner(
"exec_args global_ production ignore_scripts unsafe_perm name_version registry no_optional no_bin_links",
"exec_args global_ production ignore_scripts unsafe_perm name_version registry no_optional no_bin_links force",
check_rc=check_rc, cwd=cwd
) as ctx:
rc, out, err = ctx.run(**params)
@ -289,6 +302,7 @@ def main():
ci=dict(default=False, type='bool'),
no_optional=dict(default=False, type='bool'),
no_bin_links=dict(default=False, type='bool'),
force=dict(default=False, type='bool'),
)
arg_spec['global'] = dict(default=False, type='bool')
module = AnsibleModule(
@ -318,7 +332,8 @@ def main():
unsafe_perm=module.params['unsafe_perm'],
state=state,
no_optional=module.params['no_optional'],
no_bin_links=module.params['no_bin_links'])
no_bin_links=module.params['no_bin_links'],
force=module.params['force'])
changed = False
if module.params['ci']: