Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Ansible:强制安装最新的nodejs包_Node.js_Vagrant_Ansible_Virtualbox_Apt - Fatal编程技术网

Node.js Ansible:强制安装最新的nodejs包

Node.js Ansible:强制安装最新的nodejs包,node.js,vagrant,ansible,virtualbox,apt,Node.js,Vagrant,Ansible,Virtualbox,Apt,我不明白为什么Ansible正在安装旧版本的nodejs,尽管我将其设置为安装最新版本: - name: NodeJS => Install NodeJS apt: pkg: "{{ item }}" state: latest force: yes update_cache: yes with_items: - nodejs - npm become: yes - name: NodeJS => Crea

我不明白为什么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"

您需要首先为要安装的nodejs分支设置ppa存储库,例如6.x分支(如果需要7.x分支,请更改)


然后您将能够安装node和npm。

ansible将从repo获取最新版本,您的vagrant box是什么?config.vm.box=“ubuntu/trusty64”是否有可能在不指定版本的情况下更新到最新版本?不太可能,因为此版本的repo非常旧,您需要更新repo,nodejs以这种方式维护回购协议
- apt_repository:
    repo: deb https://deb.nodesource.com/setup_6.x nodejs
    state: present