/ linx

Using Ansible to Set Up Node

Whew! This is the last installment (for now?) of my ansible development setup journey. I'm going to install nvm for managing and installing versions of node.js.

This follows in a series of Ansible for Development Environment articles:

Here is the content of my ~/ansible-develop/node.yml:

- name: Set Up Node
  hosts: localhost
  become_user: "{{ username }}"
    - name: ensure the ~/src-hub directory is present
      file: path=/home/{{ username }}/src-hub

    - name: clone nvm
      git: repo=https://github.com/creationix/nvm.git
           dest=/home/{{ username }}/src-hub/nvm

    - name: create symlink to nvm
      file: path=/home/{{ username }}/.nvm
            src=/home/{{ username }}/src-hub/nvm

    - name: set NVM_DIR in .zshrc
      lineinfile: dest=/home/{{ username}}/.zshrc
                  regexp='export NVM_DIR'
                  line='export NVM_DIR="$HOME/.nvm"'

    - name: source nvm in .zshrc
      lineinfile: dest=/home/{{ username }}/.zshrc
                  line='[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"'

Assuming that worked, you can either log out / log in or just source your zshrc file to make nvm available for use:

source ~/.zshrc

Now with the power of nvm, install a node version or two:

nvm install node
nvm install --lts

Learn more about nvm usage here: https://github.com/creationix/nvm

Now we're ready to write some JavaScript!

Benjamin Rosas

Benjamin Rosas

I am a constantly curious programmer with a background in science. I enjoy open-source software, programming languages, web development and server administration, along with music, travel and snark.

Read More
Using Ansible to Set Up Node
Share this