在puppet中的稍后点将用户添加到组
我在一个模块中有一个用户资源,它被几个不同的节点使用。现在我想把这个用户添加到一个组中,但只添加到一个特定的节点中。有什么好的解决办法吗 模块的外观如下所示:在puppet中的稍后点将用户添加到组,puppet,Puppet,我在一个模块中有一个用户资源,它被几个不同的节点使用。现在我想把这个用户添加到一个组中,但只添加到一个特定的节点中。有什么好的解决办法吗 模块的外观如下所示: class testmodule::basics { user { 'testuser': ensure => present, home => '/home/testuser', managehome => true, } } 节点清单: node 'testnod
class testmodule::basics {
user { 'testuser':
ensure => present,
home => '/home/testuser',
managehome => true,
}
}
节点清单:
node 'testnode' {
include testmodule::basics
# here I would like to add the user to a group
# something like this (obviously does not work because of duplicate resource)
user { 'testuser':
groups => 'testgroup',
membership => 'minimum',
}
}
您有几个备选方案,分为几个一般类别 类别1-使用外部数据传达用户应该拥有哪些辅助组。特定的数据可能是一个标志,指示用户是否应该在辅助组中,或者它可能是适当的辅助组的实际数组。然后,您可以通过直接调用
lookup()
或hiera()
函数(具体取决于您使用的Puppet版本)或通过为其创建类参数并使用自动数据绑定来获得它
例如:
modules/testmodule/manifests/basics.pp:
class testmodule::basics($secondary_groups = []) {
user { 'testuser':
ensure => present,
home => '/home/testuser',
managehome => true,
groups => $secondary_groups
}
}
---
testmodule::basics::secondary_groups:
- testgroup
class testmodule::basics::special inherits testmodule::basics {
User['testuser'] {
groups => 'testgroup'
}
}
数据/节点/special.my.com.yaml:
class testmodule::basics($secondary_groups = []) {
user { 'testuser':
ensure => present,
home => '/home/testuser',
managehome => true,
groups => $secondary_groups
}
}
---
testmodule::basics::secondary_groups:
- testgroup
class testmodule::basics::special inherits testmodule::basics {
User['testuser'] {
groups => 'testgroup'
}
}
类别2-设置一个类参数以接收区分数据,就像在类别1选项中一样,并通过外部节点分类器(ENC)而不是外部数据输入数据。但是,设置和启用ENC比将数据提供给单个类具有更广泛的含义,因此我不建议这样做,除非您已经在使用或计划使用ENC
类别3-在需要时执行资源参数覆盖。这可能几乎是对示例清单的一个小改动,不过最好将重写放在单独的类中,而不是直接在节点块中执行。在从testmodule::basics
继承的类中,可以使用资源参数重写语法,如下所示:
modules/testmodule/manifests/basics/special.pp:
class testmodule::basics($secondary_groups = []) {
user { 'testuser':
ensure => present,
home => '/home/testuser',
managehome => true,
groups => $secondary_groups
}
}
---
testmodule::basics::secondary_groups:
- testgroup
class testmodule::basics::special inherits testmodule::basics {
User['testuser'] {
groups => 'testgroup'
}
}
但是,如果要在节点块或不相关的类中执行此类重写,则需要通过收集器执行:
node 'testnode' {
include testmodule::basics
User<title == 'testuser'> {
groups => 'testgroup'
}
}
节点“testnode”{
包括testmodule::basics
使用者{
组=>'testgroup'
}
}
这两种类型的覆盖在使用范围之外有一些细微的差异,所以请阅读了解更多信息。以下是对我有效的方法:User{groups=>[“ubuntu”,“docker”]}
。