title: ansible install node.js version 6
body: <p>For installing the node 6.x version these are the commands:</p>
  
  <pre><code>curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
  sudo apt-get install -y nodejs
  </code></pre>
  
  <p>now how exactly do I do that in ansible?
  any ideas here?</p>
  
  <p>this is what I had till now, but it installs the old version</p>
  
  <pre><code>---
  - 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}}"
  </code></pre>