nodesource / ansible-nodejs-role

Ansible Role for Node.js Binary Install
MIT License
131 stars 47 forks source link

Allow installation of NPM packages #1

Open iamcarrico opened 9 years ago

iamcarrico commented 9 years ago

Howdy!

I was looking for an ansible way to install node, and since most of them go though the old PPA-- this was the only one that does it the new way.

Anyway--- I made a few minor changes, a couple yml syntax changes (couldn't run it without those changes). And then created a way to install npm packages as well. I don't know of a way to use items only if a variable exists, so instead I made one with a dummy package name. Ansible will then install everything except that package (if the user doesn't override).

Also... it isn't up on Ansible galaxy yet. I am guessing that is because this is ... 7 days old? Either way, can you push it? :+1:

Thanks mate!

wolfeidau commented 9 years ago

Hey sorry for the delay in reviewing this, we haven't published this yet as I am waiting for @rvagg to get back from holidays. Plan on testing this more thoroughly once he gets back, hence the stall.

Is there a reason you have used a place holder entry in the array of global modules? Could you just declare an empty array as the default?

Cheers

iamcarrico commented 9 years ago

Only reason: I didn't know how to off hand and was working on a bunch of other tasks to setup my server. But I will change that quickly.

thlorenz commented 9 years ago

Fwiw, installing npm modules doesn't belong in this role IMO. This role is to install node and that's a clear concern and it should stay that way.

Couldn't we create an npm role or maybe even a module similar to apt to achieve that without muddling the concern of the node role?

iamcarrico commented 9 years ago

@thlorenz I see the point of having the two separate, but I also think they are linked for many people's deployment. As it is such a simple piece, I don't see the need for separating them out.

thlorenz commented 9 years ago

As it is such a simple piece, I don't see the need for separating them out

Everything starts out as a very simple piece, but most grow more complex afterwards. However once it is included with this role it can never be removed without breaking backwards compat.

Therefore I maintain it'd be a better idea to have it separate. I mean how hard is it to add the line xxxxx.npm to your - roles?

iamcarrico commented 9 years ago

Good point.

Well, do you want to pull this out and put it into its own repo / ansible-galaxy? I think it would make sense to have it be within the nodesource org, for consistency?

thlorenz commented 9 years ago

@iamcarrico nice idea, lets see what the others think about that.

/cc @wolfeidau @chrislea @rvagg @joemccann

chrislea commented 9 years ago

Well just putting in my $0.02 here... I went through this sort of thing making Debian / Ubuntu packages a ways back. I used to make separate packages for node, node devel (header files and stuff), and npm. I then stopped doing that and started making a single package that had everything at the request of Joyent.

The reasoning was that these days, you're not really using node correctly if you're not using npm, and you can't use npm without the development files. So while I understand that having separate roles is sort of the "pure" thing to do, if we're following the same logic we'd just have a single role that installed everything.

rvagg commented 9 years ago

What's the use-case here? The only sensible one I can see for an Ansible role is to install global packages as commands, like npm install st -g, tho I'm not sure how common this kind of use is for real deployments.

iamcarrico commented 9 years ago

Not all ansible scripts are for deployment servers--- I use this for a local vagrant box. I would like to install some global packages for me always to use (e.g. gulp and yeoman)

rvagg commented 9 years ago

ah yes, gulp, yeoman, grunt, those are all pretty popular globals, ok, +1 from me, we should make a separate role for this

wolfeidau commented 9 years ago

Yep +1 for separate role, and great to see some good discussion on this, I love open source.

We also install node-gyp via Ansible at the moment albeit in our CI role (which is of course way to big).

iamcarrico commented 9 years ago

:+1: Open source. Let me know if I can help y'all on this one.

rvagg commented 9 years ago

@wolfeidau we're doing that in our docker images: https://github.com/nodesource/docker-node/blob/master/Dockerfile#L16-L17 tho it's mainly so that we prime the images with the stuff downloaded to .node-gyp so you don't have to wait if you run any builds as root.

wolfeidau commented 9 years ago

O that is a damn good idea, mite be worth optionally doing the same thing in this role.

Tricks like that make stuff like this invaluable.

conorgil commented 8 years ago

We are currently using this to install packages via npm: http://docs.ansible.com/ansible/npm_module.html. Does this satisfy the use-case discussed in this thread about installing npm packages separately?

iamcarrico commented 8 years ago

@conorgil this code is just a wrapper around that.