marverix.nodejs
Ansible角色:Node.js
这是一个在Linux上安装Node.js、npm并可选进行基本npm配置的Ansible角色。
功能
- ✔️ 安装Node.js
- 可定义要安装的版本
- 确保安装了最新版本的
npm
- ✔️
npm
配置- 为用户设置全局注册表
- 为用户设置前缀
- 为用户设置默认作用域
- 为用户配置作用域
- ✔️ 安装你希望的全局
npm
包 - ✔️ 确保
nodejs
别名可用 - ✔️ 使用Molecule验证进行测试
支持的平台
- ✔️ Ubuntu 16.04 (Xenial)
- ✔️ Ubuntu 18.04 (Bionic)
- ✔️ Ubuntu 20.04 (Focal)
- ✔️ CentOS 7
- ✔️ CentOS 8
要求
无
角色变量
变量 | 描述 | 默认值 |
---|---|---|
nodejs_version |
要安装的Node.js版本 | 14 |
nodejs_npm_install_globally |
应该全局安装的npm 包列表 |
[] |
nodejs_npm_config |
npm 配置列表 - 见“如何配置npm”部分 |
[] |
如何配置npm
nodejs_npm_config
必须是对象数组。每个对象的结构如下:
属性 | 描述 | 是否必需 |
---|---|---|
user |
用户(每个用户一个npm配置) | 是 |
prefix |
npm前缀 | 否 |
registry |
npm注册表URL | 否 |
scopes |
作用域列表。每个作用域必须有name (不带@ )和registry 。请参阅下面的剧本示例。 |
否 |
default_scope |
默认作用域 | 否 |
依赖关系
无
示例剧本
最简单的示例
--- - hosts: all roles: - marverix.nodejs
全局安装
mocha
和eslint
--- - hosts: all roles: - role: marverix.nodejs vars: nodejs_npm_install_globally: - mocha - eslint
为用户
root
设置npm
注册表,设置前缀,配置作用域并设置默认作用域:--- - hosts: all roles: - role: marverix.nodejs vars: nodejs_npm_config: - user: root prefix: /home/root/.node registry: https://nexus.example.org/repository/npm/ scopes: - name: example-int registry: https://nexus.example.org/repository/npm-int/ - name: example2-int registry: https://nexus.example2.org/repository/npm-int/ default_scope: example-int
顺便说一句:这里有一篇好博客,讲述如何将Nexus设置为你的
npm
注册表: https://blog.sonatype.com/using-nexus-3-as-your-repository-part-2-npm-packages
许可证
ISC
关于项目
Ansible role that installs Node.js and configures npm
安装
ansible-galaxy install marverix.nodejs
许可证
isc
下载
189
拥有者
Everyday normal Software Engineer