community.general.npm 模块 – 使用 npm 管理 node.js 包
注意
此模块是 community.general 集合 (版本 10.1.0) 的一部分。
如果您使用的是 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用:ansible-galaxy collection install community.general。您需要其他要求才能使用此模块,请参阅 要求 获取详细信息。
要在 playbook 中使用它,请指定:community.general.npm。
概要
- 使用节点包管理器 (npm) 管理 node.js 包。 
要求
在执行此模块的主机上需要以下要求。
- 在 bin 路径中安装 npm (推荐 /usr/local/bin) 
参数
| 参数 | 注释 | 
|---|---|
| 根据 package-lock 文件安装包,与运行  选项 
 | |
| npm 的可执行文件位置。 如果您使用的是版本管理器(例如 nvm),这将很有用。 | |
| 安装时使用  选项 
 | |
| 全局安装 node.js 库。 选项 
 | |
| 安装时使用  选项 
 | |
| 要安装的 node.js 库的名称。 | |
| 安装时使用  选项 
 | |
| 安装时使用  选项 
 | |
| 安装 node.js 库的基本路径。 | |
| 以生产模式安装依赖项,不包括 devDependencies。 选项 
 | |
| 从中安装模块的注册表。 | |
| node.js 库的状态。 选项 
 | |
| 安装时使用  选项 
 | |
| 要安装的版本。 | 
属性
| 属性 | 支持 | 描述 | 
|---|---|---|
| 支持:完全支持 | 可以在  | |
| 支持:不支持 | 在差异模式下,将返回有关已更改内容(或可能需要在  | 
示例
- name: Install "coffee-script" node.js package.
  community.general.npm:
    name: coffee-script
    path: /app/location
- name: Install "coffee-script" node.js package on version 1.6.1.
  community.general.npm:
    name: coffee-script
    version: '1.6.1'
    path: /app/location
- name: Install "coffee-script" node.js package globally.
  community.general.npm:
    name: coffee-script
    global: true
- name: Force Install "coffee-script" node.js package.
  community.general.npm:
    name: coffee-script
    force: true
- name: Remove the globally package "coffee-script".
  community.general.npm:
    name: coffee-script
    global: true
    state: absent
- name: Install "coffee-script" node.js package from custom registry.
  community.general.npm:
    name: coffee-script
    registry: 'http://registry.mysite.com'
- name: Install packages based on package.json.
  community.general.npm:
    path: /app/location
- name: Update packages based on package.json to their latest version.
  community.general.npm:
    path: /app/location
    state: latest
- name: Install packages based on package.json using the npm installed with nvm v0.10.1.
  community.general.npm:
    path: /app/location
    executable: /opt/nvm/v0.10.1/bin/npm
    state: present
