如何使用 Puppet 中的 ERB 模板文件调整 ~/.ssh/config 文件中的“用户”行,使其包含与帐户名称匹配的正确用户名?
class accounts_global::tharold {
account { 'tharold':
ensure => present,
}
file { "/home/tharold/.ssh/config" :
require => Account['tharold'],
owner => 'tharold',
group => 'tharold',
mode => '0600',
content => template('accounts_global/user_ssh_config.erb'),
}
}
Run Code Online (Sandbox Code Playgroud)
user_ssh_config.erb 文件的内容如下所示:
Host ssh.example.com
Port 22
User tharold
IdentityFile ~/.ssh/ssh-key
Run Code Online (Sandbox Code Playgroud)
问题是,用用户的帐户名替换模板文件中的“User tharold”应该是什么样子的?这个 ERB 配置文件将被多个用户使用,所以我需要参数化文件的那部分。
尝试使用 <%= @name %> 最终将“accounts_global::tharold”放入文件中。