Puppet 傀儡角色/配置文件,具有多个配置文件实例的角色-参数如何工作?

Puppet 傀儡角色/配置文件,具有多个配置文件实例的角色-参数如何工作?,puppet,Puppet,我只是在学习木偶(我们在当地有木偶企业)。我试图理解“角色和配置文件”模式。请原谅任何命名错误 如何创建具有多个概要文件实例的角色,其中概要文件实例仅因参数不同而不同?我猜希拉在某个地方适合这个,但我不确定怎么做 例如: 木偶文件: apache.pp配置文件 twoapaches.pp角色 我希望twoapaches角色的一个实例在端口90和100上有一个apache—我该怎么做?实际上,在Puppet中不能使用这样的类;每个节点只能声明一次类 您可能需要模块中的一些功能。当您需要在单个节点上

我只是在学习木偶(我们在当地有木偶企业)。我试图理解“角色和配置文件”模式。请原谅任何命名错误

如何创建具有多个概要文件实例的角色,其中概要文件实例仅因参数不同而不同?我猜希拉在某个地方适合这个,但我不确定怎么做

例如:

木偶文件:

apache.pp配置文件

twoapaches.pp角色


我希望twoapaches角色的一个实例在端口90和100上有一个apache—我该怎么做?

实际上,在Puppet中不能使用这样的类;每个节点只能声明一次类

您可能需要模块中的一些功能。当您需要在单个节点上多次声明用户定义的“资源”时,将使用已定义的类型

例如,配置文件可能是:

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 {
  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用于参数。通过这种方式,您可以在需要时轻松更改端口,并遵守禁止放置的规则:

包含角色时的Hiera配置如下所示:

profile::two_vhosts::ip1_port: '80'
profile::two_vhosts::ip2_port: '8080'

我懂了。因此,如果我想将端口作为参数传递到“profile::two_vhost”中。我可以这样做吗?在我看来,这个角色的名字会有所不同,但大多数角色/个人资料都是观点和整体上非常好的演示。
class role::two_vhosts {
  include profile::two_vhosts
  include profile::other_stuff
  ...
}
profile::two_vhosts::ip1_port: '80'
profile::two_vhosts::ip2_port: '8080'