Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm: Add force flag #8885

Merged
merged 5 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/8885-add-force-flag-for-nmp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- npm - add ``force`` parameter to allow ``--force`` (https://github.com/ansible-collections/community.general/pull/8885).
19 changes: 17 additions & 2 deletions plugins/modules/npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@
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)
'''
Expand All @@ -117,6 +123,11 @@
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
Expand Down Expand Up @@ -167,6 +178,7 @@ def __init__(self, module, **kwargs):
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(' ')
Expand All @@ -191,6 +203,7 @@ def __init__(self, module, **kwargs):
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'),
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
)
)

Expand All @@ -212,7 +225,7 @@ def _exec(self, args, run_in_check_mode=False, check_rc=True, add_package_name=T
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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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']:
Expand Down