2016-05-10 12 views
3

Für den Knoten 6.x Version installieren, das sind die Befehle:ansible installieren node.js Version 6

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - 
sudo apt-get install -y nodejs 

nun, wie genau mache ich das in ansible? irgendwelche Ideen hier?

das ist, was ich bis jetzt hatte, aber es installiert die alte 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}}" 
+0

meinen alten und aktuellen Code hinzugefügt –

+0

Also, was genau falsch ist mit dem, was Sie versucht haben? – ydaetskcoR

+0

meins installiert Knoten Version 0.1, ich möchte Version 6. Ich Knoten Dokumente tun Sie es so: curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - sudo apt-get install -y nodejs –

Antwort

6

ich dieses Textbuch wurde mit für den Knoten 6.1.0 über NVM (Knoten Version Manager) installieren:

Hinweis: Möglicherweise müssen Sie die Hosts und die Verbindung im Spiel ändern.

--- 
- 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 }} 

Weitere Informationen zu NVM finden Sie unter: https://github.com/creationix/nvm

2

Basierend auf dem Code in der ursprünglichen Frage, und die helpful comment from @ydaetskcoR konnte ich NodeJS 6.x mit dem folgenden auf Ubuntu 16.04 installieren:

Ich habe ein wenig kurz umgestaltet, aber das Wichtigste ist das Hinzufügen von _6.x zu den Repository-URLs.

Dieser arbeitete für mich mit ansible 2.3.2.0

Verwandte Themen