Jan*_*han 7 node.js ansible ansible-role
我正在寻找一个合适的Ansible Role或Ansible YAML文件,用于在Ubuntu 16.04.3 xenial系统上安装NodeJS LTS.我从Galaxy尝试了超过10个Ansible角色,但没有找到任何工作(抛出错误,如potentially dangerous to add this PPA etc..
任何人都可以提供任何Ansible剧本或建议我在Ubuntu 16.04上安装NodeJS LTS的角色吗?
Arb*_*zar 12
这是工作示例:
---
- hosts: all
gather_facts: yes
become: yes
vars:
NODEJS_VERSION: "8"
ansible_distribution_release: "xenial" #trusty
tasks:
- name: Install the gpg key for nodejs LTS
apt_key:
url: "https://deb.nodesource.com/gpgkey/nodesource.gpg.key"
state: present
- name: Install the nodejs LTS repos
apt_repository:
repo: "deb https://deb.nodesource.com/node_{{ NODEJS_VERSION }}.x {{ ansible_distribution_release }} main"
state: present
update_cache: yes
- name: Install the nodejs
apt:
name: nodejs
state: present
Run Code Online (Sandbox Code Playgroud)
希望它会对你有所帮助
并不是说我真的很高兴不得不这样做,但是......
(环境:Ubuntu 18.04,ansible 2.6.1,主机:macOS)
来自https://github.com/nodesource/distributions/blob/master/README.md#debinstall
- name: install node
shell: |
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - && sudo apt-get install -y nodejs
Run Code Online (Sandbox Code Playgroud)
结果:
> vagrant@vagrant:~$ node --version
v10.15.2
Run Code Online (Sandbox Code Playgroud)
并且npm一定也出现了:
vagrant@vagrant:~$ npm --version
6.4.1
Run Code Online (Sandbox Code Playgroud)
在我运行这个时,https: //www.npmjs.com/package/npm显示6.8.0是最新的,6.4.1是 6 个月前的。Node 显示10.15.2是 10.x 系列中的最新版本,日期为 5 天前。
顺便说一句,我也尝试过,apt-get但以节点 8.x 而不是 10.x 结束
我没有使用 ansible Galaxy 角色的原因是我没有看到任何似乎来自知名作者并且拥有大量明星和下载的 nodejs 角色(我很谨慎和怀疑)。
我的开发机器有6.8.0所以我添加了这个:
变量.yml :
versions:
npm: "6.8.0"
Run Code Online (Sandbox Code Playgroud)
剧本.yml :
- name: npm self-update
command: npm install npm@{{ versions.npm }} -g
Run Code Online (Sandbox Code Playgroud)
这让我一路:
vagrant@vagrant:~$ npm --version
6.8.0
Run Code Online (Sandbox Code Playgroud)
接受的答案很好,但如果您愿意,可以使用已发现的变量作为发行版代号(即ansible_lsb.codename)。此外,确保gcc g++ make已安装在主机上可确保 nodejs 的本机插件正常工作。
只需用12你想要的替换节点版本。
---
- name: Install nodejs
hosts: all
become: true
tasks:
- name: install nodejs prerequisites
apt:
name:
- apt-transport-https
- gcc
- g++
- make
state: present
- name: add nodejs apt key
apt_key:
url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
state: present
- name: add nodejs repository
apt_repository:
repo: deb https://deb.nodesource.com/node_12.x {{ ansible_lsb.codename }} main
state: present
update_cache: yes
- name: install nodejs
apt:
name: nodejs
state: present
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6689 次 |
| 最近记录: |