我不明白为什么Ansible正在安装旧版本的nodejs,即使我将其设置为安装最新版本:
- name: NodeJS => Install NodeJS
apt:
pkg: "{{ item }}"
state: latest
force: yes
update_cache: yes
with_items:
- nodejs
- npm
become: yes
- name: NodeJS => Create link symlink for node
become: yes
file:
src: /usr/bin/nodejs
dest: /usr/bin/node
state: link
对于我现在拥有的当前版本:
$ node -v
v0.10.25
$ npm -v
1.3.10
我终于在我的task / main.yml
中做了这个---
- name: Ensure apt-transport-https is installed.
apt: name=apt-transport-https state=present
- name: Add Nodesource apt key.
become: yes
apt_key:
url: https://keyserver.ubuntu.com/pks/lookup?op=get&fingerprint=on&search=0x1655A0AB68576280
id: "68576280"
state: present
- name: Add NodeSource repositories for Node.js.
become: yes
apt_repository:
repo: "{{ item }}"
state: present
with_items:
- "deb https://deb.nodesource.com/node_{{ params['nodejs'].version }} {{ ansible_distribution_release }} main"
# - "deb-src https://deb.nodesource.com/node_{{ params['nodejs'].version }} {{ ansible_distribution_release }} main"
register: node_repo
- name: Update apt cache if repo was added.
become: yes
apt: update_cache=yes
when: node_repo.changed
- name: Ensure Node.js and npm are installed.
become: yes
apt: "name=nodejs={{ params['nodejs'].version|regex_replace('x', '') }}* state=present"
答案 0 :(得分:1)
您需要首先为要安装的nodejs分支设置ppa存储库,例如6.x分支(如果需要7.x分支则更改)
- apt_repository:
repo: deb https://deb.nodesource.com/setup_6.x nodejs
state: present
然后你就可以安装node和npm了。