install a specific version of nodejs
---
- name: nodejs install block
block:
- name: Check for nodejs
stat:
path: "{{ node_path }}/node"
register: node_check
- name: Install nodejs
unarchive:
src: "https://nodejs.org/dist/v{{ node_version }}/node-v{{ node_version }}-linux-x64.tar.xz"
dest: "{{ node_install_location }}"
remote_src: yes
owner: root
group: root
when: node_check.stat.exists == false
- name: Install NPM modules (global)
npm:
name: "{{ item }}"
global: yes
state: present
with_items:
- knex-migrator
- ghost-cli
- name: Adding node_path to PATH
template:
src: nodejs.sh.j2
dest: /etc/profile.d/nodejs.sh
owner: root
group: root
mode: 0644
- name: Adjusting secure_path in sudoers
lineinfile:
path: /etc/sudoers
owner: root
group: root
mode: 0440
state: present
regexp: 'secure_path'
line: 'Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:{{ node_path }}"'
when: inventory_dir | basename in ['dev', 'packer']
environment:
PATH: "{{ ansible_env.PATH }}:{{ node_path }}"
PATH=${PATH}:{{ node_path }}
---
node_version: "8.9.4"
node_install_location: /usr/local
node_path: "{{ node_install_location }}/node-v{{ node_version }}-linux-x64/bin"