如何收集标记的导出资源?

如何收集标记的导出资源?

haproxy::balancermember为我的应用服务器导出资源:

class www_admin($datacenter){
  @@haproxy::balancermember{"${hostname}-www-admin:9193":
    listening_service => 'www-admin',
    server_names      => "${hostname}:9193",
    ipaddresses       => $ipaddress,
    ports             => 9193,
    options           => "check inter 65761 fastinter 1751 downinter 5761 weight ${weight}",
    tag               => $datacenter,
  }
}

我有两个数据中心:dc:enovancedc:staging。在生产环境 (dc:enovance) 中,我使用 haproxy,而在准备阶段,我还没有使用。我已验证当mike(准备服务器)导出资源时,$datacenter是否正确设置为dc:staging

$ hiera --debug www_admin::datacenter ::fqdn=mike.cvib.es ::hostname=mike ::domain=cvib.es
DEBUG: Tue Dec 03 20:59:29 +0000 2013: Hiera JSON backend starting
DEBUG: Tue Dec 03 20:59:29 +0000 2013: Looking up www_admin::datacenter in JSON backend
DEBUG: Tue Dec 03 20:59:29 +0000 2013: Looking for data source node/mike.cvib.es
DEBUG: Tue Dec 03 20:59:29 +0000 2013: Looking for data source node/mike
DEBUG: Tue Dec 03 20:59:29 +0000 2013: Cannot find datafile /etc/puppet/hiera/node/mike.json, skipping
DEBUG: Tue Dec 03 20:59:29 +0000 2013: Looking for data source cvib.es
dc:staging

在生产 haproxy 节点上,我收集导出的资源如下:

node proxy {
  # ...
  Haproxy::Balancermember <<| tag == 'dc:enovance' |>>
}

不幸的是,生产仍然想将mike添加到生产haproxy中:

# puppet agent -t --noop
Info: Retrieving plugin
Info: Loading facts in /etc/puppet/modules/puppetlabs-stdlib/lib/facter/facter_dot_d.rb
Info: Loading facts in /etc/puppet/modules/puppetlabs-stdlib/lib/facter/root_home.rb
Info: Loading facts in /var/lib/puppet/lib/facter/facter_dot_d.rb
Info: Loading facts in /var/lib/puppet/lib/facter/concat_basedir.rb
Info: Loading facts in /var/lib/puppet/lib/facter/sshpubkey.rb
Info: Loading facts in /var/lib/puppet/lib/facter/root_home.rb
Info: Caching catalog for proxy100.novalocal
Info: Applying configuration version '1386103029'
Notice: /Stage[main]/Haproxy/Concat[/etc/haproxy/haproxy.cfg]/File[/etc/haproxy/haproxy.cfg]/content:
--- /etc/haproxy/haproxy.cfg    2013-12-03 16:22:35.279592067 +0000
+++ /tmp/puppet-file20131203-5679-1qu03nj       2013-12-03 20:37:54.946867039 +0000
@@ -173,6 +173,9 @@
  timeout  server 10m
  timeout  client 10m
  timeout  http-request 10m
+  server mike:9193 142.4.219.180:9193 check inter 65761 fastinter 1751 downinter 5761 weight 100
+
+  server mike:9194 142.4.219.180:9194 check inter 65761 fastinter 1751 downinter 5761 weight 100

  server worker111:9193 10.43.0.22:9193 check inter 65761 fastinter 1751 downinter 5761 weight 100


Notice: /Stage[main]/Haproxy/Concat[/etc/haproxy/haproxy.cfg]/File[/etc/haproxy/haproxy.cfg]/content: current_value {md5}2b0fe2a09bdac5a12a6c7eaffd1cc35e, should be {md5}a72cef384a71c120d03af14bd33d29d0 (noop)
Notice: Concat[/etc/haproxy/haproxy.cfg]: Would have triggered 'refresh' from 1 events
Info: Concat[/etc/haproxy/haproxy.cfg]: Scheduling refresh of Service[haproxy]
Notice: /Stage[main]/Haproxy/Service[haproxy]: Would have triggered 'refresh' from 1 events
Notice: Class[Haproxy]: Would have triggered 'refresh' from 2 events
Notice: Stage[main]: Would have triggered 'refresh' from 2 events
Notice: Finished catalog run in 11.22 seconds

# puppet --version
3.3.2

我怀疑我犯了一个基本的错误。文档位于http://docs.puppetlabs.com/puppet/latest/reference/lang_exported.html指出我应该简单地使用相等运算符来查找标记的资源(查找带有 bacula 的示例)。使用puppet node exports(来自http://forge.puppetlabs.com/zack/exports),我可以看到 Mike 确实导出了dc:staging

---
  - parameters:
      ports: "9194"
      ipaddresses: "142.4.219.180"
      server_names: "mike:9194"
      tag: "dc:staging"
      options: "check inter 65761 fastinter 1751 downinter 5761 weight 100"
      listening_service: www-admin
    line: 57
    file: /etc/puppet/modules/company/manifests/www_admin.pp
    exported: true
    tags:
      - "dc:staging"
      - "haproxy::balancermember"
      - www_admin
      - "mike-www-admin:9194"
      - balancermember
      - haproxy
      - class
    title: "mike-www-admin:9194"
    type: "Haproxy::Balancermember"
    resource: c19ef1cbb789f41f2f83c02ebfb31b6e6fea17f6
    certname: mike.cvib.es
  - parameters:
      ports: "9193"
      ipaddresses: "142.4.219.180"
      server_names: "mike:9193"
      tag: "dc:staging"
      options: "check inter 65761 fastinter 1751 downinter 5761 weight 100"
      listening_service: www-admin
    line: 48
    file: /etc/puppet/modules/company/manifests/www_admin.pp
    exported: true
    tags:
      - "dc:staging"
      - "haproxy::balancermember"
      - www_admin
      - "mike-www-admin:9193"
      - balancermember
      - haproxy
      - class
    title: "mike-www-admin:9193"
    type: "Haproxy::Balancermember"
    resource: f6d8c6f60a52cc2cd160f20ac5998ef07560c61f
    certname: mike.cvib.es

我怎样才能仅包含dc:enovance生产中的资源,而忽略导出的dc:staging资源?

答案1

的文档haproxy::listen包含对参数的引用collect_exported。在 的代码中haproxy::listenHaproxy::Balancermember收集了 。由于我也在收集资源,所以我无论如何都在收集 Mike 的资源。

第二个问题发生是因为我没有导出ensure => false资源,而 concat 模块只是让文件保持活动状态。当我清除 concat 的资源缓存时/etc/haproxy/haproxy.cfg,问题就消失了。

相关内容