Ask Your Question

Why would one use "resource collectors"?

asked 2016-08-30 23:18:37 -0500

Red Cricket gravatar image

updated 2016-08-30 23:32:49 -0500

I was looking at the OpenStack modules on Puppet Forge. These modules make use of "resource collectors" so I was reading up on "resource collectors" here:

I still cannot figure out why one would need to use a resource collector?

Here's a example where the OpenStack/puppet-keystone module uses a resource collector:

if !is_service_default($memcache_servers) or !is_service_default($cache_memcache_servers) {
    Service<| title == 'memcached' |> -> Anchor['keystone::service::begin']

I guess this would do resource ordering; causing the memcached service resource to execute before the keystone::service::begin Anchor. I don't really know what an Anchor is. I am guessing its used for resource ordering???

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-08-31 04:15:22 -0500

lupin gravatar image

updated 2016-09-01 03:38:14 -0500

It was explain here with use-cases.

Here's an example(use case) that hopefully can help to explain.

Result without collector

[root@ha-centos7 modules]# puppet apply module2/tests/init.pp 
Notice: Compiled catalog for ha-centos7.home in environment production in 0.23 seconds
Notice: Finished catalog run in 0.02 seconds

Result with collector/realize

[root@ha-centos7 modules]# puppet apply module1/tests/init.pp Notice: Compiled catalog for ha-centos7.home in environment production in 0.22 seconds Notice: /Stage[main]/Module0/User[yoda]/ensure: created Notice: Finished catalog run in 0.05 seconds

[root@ha-centos7 modules]# cat module0/manifests/init.pp 
class module0 {
  @user {'yoda': 
    ensure => 'present',
    name => 'yoda',
    uid  => '1500',
[root@ha-centos7 modules]# cat module1/manifests/init.pp 
class module1 {
 include ::module0
 User <|  |>
[root@ha-centos7 modules]# cat module2/manifests/init.pp 
class module2 {
  include ::module0

Above we have three sample modules. Module0(declares a virtual resource) both module1 and module2 both include module0. module1 does extra by collecting/realising the virtual resource and thus user(yoda) got created. You can collect virtual resource from any module/module without getting into error of duplicate resource declaration.

In Openstack code in your post, the memcache service got restarted (collected/realise) before the keystore stuff begin. The memcache in that case was declared virtually by some other module.

Hth, Lupin

edit flag offensive delete link more


Ah I see thanks for the update!

Red Cricket gravatar imageRed Cricket ( 2016-09-01 02:23:16 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2016-08-30 23:18:37 -0500

Seen: 121 times

Last updated: Sep 01 '16