diff --git a/changelogs/fragments/49664-npm-added-ci-param.yaml b/changelogs/fragments/49664-npm-added-ci-param.yaml new file mode 100644 index 0000000000..9ae98862c3 --- /dev/null +++ b/changelogs/fragments/49664-npm-added-ci-param.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: + - "npm ci feature added which allows to install a project with a clean slate: https://docs.npmjs.com/cli/ci.html" diff --git a/lib/ansible/modules/packaging/language/npm.py b/lib/ansible/modules/packaging/language/npm.py index aa608052f8..4afa2ef56e 100644 --- a/lib/ansible/modules/packaging/language/npm.py +++ b/lib/ansible/modules/packaging/language/npm.py @@ -59,6 +59,12 @@ options: type: bool default: no version_added: "2.8" + ci: + description: + - Install packages based on package-lock file, same as running npm ci + type: bool + default: no + version_added: "2.8" production: description: - Install dependencies in production mode, excluding devDependencies @@ -211,6 +217,9 @@ class Npm(object): def install(self): return self._exec(['install']) + def ci_install(self): + return self._exec(['ci']) + def update(self): return self._exec(['update']) @@ -241,6 +250,7 @@ def main(): state=dict(default='present', choices=['present', 'absent', 'latest']), ignore_scripts=dict(default=False, type='bool'), unsafe_perm=dict(default=False, type='bool'), + ci=dict(default=False, type='bool'), ) arg_spec['global'] = dict(default='no', type='bool') module = AnsibleModule( @@ -258,6 +268,7 @@ def main(): state = module.params['state'] ignore_scripts = module.params['ignore_scripts'] unsafe_perm = module.params['unsafe_perm'] + ci = module.params['ci'] if not path and not glbl: module.fail_json(msg='path must be specified when not using global') @@ -269,7 +280,10 @@ def main(): unsafe_perm=unsafe_perm, state=state) changed = False - if state == 'present': + if ci: + npm.ci_install() + changed = True + elif state == 'present': installed, missing = npm.list() if missing: changed = True