Ansible、npm和--save-dev标志

4
我正在尝试使用ansible通过karma-phantomjs-launcher插件为jenkins提供karma测试服务器。我希望避免使用"exec npm install"格式的shell脚本。
问题在于phantomjs插件需要在安装时使用“--save-dev”标志。我想要使用npm中的“--save-dev”标志,但是ansible npm模块似乎没有办法将这些标志传递给它运行的实际npm命令。
这是否有可能,还是我应该只使用ansible的command模块运行“npm install karma-phantomjs-launcher --save-dev”?
1个回答

0

虽然问题不完全相同,但我曾经遇到过类似的问题,尝试在ansible内使用代理来获取npm。我发现你可以运行npm命令,从而运行npm配置命令。我假设有一个npm配置命令save-dev,对于大多数事情都是如此。

在我的情况下,我设置了一个任务,位于角色内部,负责设置apache和npm(并安装npm的bower包)。

这是我的任务代码片段(请记住,这是角色内部的代码片段,不是直接的任务,并且它跟随着一个yum命令,该命令传递一个包列表,其中包括npm)。

- name: Setup NPM HTTP Proxy
  become: True
  command: npm config set proxy "{{http_proxy}}"
  when: (http_proxy is defined) and (not http_proxy == '') and (node_modules.stat.exists == False)

- name: Clear NPM HTTP Proxy Setting
  become: True
  command: npm config rm proxy
  when: (http_proxy is defined) and (http_proxy == '') and (node_modules.stat.exists == False)

- name: Setup NPM HTTPS Proxy
  become: True
  command: npm config set https-proxy "{{https_proxy}}"
  when: (https_proxy is defined) and (not https_proxy == '') and (node_modules.stat.exists == False)

- name: Clear NPM HTTPS Proxy Setting
  become: True
  command: npm config rm https-proxy
  when: (https_proxy is defined) and (https_proxy == '') and (node_modules.stat.exists == False)

- name: Disable NPM strict SSL mode
  become: True
  command: npm config set strict-ssl false
  when: (http_proxy is defined) and (not http_proxy == '') and (node_modules.stat.exists == False)

- name: Clear NPM strict SSL mode Setting (if no http_proxy)
  become: True
  command: npm config rm strict-ssl
  when: (http_proxy is defined) and (http_proxy == '') and (node_modules.stat.exists == False)

- name: Setup NPM to use http:// version of the registry
  become: True
  command: npm config set registry "http://registry.npmjs.org/"
  when: (http_proxy is defined) and (not http_proxy == '') and (node_modules.stat.exists == False)

- name: Install Bower
  become: True
  shell: >
         umask 022; npm install bower chdir=/usr/local/lib
  when: node_modules.stat.exists == False

如果这没有帮助,我很抱歉。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接