这与您的问题不完全相同,但我遇到了类似的问题,试图让 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
抱歉,如果这没有帮助