Giter VIP home page Giter VIP logo

ansible-nvm-node's Introduction

Build Status

Ansible NVM Node

Installs node via NVM on Debians and Redhats.

installation

either

  • ansible-galaxy install grzegorznowak.nvm_node
  • clone the repo directly

Dislaimer

It's a pretty bespoke installation of node that doesn't rely on any of apt/yum goodies nor it follows the recommended (@see nvm-sh/nvm#1533) way of using NVM. Additionally versioning is only achievable via Ansible itself. Please make sure the setup given here is the one you actually do require on your end. I would say it's 70% for DEV purposes and 30% for live. And 0% if you plan having many users/roles using it on a single server - it's not going to fly in the current state (though might work at some point with relatively minimal extra love added).

The crux is it installs nvm into a global path and symlinks it back to /usr/local/bin for general accessibility, and hijacks global bashrc to include the NVM's paths for each user on the system. Which although minor, breaks the concept of VNM being a per-user tool, as well as not working 100% flawlessly when specific non-interactive shells are used. This might affect usage of npm installed packages for those cases. However a cool cat as it is, nvm really is the tool of our choice so that's the way we need it and might be you need it too!

Requirements

No dependencies, just note it will install wget to fetch the nvm installation script.

Coverage

Currently builds and integrates on those distros:

Ubuntu: 20.04, 18.04, 16.04, 14.04
Debian: buster, stretch
CentOS: 7

Variables

defaults

    nvm_install_script_version: "0.33.11"   # the nvm installation script to use (latest stable version as of writing this)
    nvm_user_name: "root"                   # you can use a different user, and you might in the end achieve the more nvm-ish approach
                                            # but I've not covered that in tests etc.  
    nvm_dir: "/var/lib/nvm"                 # for global (default) installation. Follow the same rule as the nvm_user_name variable
    nvm_node_version: "8.11.3"              # the node version to install via nvm
    nvm_install_globally: []                # libraries to intall globally and symlink, look further down for details

Example playbook

when cloned from github
    ---
    - hosts: all
      vars:
        nvm_node_version: "4.1.1"
      roles:
        - role: ansible-nvm-node
when from ansible-galaxy
    ---
    - hosts: all
      vars:
        nvm_node_version: "your.node.version"
      roles:
        - role: grzegorznowak.nvm_node        

Upgrading node

Simply replace nvm_node_version with whatever version you want to be using globally and rerun the playbook

Installing global packages

For the best coherency you are strongly encouraged to install global packages using this role too, in which case just edit the nvm_install_globally variable, as follows:

nvm_install_globally: ['gulp']

also can use version targeting for global packages:

nvm_install_globally:
  - name: yarn
    version: 1.9.4

or mix both:

nvm_install_globally:
  - gulp
  - lighthouse
  - name: yarn
    version: 1.9.4

and that will install listed libraries and put a symlink to global $PATH for specific environments to access it (like cron)

Testing

Requirements

you may use a helper script that will install virtual env with all the needed stuff ./bootstrap_test.sh

the simply activate the virtualenv with source test_env/bin/activate

or just do it 100% manually for better control

sudo apt install virtualenv python3-pip
virtualenv test_env --python=python3
source test_env/bin/activate
pip install -r test-requirements.txt

Testing with lxc containers

molecule test

Additional perks from molecule

You can do all sort of super handy stuff like molecule converge to simply bring instance(s) at will and then tear them down with molecule destroy. The sky is the limit here really!

Sponsored by

Kwiziq.com - The AI language education platform

Spottmedia.com - Technology design, delivery and consulting

Author Information

brought to you with love from Grzegorz Nowak.

ansible-nvm-node's People

Contributors

alexindrez avatar etlam avatar ferblape avatar grzegorznowak avatar zoechi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ansible-nvm-node's Issues

Add check for binary to determine whether to execute script

- name: Execute the nvm installation script
command: "{{ nvm_dir }}/install_nvm_{{ nvm_node_version }}.script"
when: nvm_installation_script_template is defined and nvm_installation_script_template.changed
# the tag is needed so that linter wouldn't complain about this not being handler,
# and handlers are so unstable I eventually decided not to use them in this role
tags: skip_ansible_lint

I saw a case where the script was put in place but for some reason didn't run the install (maybe ctrl-c was the culprit during runtime) and then on 2nd run, it failed at the symlink task because it never ran the script.

Bash always opens in home directory

After installing this role every bash starts in your home directory.
Even if you click Open this folder in terminal in Nautilus it always jumps to the home directory.
I will provide a pull request ;-)

refusing to convert from file to symlink for /usr/bin/node

ubuntu 20.04

Problem:

TASK [grzegorznowak.nvm_node : Make the node binary always discoverable by symlinking to a system bin PATH that cron sees by default too] ***************************
fatal: [cpio]: FAILED! => {"changed": false, "gid": 0, "group": "root", "mode": "0755", "msg": "refusing to convert from file to symlink for /usr/bin/node", "owner": "root", "path": "/usr/bin/node", "size": 14416, "state": "file", "uid": 0}

Workaround, I did:

mv /usr/bin/node /usr/bin/system-node

What is a proper solution?

How does it work?

I installed ansible and did ansible-galaxy install grzegorznowak.nvm_node.
So how do I run nvm or node now?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.