2017-06-02 50 views
0

我不明白爲什麼Ansible正在安裝的是舊版本的的NodeJS即使我將它安裝最新: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 

更新的解決方案

我終於在我的任務這樣做/ 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

ansible會採取最新的回購,你的流浪者箱子是什麼? –

+0

config.vm.box =「ubuntu/trusty64」 – numediaweb

回答

0

您需要先設置爲你想要安裝的分支的NodeJS PPA的庫,例如用於6.x的分支(其他城市,如果你想在7.x的分支)

- apt_repository: 
    repo: deb https://deb.nodesource.com/setup_6.x nodejs 
    state: present 

然後你將能夠安裝節點和npm。

+0

有沒有可能在不指定版本的情況下更新到最新版本? – numediaweb

+0

不是真的,因爲這個版本的回購很舊,您需要更新回購,並且nodejs以這種方式維護回購 –