Changing user passwords with Puppet

passwordpuppetusers

I have this class that, when run, should let a user change their password. However, when I run it with puppet agent --test, it gives a syntax error at line 9, where it's setting the password, but I don't know what's wrong with that line. Here is the code I have so far. The "$6" is because it's SHA-512 hashed, as opposed to $1 for MD5, which is the default.

class pwdchange ($newpwd = '', $targetuser = $::id) {
   $hash  = inline_template("<%
     require 'digest'
     Digest::SHA1.hexdigest(newpwd)
   %>")
   $encryptedpwd = '$6'+template($hash)
   user {"$targetuser":
     ensure   => present
     password => $encryptedpwd
  }
}

Could anyone tell me what I'm doing wrong?

Best Answer

You need to terminate lines with commas in the resource definition, also quoting variables is recommended:

class pwdchange ($newpwd = '', $targetuser = $::id) {
   $hash  = inline_template("<%
     require 'digest'
     Digest::SHA1.hexdigest(newpwd)
   %>")
   $encryptedpwd = '$6'+template($hash)
   user {"$targetuser":
     ensure   => present,
     password => "$encryptedpwd",
  }
}
Related Topic