-1

Right now, I'm just trying to set up a YAML script that simply checks if a particular node package is installed or not. The way I currently have it is:

command: npm list selenium-webdriver >/dev/null || npm install selenium-webdriver

However, this always returns:

fatal: [localhost -> localhost]: FAILED! => {"changed": false, "cmd": ["npm", "ls", "selenium-webdriver", ">/dev/null", "||", "npm", "install", "selenium-webdriver"], "delta": "0:00:00.463110", "end": "2017-08-09 12:56:30.359529", "failed": true, "rc": 1, "start": "2017-08-09 12:56:29.896419", "stderr": "npm ERR! code 1", "stdout": "/myDir\n└── (empty)", "stdout_lines": ["/myDir", "└── (empty)"], "warnings": []}

I'm not entirely sure what an "npm ERR! code 1" error even is.

I tried to shorten it to see what the error might be, can it seems to be the argument:

npm list selenium-webdriver

I was hoping that it would run the first command, and IF that failed, then run the second command (the installation).

How exactly do I go about doing such that this command acts in the manner I'm looking for?

  • There is no such thing as a YAML script. You seem to be confusing something that is using a YAML document as its input with "YAML doing something". It makes as much sense to ask "How do you get UTF-8 to run two functions with Node.js" or ask about an "ASCII script". – Anthon Aug 09 '17 at 18:38

1 Answers1

0

Isn't better to use npm module?

- npm:
    name: selenium-webdriver
    path: /app/location

npm module is idempotent and it will only install the selenium-webdriver if it is not installed already.

Arbab Nazar
  • 22,378
  • 10
  • 76
  • 82
  • I do not have permissions to use this. I'm not the administrator. So this method won't work. –  Aug 09 '17 at 18:37
  • in the above mentioned command, you are doing the same thing `npm install selenium-webdriver`? – Arbab Nazar Aug 09 '17 at 19:02
  • I think it's the global part that gives me the error. What should be done if you set the global variable to no, instead of yes? –  Aug 09 '17 at 19:26
  • you can remove the global line and then run it – Arbab Nazar Aug 09 '17 at 19:27
  • This is the output: fatal: [localhost -> localhost]: FAILED! => {"changed": false, "failed": true, "msg": "path must be specified when not using global"} –  Aug 09 '17 at 19:34
  • I solved it using this: https://stackoverflow.com/questions/19369931/ansible-how-to-change-active-directory-in-ansible-playbook –  Aug 09 '17 at 19:35
  • check the updated answer, it will help you, I got your point that you want to install it in custom location – Arbab Nazar Aug 09 '17 at 19:38