1

I want to install package.json using ansible, I'm using the example from the docs, only thing different from this is that I'm using npm not nvm so the tasks look like this

- name: npm install (manual)
  npm:
    path:"{{ project_path }}"
    executable: /usr/bin/npm

{{ project_path }} is path to package.json file, basically it's /srv/example.com/.

The result of this tasks is

TASK [angular : npm install (manual)] ******************************************
task path: /srv/example.com/orchestration/ansible/roles/angular/tasks/main.yml:16
Using module file /usr/local/lib/python2.7/dist-packages/ansible/modules/packaging/language/npm.py
<default> ESTABLISH LOCAL CONNECTION FOR USER: vagrant
<default> EXEC /bin/sh -c 'echo ~ && sleep 0'
<default> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/vagrant/.ansible/tmp/ansible-tmp-1540437954.12-74081721294328 `" && echo ansible-tmp-1540437954.12-74081721294328="` echo /home/vagrant/.ansible/tmp/ansible-tmp-1540437954.12-74081721294328 `" ) && sleep 0'
<default> PUT /tmp/tmpkx6E4h TO /home/vagrant/.ansible/tmp/ansible-tmp-1540437954.12-74081721294328/npm.py
<default> EXEC /bin/sh -c 'chmod u+x /home/vagrant/.ansible/tmp/ansible-tmp-1540437954.12-74081721294328/ /home/vagrant/.ansible/tmp/ansible-tmp-1540437954.12-74081721294328/npm.py && sleep 0'
<default> EXEC /bin/sh -c 'sudo -H -S -n -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-anopitzukaokwawzhqmxqjfzoxjtozxh; /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1540437954.12-74081721294328/npm.py; rm -rf "/home/vagrant/.ansible/tmp/ansible-tmp-1540437954.12-74081721294328/" > /dev/null 2>&1'"'"' && sleep 0'
ok: [default] => {
    "changed": false, 
    "invocation": {
        "module_args": {
            "executable": "/usr/bin/npm", 
            "global": false, 
            "ignore_scripts": false, 
            "name": null, 
            "path": "/srv/example.com/", 
            "production": false, 
            "registry": null, 
            "state": "present", 
            "version": null
        }
    }
}

It does not do anything, why? How can I install my package.json, can someone please help me understand how to overcome this, thanks.

copser
  • 2,523
  • 5
  • 38
  • 73
  • According to [the source](https://github.com/ansible/ansible/blob/v2.5.10/lib/ansible/modules/packaging/language/npm.py#L268), it will do that if all the deps are already installed. Are you certain they aren't already installed, and I would encourage you to check the global `node_modules` since you're running npm as root (not that _this task_ installed them globally, but that they _were already_ installed globally) – mdaniel Oct 25 '18 at 06:05
  • Hey, `npm -g ls --depth=0` will only show `angular/cli` and `npm` installed, so nope it didn't installed `package.json` globally – copser Oct 25 '18 at 06:26
  • It's Ansible version, changed to `2.5.0` from `2.3.2`, and it works, more info [here](https://github.com/ansible/ansible/issues/33555) – copser Oct 25 '18 at 08:17

0 Answers0