Skip to content

Commit

Permalink
Add nodejs and npm to path via alternatives modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtpereira committed May 19, 2015
1 parent fe78bcc commit 4ade38f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq python-apt python-pycurl
install:
- pip install ansible==1.5.0
- pip install ansible==1.6.9
script:
- echo localhost > inventory
- ansible-playbook -i inventory -e nodejs_install_method=binary test.yml --syntax-check
Expand Down
1 change: 1 addition & 0 deletions tasks/source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
force: yes

- include: update_path.yml

33 changes: 19 additions & 14 deletions tasks/update_path.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
# file: nodejs/tasks/update_path.yml

- name: node.js | update_path | Add the node.js binary to the system path
lineinfile: "dest={{item.dest}} regexp={{item.regexp}} line={{item.line}} state={{item.state}}"
with_items:
- { dest: "/etc/profile", regexp: "^NODE_HOME=/usr/local/nodejs/default", line: "NODE_HOME=/usr/local/nodejs/default", state: "present" }
- { dest: "/etc/profile", regexp: "^PATH=.*NODE_HOME.*", line: "PATH=$PATH:$NODE_HOME/bin", state: "present" }
- name: node.js | Add the node installation path to the system path
lineinfile:
dest: /etc/profile
regexp: '^NODE_HOME={{ nodejs_directory }}/default'
line: 'NODE_HOME={{ nodejs_directory }}/default'
state: present

- name: node.js | update_path | Inform the system where node is located and set this one as the default
shell: "{{item}}"
with_items:
- 'update-alternatives --install "/usr/bin/node" "node" "/usr/local/nodejs/default/bin/node" 1'
- 'update-alternatives --set node /usr/local/nodejs/default/bin/node'
- name: mode.js | Add the node binary path to the system path
lineinfile:
dest: /etc/profile
regexp: '^PATH=.*NODE_HOME.*'
line: 'PATH=$PATH:$NODE_HOME/bin'
state: present

- name: node.js | update_path | Inform the system where npm is located and set this one as the default
shell: "{{item}}"
- name: node.js | Inform the system where the binaries are located and set as the default
alternatives:
name: "{{ item }}"
path: "{{ nodejs_directory }}/default/bin/{{ item }}"
link: "/usr/bin/{{ item }}"
with_items:
- 'update-alternatives --install "/usr/bin/npm" "npm" "/usr/local/nodejs/default/bin/npm" 1'
- 'update-alternatives --set npm /usr/local/nodejs/default/bin/npm'
- node
- npm

0 comments on commit 4ade38f

Please sign in to comment.