# file: nodejs/tasks/source.yml

- name: node.js | source | Make sure that the directory to hold the node.js binaries exists
  file:
    path: "{{nodejs_directory}}"
    state: directory
    recurse: yes
    mode: 0755

- name: node.js | source | Download the node.js source
  get_url:
    url: "{{nodejs_source_url}}"
    dest: "/tmp/node-v{{nodejs_version}}.tar.gz"

- name: node.js | source | Unpack the node.js source
  shell: tar -xvzf /tmp/node-v{{nodejs_version}}.tar.gz chdir=/tmp creates=/tmp/node-v{{nodejs_version}}

- name: node.js | source |Get the number of processors
  command: nproc
  register: cpu_count

- name: node.js | source | Build node.js from source
  shell: >
    cd /tmp/node-v{{nodejs_version}} &&
    ./configure --prefix={{nodejs_source_prefix}} &&
    make -j {{cpu_count.stdout}} &&
    sudo make install

- name: node.js | source | Update the symbolic link to the node.js install
  file:
    path: "{{nodejs_directory}}/default"
    src: "{{nodejs_source_prefix}}"
    state: link
    force: yes

- include: update_path.yml

# file: nodejs/tasks/source.yml

- name: node.js | source | Make sure that the directory to hold the node.js binaries exists
  file:
    path: "{{nodejs_directory}}"
    state: directory
    recurse: yes
    mode: 0755

- name: node.js | source | Download the node.js source
  get_url:
    url: "{{nodejs_source_url}}"
    dest: "/tmp/node-v{{nodejs_version}}.tar.gz"

- name: node.js | source | Unpack the node.js source
  unarchive:
    src: "/tmp/node-v{{nodejs_version}}.tar.gz"
    dest: "/tmp/node-v{{nodejs_version}}"

- name: node.js | source |Get the number of processors
  command: nproc
  register: cpu_count

- name: node.js | source | Build node.js from source
  shell: >
    cd /tmp/node-v{{nodejs_version}} &&
    ./configure --prefix={{nodejs_source_prefix}} &&
    make -j {{cpu_count.stdout}} &&
    sudo make install

- name: node.js | source | Update the symbolic link to the node.js install
  file:
    path: "{{nodejs_directory}}/default"
    src: "{{nodejs_source_prefix}}"
    state: link
    force: yes

- include: update_path.yml

Use unarchive module instead of tar when extracting node archive
Use unarchive module instead of tar when extracting node archive
