Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

1 Answer 1

up vote 1 down vote accepted
$username = $forename[0].chr.downcase+name.downcase $email
$forename.downcase+'.'+$name.downcase+'@localnet.lan'

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

Have a look at http://docs.puppetlabs.com/references/stable/function.html to see what you can do with strings directly in Puppet (not much). Then have a look at http://docs.puppetlabs.com/guides/templating.html 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
add comment

Your Answer

 
discard

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.