木偶,设置依赖关系

我开始设置木偶。 我想设置一个依赖关系,在该类尝试安装或启动任何东西之前,必须安装邮件传输代理。 用puppet,标准方法似乎设置依赖似乎是require blah 。 我面临的挑战是我不在所有的系统上使用相同的MTA。 一些实际的邮件服务器系统我有一个完整的MTA(exim),但是我的系统绝大多数都安装了ssmtp。 我想要做的是设置一个需求,以便在处理foo类之前安装这些MTA中的任何一个。

这是一个configuration,有点演示我正在尝试做什么。

 node default { if $fqdn in ["mail1.example.org", "mail2.example.org", "mail3.example.org"] { include fullmta # mailhub, and so on } else { include ssmtp # really basic send-only mta. } include foo # class that requries an mta be installed } class foo { require MTA # FIXME, A valid mta is required. package { foo: ensure => present, } ... # also a service, and some files, and so on... } 

所以在我的foo类中,我如何要求可能的MTA类之一被处理?

如果将MTA逻辑拆分为一个单独的类,则可以在那里处理逻辑 – 而且您的资源可能要求MTA类强制执行依赖关系。

 node default { include mta include foo # class that requries an mta be installed } class mta { if $fqdn in ["mail1.example.org", "mail2.example.org", "mail3.example.org"] { include fullmta # mailhub, and so on } else { include ssmtp # really basic send-only mta. } } class foo { package { foo: ensure => present, require => Class['mta'], } ... # also a service, and some files, and so on... } 

使用别名。 像这样的东西:

 service { "ssmtp": ... alias => "MTA", } service { "fullmta": ... alias => "MTA", } class foo { package { foo: ensure => present, require => Service["mta"], ... } ... } 

您可以指定require依赖项作为数组,在这种情况下,Puppet将确保在继续之前满足所有的依赖关系。 在这种情况下,我通常会做如下的事情:

 node default { include mta include foo # class that requries an mta be installed } class mta { if $fqdn in ["mail1.example.org", "mail2.example.org", "mail3.example.org"] { package { "conflicting-package-A": ensure => present, } package { "conflicting-package-B": ensure => absent, } } else { package { "conflicting-package-A": ensure => absent, } package { "conflicting-package-B": ensure => present, } } } class foo { package { foo: ensure => present, require => [Package["conflicting-package-A", "conflicting-package-B"], } ... # also a service, and some files, and so on... } 

这样,你不仅要确保foo包明确地依赖于其他包,而且还要设置它,以便如果将来从mail*.example.org列表中删除了一个主机,那么“conflict-package -A“将自动replace为”冲突包-B“。