Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to use puppet as a unix users management.

Here is the class I created to add new users:

class unix_accounts( $username, $forename, $name, $email, $uid) {

user { $username:
    comment => '$forename $name',
    home    => '/home/$username',
    shell   => '/bin/bash',
    uid     => $uid,
    groups  => [$username, 'sudo'],

I would like, as basically email and username ca be deduced from $name and $forename, to define these variables in the unix_accounts class. I have tried this:

$username = $forename[0].chr.downcase+name.downcase
$email    = $forename.downcase+'.'+$name.downcase+'@localnet.lan'

But puppetd test on client side fails out at the first dot (.) with the following message:

Error 400 on server: Syntax error at '.'; expected '}' at ....

This has nothing to do with ruby, because I have tried before with irb, it seems to be related to puppet syntax only. Is it possible anyway to created these variables inside a class? How to do that?

Many thanks

share|improve this question
up vote 1 down vote accepted
$username = $forename[0].chr.downcase+name.downcase $email

What makes you think this will work? None of these are functions provided by the Puppet language.

Have a look at to see what you can do with strings directly in Puppet (not much). Then have a look at to see how to use ERB templates, which will solve your problem.

Also, and this is not your problem, but it is a problem: if you want your strings to interpolate variables then you have to use double quotes, like so:

user { $username:
    comment => "$forename $name",
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.