gpt4 book ai didi

node.js - ansible 安装 node.js 版本 6

转载 作者:搜寻专家 更新时间:2023-10-31 22:59:06 24 4
gpt4 key购买 nike

安装 node 6.x 版本的命令如下:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

现在我该如何在 ansible 中做到这一点?这里有什么想法吗?

这是我到目前为止所拥有的,但它安装的是旧版本

---
- name: Ensure Ubuntu Distro is Supported
get_url:
url='https://deb.nodesource.com/node/dists/"{{ ansible_distribution_release }}"/Release'
dest=/dev/null
register: distrosupported


- name: Remove Old Chris Lea PPA
apt_repository:
repo='ppa:chris-lea/node.js'
state=absent
when: distrosupported|success
ignore_errors: yes

- name: Remove Old Chris Lea Sources
sudo: yes
file:
path='/etc/apt/sources.list.d/chris-lea-node_js-"{{ ansible_distribution_release }}".list'
state=absent
when: distrosupported|success
ignore_errors: yes

- name: Add Nodesource Keys
sudo: yes
apt_key:
url=https://deb.nodesource.com/gpgkey/nodesource.gpg.key
state=present

- name: Add Nodesource Apt Sources List Deb
sudo: yes
apt_repository:
repo='deb https://deb.nodesource.com/node "{{ ansible_distribution_release }}" main'
state=present
when: distrosupported|success

- name: Add Nodesource Apt Sources List Deb Src
sudo: yes
apt_repository:
repo='deb-src https://deb.nodesource.com/node "{{ ansible_distribution_release }}" main'
state=present
when: distrosupported|success

- name: Install NodeJS
sudo: yes
apt: pkg=nodejs state=latest update_cache=true
when: distrosupported|success





- debug: msg="{{npm_pkgs}}"


- name: install global npm packages
sudo: yes
npm: name={{item}} global=yes state=latest
with_items: "{{npm_pkgs}}"

最佳答案

我使用这个剧本通过 nvm( Node 版本管理器)安装 Node 6.1.0:

注意:您可能需要在播放中更改主机和连接。

---
- hosts: localhost
connection: local
vars:
node_version: 6.1.0
tasks:
- name: Download the nvm(node version manager) install script
get_url: url=https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh dest=/tmp/install.sh

- name: Install dependencies
apt: pkg={{ item }} update_cache=yes cache_valid_time=3600
with_items:
- git
- curl
- build-essential
- libssl-dev
become: yes
become_user: root

- name: Execute the nvm install script
shell: bash install.sh chdir=/tmp executable=/bin/bash

- name: Register the NVM_DIR
shell: echo $NVM_DIR
register: nvm_dir

- name: Install the specified node version using the nvm command and set it as default
shell: . {{ nvm_dir.stdout }}/nvm.sh && nvm install {{ node_version }} && nvm run {{node_version}} --version && nvm alias default {{node_version}}
creates=~/.nvm/versions/node/v{{ node_version }}

有关 nvm 的更多信息,请参阅:https://github.com/creationix/nvm

关于node.js - ansible 安装 node.js 版本 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37137513/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com