我正在尝试使用 puppet 将所有用户添加到系统并将他们全部添加到单个组中。但是,我不断收到
Error 400 on SERVER: Duplicate declaration: Group[users] is already declared
in file *filename*:17 cannot redeclare at *filename* on node *server*
如果我将用户更改为变量名(如 $title),则一切正常。如何使用静态组名(如“用户”)执行此操作?我使用以下配置:
笔记:下面我可能打错了。由于我所在的系统无法访问互联网,我不得不重新输入所有内容。
define users::virtual ($uid, $realname, $password) {
user { $title:
ensure => 'present',
uid => $uid,
gid => $'users',
shell => '/bin/bash',
home => "/home/${title}",
comment => $realname,
password => $password,
managehome => true,
require => Group ['users'],
}
group { 'users':
ensure => 'present',
gid => 100,
}
file { "/home/${title}":
ensure => directory,
owner => $title,
group => 'users',
mode => 0700,
require => [ User[$title], Group['users'] ],
}
}
class users {
@users::virtual { 'user1':
uid => 510,
realname = 'John Doe',
password = cyphertext
}
@users::virtual { 'user2':
uid => 511,
realname = 'Jane Doe',
password = cyphertext
}
}
node 'server' {
realize (Users::Virtual['user1']
realize (Users::Virtual['user2']
}
答案1
Group['users'] 资源不应位于定义的资源内 users::virtual
。您只能创建一次该组。将其移出到单独的类中。
group { 'users':
ensure => 'present',
gid => 100,
}