我有这个class,运行时应该让用户改变他们的密码。 然而,当我用puppet agent --test
运行它 – testing时,它会在第9行给出一个语法错误,在那里它设置密码,但我不知道那一行有什么问题。 这是我到目前为止的代码。 “$ 6”是因为它是SHA-512散列,而MD5是$ 1,这是默认值。
class pwdchange ($newpwd = '', $targetuser = $::id) { $hash = inline_template("<% require 'digest' Digest::SHA1.hexdigest(newpwd) %>") $encryptedpwd = '$6'+template($hash) user {"$targetuser": ensure => present password => $encryptedpwd } }
谁能告诉我我做错了什么?
您需要在资源定义中以逗号结束行,还build议引用variables:
class pwdchange ($newpwd = '', $targetuser = $::id) { $hash = inline_template("<% require 'digest' Digest::SHA1.hexdigest(newpwd) %>") $encryptedpwd = '$6'+template($hash) user {"$targetuser": ensure => present, password => "$encryptedpwd", } }
当您已经使用inline_template
,不需要template
function。 此外,使用反斜杠来转义美元符号。
$hash = inline_template(...) $encryptedpwd = "\$6${hash}" user {$targetuser: ensure => present, password => $encryptedpwd, }
构build复杂string的另一种可能性是将前缀放在不同的variables中。 使用单引号将美元唱歌保留为文字字符:
$hash = inline_template(...) $prefix = '$6' $encryptedpwd = "${prefix}${hash}"