我只是在学习木偶(我们在本地有puppet企业)。我试图理解" 角色和配置文件"模式。请原谅任何命名法的滑倒。
如何在配置文件的多个实例中创建角色,在该轮廓的多个实例中,该配置文件实例仅因参数而不同?我猜hiera适合在某个地方,但我不确定如何。
例如:
puppetfile:
mod 'puppetlabs-apache', '2.3.0'
apache.pp profile
class profile::apache (
String $port = '80',
) {
class { 'apache':
listen => $port,
}
}
tribtapaches.pp角色
class role::twoapaches {
include profile::apache
include profile::apache
}
我想要一个triwapaches角色的实例在端口90和100处具有Apache - 我该怎么做?
您实际上无法在puppet中使用类似类。一个只能声明每节点一次。
您可能需要PuppetLabs/Apache模块中的一些定义类型。当您需要在一个节点上多次声明用户定义的"资源"时,使用定义的类型。
例如。个人资料可能是:
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(参考)。
我也将使用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'