4

我正在尝试使用 ansible 使用 karma-phantomjs-launcher 插件为詹金斯提供业力测试服务器。我希望避免使用“exec npm install”格式的shellscripts。

问题在于 phantomjs 插件需要--save-dev在安装时使用该标志。我正在寻找使用--save-devnpm 的标志,但 ansible npm 模块似乎没有办法将这些标志传递给它运行的实际 npm 命令。

这可能吗,还是我应该求助于使用 ansible 的命令模块来运行npm install karma-phantomjs-launcher --save-dev

4

1 回答 1

0

这与您的问题不完全相同,但我遇到了类似的问题,试图让 npm 使用 ansible 中的代理。我发现您可以运行 npm 命令,因此可以运行 npm config 命令。我假设save-dev大多数事情都有一个 npm config 命令。

就我而言,我在一个角色中设置了一个任务,该角色负责设置 apache 和 npm(并安装 npm 的 bower 包)。

这是从我的任务中截取的(请记住,这是在角色内部,而不是直接任务,它遵循 yum with 命令,该命令传递了一个包列表,包括 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

抱歉,如果这没有帮助

于 2017-05-08T10:07:28.773 回答