1

I am attempting to install node.js, npm and Grunt.js in an Ubuntu Trusty 64bit Vagrant environment and running into some issues. Here is my puppet manifest:

init.pp --
class grunt::install {

    exec { 'apt_update':
        command => 'apt-get update',
        path    => '/usr/bin'
    }

    package { [
      'curl',
      'python-software-properties',
      'ruby1.9.3'
    ]:
        ensure  => present,
        require => Exec['apt_update']
    }

    # Get node
    exec { 'add-node-repo':
        command => '/usr/bin/add-apt-repository ppa:chris-lea/node.js && /usr/bin/apt-get update',
        require => Package['python-software-properties']
    }
    package { 'nodejs':
        ensure  => latest,
        require => [Exec['apt_update'], Exec['add-node-repo']]
    }

    # Install npm
    exec { 'npm':
        command     => '/usr/bin/curl -L https://npmjs.org/install.sh | /bin/sh',
        require     => [Package['nodejs'], Package['curl']],
        environment => 'clean=yes'
    }

    # Create symlink to stop node-modules folder breaking
    exec { 'node-modules-symlink':
        command => '/bin/rm -rfv /usr/local/node_modules && /bin/rm -rfv /vagrant/node_modules && /bin/mkdir /usr/local/node_modules && /bin/ln -sf /usr/local/node_modules /vagrant/node_modules ',
    }

    # Copy Grunt config files over for the vagrant setup.
    file { '/vagrant/package.json':
        source  => 'puppet:///modules/grunt/package.json'
    }
    file { '/vagrant/Gruntfile.js':
        source  => 'puppet:///modules/grunt/Gruntfile.js'
    }

    # Finally install grunt
    exec { 'install-grunt':
        command => '/usr/bin/npm install -g grunt-cli',
        require => Exec['npm']
    }

    # Install grunt task runner in directory
    exec { 'install-grunt-task-runner':
        command => '/usr/bin/npm install grunt --save-dev',
        cwd     => '/vagrant/',
        require => Exec['install-grunt']
    }
    exec { 'install-project-dependencies':
        command => '/usr/bin/npm install --save-dev',
        require => [Exec['install-grunt-task-runner'], Exec['node-modules-symlink']],
        cwd     => '/vagrant/'
    }

}

...and here is the console error log I am getting:

Stderr from the command:

stdin: is not a tty

Error: /usr/bin/npm install grunt --save-dev returned 1 instead of one of [0]
Error: /Stage[main]/Grunt::Install/Exec[install-grunt-task-runner]/returns: change from notrun to 0 failed: /usr/bin/npm install grunt --save-dev returned 1 instead of one of [0]
Warning: /Stage[main]/Grunt::Install/Exec[install-project-dependencies]: Skipping because of failed dependencies

Thanks in advance for any help/suggestions! :D

kaffolder
  • 285
  • 1
  • 2
  • 7
  • You would get much better results using puppet modules for apt, nodejs etc. take a look at [puppet forge](https://forge.puppetlabs.com) Using exec is a bad idea, as you really need to take care of the idempotency on your own. – b13n1u Sep 27 '14 at 17:50
  • @b13n1u Thanks for the suggestion! Could you point me to any examples of what you mean? Appropriate modules on forge to accomplish the same thing I'm trying to do above? Tutorials? Etc? Still newer to Puppet, so I'm sure what I was trying to do above isn't entirely correct either. More of a bash guy myself & have worked server admin for a while. Wanting to transition more to using Puppet though, especially in my dev environments. Thanks again for the help! – kaffolder Sep 27 '14 at 18:06
  • I have added some info as an answer although it doesn't really answer your question. But there is not enough space available in the comment :) – b13n1u Sep 27 '14 at 19:30

1 Answers1

1

You would get much better results using puppet modules for apt, nodejs etc. take a look at puppet forge.
Using exec is a bad idea, as you really need to take care of the idempotency on your own.

For example instead of lines:

package { 'nodejs':
    ensure  => latest,
    require => [Exec['apt_update'], Exec['add-node-repo']]
}

# Install npm
exec { 'npm':
    command     => '/usr/bin/curl -L https://npmjs.org/install.sh | /bin/sh',
    require     => [Package['nodejs'], Package['curl']],
    environment => 'clean=yes'
}

you could just use:

include nodejs  

Check your Vagrant file and make sure you have setup the modules and manifests directory.
Then search the puppet forge for the modules, for example apt, nodejs, ruby etc.

Download them and install (unzip in the modules dir). Make sure to change the modules directory names.
For example from puppetlabs-apt to apt
Take a look at the modules overview and usage guide it will tell you how to use a module.

Also check out this tutorial about using vagrant with puppet.

If you want to learn more about puppet take a look at the learning VM and the docs.

b13n1u
  • 980
  • 9
  • 14