0

我正在尝试将此模块与 puppet 一起使用:https ://github.com/duritong/puppet-shorewall

按照这个例子,我得到了规则的工作

node xy {
    class{'config::site_shorewall':
      startup => "0"  # create shorewall ruleset but don't startup
  }
    shorewall::rule {
        'incoming-ssh': source => 'all', destination => '$FW',  action  => 'SSH(ACCEPT)', order => 200;
        'incoming-puppetmaster': source => 'all', destination => '$FW',  action  => 'Puppetmaster(ACCEPT)', order => 300;
        'incoming-imap': source => 'all', destination => '$FW',  action  => 'IMAP(ACCEPT)', order => 300;
        'incoming-smtp': source => 'all', destination => '$FW',  action  => 'SMTP(ACCEPT)', order => 300;
    }
}

现在我想把它打包到hiera中。通过一些研究,我在这里找到了如何将不同变量转换为 hiera 哈希的解释:http: //puppetlunch.com/puppet/hiera.html

现在,当原始示例转换为 hiera 时,如果我没记错的话,它应该看起来像这样(hiera 中只有 2 个示例):

---                                                                                                                    
classes:
  - shorewall

shorewall::rule:
    incoming-ssh:
        source:   'all'
        destination: '$FW'
        action:   'SSH(ACCEPT)'
        order:    '200'
    incoming-puppetmaster:
        source:     'all'
        destination:    '$FW'
        action:     'Puppetmaster(ACCEPT)'
        order:      200

配置文件中除了页眉和页脚之外没有数据可能是什么问题?

猫 /etc/shorewall/puppet/rules

#
# Shorewall version 3.4 - Rules File
#
# For information on the settings in this file, type "man shorewall-rules"
#
# See http://shorewall.net/Documentation.htm#Rules for additional information.
#
#############################################################################################################
#ACTION SOURCE          DEST            PROTO   DEST    SOURCE          ORIGINAL        RATE            USER/   MARK
#                                               PORT    PORT(S)         DEST            LIMIT           GROUP
#LAST LINE -- ADD YOUR ENTRIES BEFORE THIS ONE -- DO NOT REMOVE
4

1 回答 1

2

在 Hiera 中对资源进行建模只是成功的一半。您必须指示 Puppet 将此数据转换回实际资源。

$data = hiera('shorewall::rule', {})
create_resources('shorewall::rule', $data)

关键是create_resources 函数

您不应将shorewall::rule其用作 Hiera 密钥的名称,这会产生误导。使用与实际语法不相似的名称,例如

shorewall_rules:
    incoming-ssh:
       ...

在清单中

$data = hiera('shorewall_rules', {})
于 2015-02-25T16:13:02.763 回答