On Sep 21, 7:35 pm, Robin Lee Powell <rlpow...@digitalkingdom.org>
wrote:
> On Tue, Aug 23, 2011 at 06:21:48AM -0700, jcbollinger wrote:
>
> > On Aug 22, 8:11 am, puppetlurker <under.my.cont...@gmail.com> wrote:
> > > Greetings,
>
> > > I'm having an issue with my implementation of exported resources. I
> > > have a memcache server pool, and want to update the /etc/php.d/
> > > memcache.ini with the ips of all the servers. Previously, I hard coded
> > > the $memcacheservers array in the node manifest and the template
> > > collected and populated the template.
>
> > > Now that I'm moving to exported resouces, how do I get it to set an
> > > array in a way I can access it from a different scope? I tried moving
> > > the file { "/etc/php.d/memcache.ini": content => template(memcache/
> > > memcache.ini.erb) to the resource function (I understand exported
> > > resources shoulld not define other resources), but it only populates
> > > the first server collected, and complains about a duplicate resource
> > > if I have more than 1 exported server.
>
> > > I've tried defining the resource without the content the first time,
> > > then override the define with the content, but that only picks up the
> > > 2nd server. I've tried accessing the variable that gets populated
> > > after the Memcache::Servers <<| |>> but it doesn't get populated in
> > > this scope. I've tried looking up the
> > > scope.lookupvar('memcached::servers::memcacheservers') but the
> > > exported resource is a define not a class and I couldn't get it to
> > > work. I've tried just using a script to populate the file with the
> > > proper contents, but there is no way to ensure it is filled with all
> > > the servers, for example the script is executed out of order,
> > > replaced 3 times if there are 3 servers, and may contain 1, 2, or 3
> > > servers after a puppet run.
>
> > > Any suggestions?
>
> > The way to do this with exported resources is for each node to export
> > a resource containing its own information only.  The trick is choosing
> > the resource to use for this.
>
> > The simplest case would be if "/etc/php.d/memcache.ini" supports some
> > kind of 'include' directive, especially if it understands globs.  Then
> > each server can export its own (distinctly-named) file intended for
> > inclusion, and the node(s) that collect them need only to put the
> > appropriate 'include' directive(s) into the main memcache.ini.
>
> So you can't do this with your own defines as the resource?


It depends what "this" is.  You certainly can export and collect
instances of a defined type.


> I have various define calls like this:
>
> users::normal { bob: id => 107, email => '...@bob.com' }
>
> What I'm looking to do is collect all the emails into an array or
> something so I can use them in a template.


It sounds like your problem is that you don't in fact want to collect
*resources* at all -- rather, you want to collect *data*.  That is not
what exported resources are for.


> I thought maybe I could make a define that does an array append or
> something?


Do not confuse a Puppet defined type with a CPP "#define" macro.  They
are not analogous.  Strictly speaking, an instance of a Puppet defined
type doesn't *do* anything; it rather declares a logical resource for
Puppet to manage on the node in question.

Exported resources are resources intended to be managed on nodes other
than (or in addition to) the one declaring them.  There is necessarily
an aspect of data sharing to that, but they should not be viewed as a
vehicle for data sharing.


> It sounds from what people are saying like there really isn't a
> reasonable way to do this yet?


Again, it depends on what "this" is, but I think you are approaching
the problem backwards.  If you need centralized data then you should
create a data source and use it to drive your resource declarations
wherever appropriate.  Details depend a lot on your general approach
and the complexity of the data, but if you want to access your shared
data store from within Puppet itself then I'd recommend looking into
hiera.

More generally, there is no good way for manifests to extract data
from declared (or collected) resources, and I am unaware of any plans
to change that.  I do not personally think it a problem that should be
solved.


John

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to