Reputation: 1284
I have a long list of items for Ansible npm install, and using a "with_items" is very slow. I would like to use a list in a single session, such as:
- name: "define list for npm install"
set_fact:
npm_install_list:
- 'mkdirp'
- 'request'
- 'extend'
... lots more ...
- name: "npm install a list at once"
npm:
name: "{{ npm_install_list | join(' ') }}"
registry: 'http://path.to.private.registry'
global: yes
state: present
I get this error:
no JSON object could be decoded
Could this work with npm? If so, what am I doing wrong?
Upvotes: 3
Views: 1340
Reputation: 68559
Could this work with npm?
No.
Just try with name: package1 package2
and you will see why:
cmd: /bin/npm install --global 'package1 package2'
name
argument expects a string and treats the given value as string thus escaping/quoting it.
—-
As a side note, some other package management modules in Ansible automatically combine the items (packages) into a single execution call (though primarily to avoid problems with dependencies, not for optimization). npm
module does not.
Upvotes: 2
Reputation: 2519
under group_vats/all define your array as top level
npm_install_list:
- 'mkdirp'
- 'request'
- 'extend'
... lots more ...
Now use this array as usual in your role
- name: "npm install a list at once"
npm:
name: "{{ npm_install_list | join(' ') }}"
registry: 'http://path.to.private.registry'
global: yes
state: present
Upvotes: -1