Skip to content

Instantly share code, notes, and snippets.

@cmndrsp0ck
Created January 14, 2018 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmndrsp0ck/0f396fd16859fc15d198e9ef373e709d to your computer and use it in GitHub Desktop.
Save cmndrsp0ck/0f396fd16859fc15d198e9ef373e709d to your computer and use it in GitHub Desktop.
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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment