【问题标题】:Ansible: force installing latest nodejs packageAnsible:强制安装最新的 nodejs 包
【发布时间】:2017-06-02 17:35:18
【问题描述】:

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

【问题讨论】:

  • ansible 将从 repo 中获取最新信息,你的 vagrant box 是什么?
  • config.vm.box = "ubuntu/trusty64"

标签: node.js vagrant ansible virtualbox apt


【解决方案1】:

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

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

然后你就可以安装node和npm了。

【讨论】:

  • 是否有可能在不指定版本的情况下更新到最新版本?
  • 不是真的,因为这个版本的repo已经很老了,你需要更新repo,nodejs就是这样维护repo的
猜你喜欢
  • 1970-01-01
  • 2014-09-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-16
  • 1970-01-01
相关资源
最近更新 更多