0
votes

I want to provision multiple sets of things on a server using existing puppet modules the simplest example would be:

file { "/var/www/MYVARIABLEHERE":
    ensure => "directory",
}
mysql::db { MYVARIABLEHERE:
    user     => MYVARIABLEHERE,
    password => MYVARIABLEHERE,
    host     => 'localhost',
    grant    => ['all'],
}

Is there a way to abstract this out so that I can have say an array of pre defined options and then pass them into existing puppet modules so I don't end up with a manifest file that's thousands of lines long?

As per the answer below I have setup:

define mySites {
  mysql::db { $name:
    user     => $name,
    password => $name,
    host     => 'localhost',
    grant    => ['all'],
  }

  file { "/var/www/${name}.drupal.dev":
    ensure => "directory",
  }
}

I then call:

mySites {"site": $name => "test", }

and get the following error:

Could not parse for environment production: Syntax error at 'name'; expected '}'
1
Remove the $ in front of $name... I would still suggest a different name for the variable not name.... - iamauser

1 Answers

1
votes

You could use a define type to simplify as much :

define mydef( $usern, $passn) {
  file { "/var/www/$usern":
     ensure => "directory",
  }
  mysql::db { $usern :
      user => $usern,
      password => $passn,
      host => "localhost",
      grant => ['all'],
  }
}

# You have to call the define type for each cases.
mydef{"u1": usern => "john", password => "pass", }

# It might be possible to provide multiple arrays to a define
# type if you use puppet's future parser