我只是在学习木偶(我们本地有木偶企业)。我试图理解“角色和配置文件”模式。请原谅任何术语上的错误。
如何使用配置文件的多个实例创建一个角色,其中配置文件实例仅通过参数不同?我猜希拉在什么地方能参与其中,但我不太清楚。
例如:
木偶档案:
mod 'puppetlabs-apache', '2.3.0'apache.pp配置文件
class profile::apache (
String $port = '80',
) {
class { 'apache':
listen => $port,
}
}twoapaches.pp角色
class role::twoapaches {
include profile::apache
include profile::apache
}我希望在端口90和100上有一个两个apache角色的实例--我如何做到这一点?
发布于 2017-11-24 08:55:10
实际上,不能在木偶中使用这样的类;类只能在每个节点声明一次。
您可能需要一些定义类型在化蛹实验室/阿帕奇模块中。当您需要在单个节点上多次声明用户定义的“资源”时,将使用定义的类型。
例如,简介可以是:
class profile::two_vhosts {
apache::vhost { 'ip1.example.com':
ip => ['127.0.0.1','169.254.1.1'],
port => '80',
docroot => '/var/www/ip',
}
apache::vhost { 'ip2.example.com':
ip => ['127.0.0.1'],
port => '8080',
docroot => '/var/www/ip',
}
} 其作用可能是:
class role::two_vhosts {
include profile::two_vhosts
include profile::other_stuff
...
}如果需要将端口传入其中,则可能有:
class profile::two_vhosts (
String $ip1_port,
String $ip2_port,
) {
apache::vhost { 'ip1.example.com':
ip => ['127.0.0.1','169.254.1.1'],
port => $ip1_port,
docroot => '/var/www/ip',
}
apache::vhost { 'ip2.example.com':
ip => ['127.0.0.1'],
port => $ip2_port,
docroot => '/var/www/ip',
}
} 这样,你就可以扮演以下角色:
class role::two_vhosts {
class { 'profile::two_vhosts':
ip1_port => '80',
ip2_port => '8080',
}
include profile::other_stuff
...
}但是在实践中,人们在这里结合Hiera (参考)使用自动参数查找功能。
发布于 2018-03-16 21:03:05
我也会用Hiera作为参数。通过这种方式,您可以在需要时轻松地更改端口,并且遵守不放置角色内部的类的规则。
class role::two_vhosts {
include profile::two_vhosts
include profile::other_stuff
...
}当包含角色时,Hiera配置如下所示:
profile::two_vhosts::ip1_port: '80'
profile::two_vhosts::ip2_port: '8080'https://stackoverflow.com/questions/47469073
复制相似问题