[英]Installing NodeJS LTS for Ansible
我正在尋找合適的 Ansible 角色或 Ansible YAML 文件,以便在 Ubuntu 16.04.3 xenial 系統上安裝 NodeJS LTS。 我嘗試了超過 10 個來自 Galaxy 的 Ansible 角色,但沒有發現它們中的任何一個工作(拋出錯誤,例如potentially dangerous to add this PPA etc.
。.
任何人都可以提供任何 Ansible 劇本或建議我在 Ubuntu 16.04 上安裝 NodeJS LTS 的角色嗎?
這是工作示例:
---
- 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
希望它會幫助你
並不是說我真的很高興不得不這樣做,但是......
(環境: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
結果:
> vagrant@vagrant:~$ node --version
v10.15.2
並且npm
一定出現了:
vagrant@vagrant:~$ npm --version
6.4.1
在我運行這個時, 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"
劇本.yml :
- name: npm self-update
command: npm install npm@{{ versions.npm }} -g
這讓我一路:
vagrant@vagrant:~$ npm --version
6.8.0
接受的答案很好,但如果您願意,可以使用已發現的變量作為發行版代號(即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
您可以使用:
ansible-galaxy install nodesource.node
然后在你的劇本上,添加roles: - nodesource.node
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.