[英]ansible install node.js version 6
For installing the node 6.x version these are the commands: 要安装节点6.x版本,请执行以下命令:
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
now how exactly do I do that in ansible? 现在我在ansible中究竟是怎么做到的? any ideas here? 这里有什么想法?
this is what I had till now, but it installs the old version 这是我迄今为止所拥有的,但它安装了旧版本
---
- 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}}"
I was using this playbook for installing node 6.1.0 via nvm(node version manager): 我正在使用这个playbook通过nvm(节点版本管理器)安装节点6.1.0:
Note: You may need to change the hosts and connection in the play. 注意:您可能需要更改播放中的主机和连接。
---
- 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 }}
For more information on nvm, see: https://github.com/creationix/nvm 有关nvm的更多信息,请参阅: https : //github.com/creationix/nvm
Based on the code in the original question, and the helpful comment from @ydaetskcoR , I was able to install NodeJS 6.x with the following on Ubuntu 16.04: 基于原始问题中的代码和@ydaetskcoR的有用评论 ,我能够在Ubuntu 16.04上安装以下的NodeJS 6.x:
- name: Add Nodesource Keys
become: yes
apt_key:
url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
state: present
# Note: "xenial" is ubuntu-speak for 16.04
- name: Add Nodesource Apt Sources
become: yes
apt_repository:
repo: '{{ item }}'
state: present
with_items:
- 'deb https://deb.nodesource.com/node_6.x xenial main'
- 'deb-src https://deb.nodesource.com/node_6.x xenial main'
- name: Install NodeJS and NPM
become: yes
apt:
name: '{{ item }}'
state: latest
update_cache: yes
with_items:
- nodejs
- nodejs-legacy
- npm
I've refactored a little for brevity, but the most important thing is the addition of _6.x
to the repository URLs . 为简洁起见,我进行了一些重构,但最重要的是在存储库URL中添加了_6.x
.
This worked for me using Ansible 2.3.2.0 这对我使用Ansible 2.3.2.0很有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.