---

- block:

  # The new PPA for nodejs bundles node and npm into a single package.
  # We need to remove all the old packages to prevent dependency conflicts.
  - name: Remove legacy nodejs and npm
    apt:
      name:
        - "nodejs-legacy"
        - "npm"
      state: absent
    # We've been seeing occasional transient failures with apt.  Until we have a
    # proper solution, just try it again.
    # TOOL-2677
    register: result
    until: result is success
    retries: 2

  - name: Remove legacy nodejs repo
    apt_repository:
      repo: "deb https://deb.nodesource.com/node_6.x trusty main"
      state: absent

  - name: Install nodejs from s3 using apt
    http_deb:
      name: nodejs
      version: 6.10.0-1nodesource1~trusty1
      url: "{{ download_url }}"
      checksum: "sha256:{{ nodejs_sha }}"

  become: yes
