Puppet roles/profiles,具有多个配置文件实例的角色 - 参数如何工作?
Puppet roles/profiles, role with multiple instances of profile - how do parameters work?
我正在学习 Puppet(我们在本地有 Puppet Enterprise)。我试图理解“roles and profiles”模式。请原谅任何命名错误。
如何创建具有多个配置文件实例的角色,其中配置文件实例仅参数不同?我猜 Hiera 在某个地方适合这个,但我不确定如何。
例如:
人偶文件:
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
}
我希望 twoapaches 角色的实例在端口 90 和 100 上有一个 apache - 我该怎么做?
实际上您不能在 Puppet 中使用 class 这样的东西; a class 每个节点只能声明一次。
您可能需要一些 defined types in the puppetlabs/apache 模块。当您需要在单个节点上多次声明用户定义的 "resource" 时,使用定义的类型。
例如个人资料可能是:
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 (ref) 结合使用。
我也会使用 Hiera 作为参数。这样您就可以根据需要轻松更改端口,并且遵守不放置 classes inside the roles:
的规则
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'
我正在学习 Puppet(我们在本地有 Puppet Enterprise)。我试图理解“roles and profiles”模式。请原谅任何命名错误。
如何创建具有多个配置文件实例的角色,其中配置文件实例仅参数不同?我猜 Hiera 在某个地方适合这个,但我不确定如何。
例如:
人偶文件:
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
}
我希望 twoapaches 角色的实例在端口 90 和 100 上有一个 apache - 我该怎么做?
实际上您不能在 Puppet 中使用 class 这样的东西; a class 每个节点只能声明一次。
您可能需要一些 defined types in the puppetlabs/apache 模块。当您需要在单个节点上多次声明用户定义的 "resource" 时,使用定义的类型。
例如个人资料可能是:
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 (ref) 结合使用。
我也会使用 Hiera 作为参数。这样您就可以根据需要轻松更改端口,并且遵守不放置 classes inside the roles:
的规则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'