gathering instances of another type in a type.

28 views
Skip to first unread message

Steve Neuharth

unread,
Dec 3, 2014, 11:48:39 AM12/3/14
to puppe...@googlegroups.com
I'm writing a module to configure Oracle Weblogic (against my will).

I've created a type to handle the configuration of the config.xml file for the domain. In puppet, you'd use it like this:

  weblogic_domain{ $name:
    admin_server => $admin_server,
    domains_dir  => $domains_dir,
    require      => Exec["creating admin server for ${domain}"]
  }

so that's great... If i change my $admin_server, then my type changes admin_server in config.xml.

I'm having a bit of trouble, however, with the next part. A 'domain' in weblogic contains 'servers'... basically a hostname and port. I *could* do this:

  weblogic_domain{ $name:
    admin_server => $admin_server,
    domains_dir  => $domains_dir,
    servers          => $hash_of_servers_and_ports
    require      => Exec["creating admin server for ${domain}"]
  }

but what I'd really like to do is on each server, declare something like this:

  @weblogic_server{ $name:
    domain => myDomain
    port => 8000
  }

and then have my type gather up all the virtual resources and drop them into the server.xml automagically.

SO... how do I access the instances of one type from a different type? Can it be done? I've read the O'Reilly book on Types/Providers, skimmed a couple other books and scoured github for an example of this but I've come up with nothing.

please sir, a tuppence for a clue
--steev

Richard Clamp

unread,
Dec 3, 2014, 12:15:23 PM12/3/14
to puppe...@googlegroups.com
This is pretty much exactly what datacat_collector does with its
datacat_fragment resources, so I think you'll find your answer if you
look at its code (or simply rework your stuff in terms of that)

https://forge.puppetlabs.com/richardc/datacat
https://github.com/richardc/puppet-datacat


--
Richard Clamp <rich...@unixbeard.net>

Steve Neuharth

unread,
Dec 3, 2014, 12:44:17 PM12/3/14
to puppe...@googlegroups.com

fragments = resource.catalog.resources.find_all do |r|
r.is_a?(Puppet::Type.type(:datacat_fragment)) && ((our_names & [ r[:target] ].flatten).size > 0)
end

that's the nugget I was looking for. I think that should work very nicely.

Thank you very much,
--steve

Leonardo Rodrigues de Mello

unread,
Dec 3, 2014, 7:21:30 PM12/3/14
to puppe...@googlegroups.com

Could you share the module on github ?

Thanks

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/b21868fe-0262-4161-9a45-aaa29370f092%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages