diff --git a/changelogs/fragments/8885-add-force-flag-for-nmp.yml b/changelogs/fragments/8885-add-force-flag-for-nmp.yml new file mode 100644 index 00000000000..40eaeff74b8 --- /dev/null +++ b/changelogs/fragments/8885-add-force-flag-for-nmp.yml @@ -0,0 +1,2 @@ +minor_changes: + - npm - add ``force`` parameter to allow ``--force`` (https://github.com/ansible-collections/community.general/pull/8885). diff --git a/plugins/modules/npm.py b/plugins/modules/npm.py index e6dc0b772a1..a906b2c1270 100644 --- a/plugins/modules/npm.py +++ b/plugins/modules/npm.py @@ -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) ''' @@ -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 @@ -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(' ') @@ -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'), ) ) @@ -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) @@ -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']: