Question

I'm trying to use Boxen to setup our dev environment. We have a number of repos that we want to pull down and run a script to get started. We landed on a convention: repos have a scripts/ directory with a bootstrap script that needs to be run.

It looks like this would be possible with the exec command. But in order to tell it what to run, I have to access the repo's directory. Other scripts use $repo_dir or ${boxen::config:srcdir}/${name}. I've tried each of these, and a number of different styles of exec, to no avail.

The Manifest

class projects::hero {

  include ruby

  boxen::project { 'hero':
    ruby          => '2.0.0',
    source        => 'myorg/hero'
  }
  ->
  Exec {
    command       => '$repo_dir/scripts/echo'
  }
  ->
  notify {'hero is running at $srcdir':}
}

This is simpler than the stated goal. The scripts need to be run within the directory they reside. So my first (and hopefully eventual) manifest would have something like this for the exec step:

->
exec { 'running bootstrap on hero':
  command         => '$repo_dir/scripts/bootstrap',
  cwd             => '$repo_dir/scripts'
}

The script

For right now, scripts/echo is super simple:

#!/bin/bash
echo "Echo File!"
touch `date`

Since the output isn't really going to be seen, we're making a file with the date so we can observe this side effect and know that the script actually ran.

Calling boxen

I just call this project directly from the manifests directory:

Chris:manifests chris$ boxen hero

The output

Warning: Scope(Class[Boxen::Environment]): Setting up 'hero'. This can be made permanent by having 'include projects::hero' in your personal manifest.
Error: Could not find resource 'command => $repo_dir/scripts/echo' for relationship from 'Boxen::Project[hero]' on node chris.local
Error: Could not find resource 'command => $repo_dir/scripts/echo' for relationship from 'Boxen::Project[hero]' on node chris.local

This is also true if I try ${boxen::config::srcdir} instead. Looking at other examples, these variables are used and seem to work. Am I calling it wrong? Is there a different variable I should be using?

Was it helpful?

Solution

I've noticed two mistakes in your manifest here:

->
Exec {
    command       => '$repo_dir/scripts/echo'
}
->

The first is that you've capitalized the first letter of exec. In puppet language this means you are specifying a default for all subsequent exec resource definitions (docs). This is not a resource definition itself, therefore resource ordering can not be applied, hence the error.

Another mistake is the use of single quotes in combination with variables. Single quoted strings are interpreted as literals. In other words, '$repo_dir' is interpreted literally as $repo_dir while "$repo_dir" is interpreted as the contents of the varialbe $repo_dir (docs).

Hope this helps,

Good luck

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top