Generate an array from PuppetDB

62 views
Skip to first unread message

Joao Morais

unread,
Jul 16, 2015, 9:41:26 AM7/16/15
to puppet...@googlegroups.com

Hello list.

I'm trying to use PuppetDB to link a webserver cluster to an EJB cluster. Each webserver host need to reference a comma separated list of IPs provided by each EJB host

Exporting and collecting resources works pretty nice but I think this isn't the better approach. I just need a variable with a hash or an array to iterate within an ERB template in order to build my list.

I tried the generate() function approach, using curl to request a JSON array. Iterating such array I can populate my template. But this approach sounds more a workaround instead a solution.

Do you have another ideas to this scenario?

Thanks, JM

Christopher Wood

unread,
Jul 16, 2015, 1:45:53 PM7/16/15
to puppet...@googlegroups.com
On Thu, Jul 16, 2015 at 06:41:26AM -0700, Joao Morais wrote:
> Hello list.
>
> I'm trying to use PuppetDB to link a webserver cluster to an EJB cluster.
> Each webserver host need to reference a comma separated list of IPs
> provided by each EJB host
>
> Exporting and collecting resources works pretty nice but I think this
> isn't the better approach. I just need a variable with a hash or an array
> to iterate within an ERB template in order to build my list.

I use this thing to grab a list of facts that eventually becomes activemq queues/topics for mcollective, your use case sounds similar enough to mine.

https://forge.puppetlabs.com/dalen/puppetdbquery

> I tried the generate() function approach, using curl to request a JSON
> array. Iterating such array I can populate my template. But this approach
> sounds more a workaround instead a solution.
>
> Do you have another ideas to this scenario?
>
> Thanks, JM
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [1]puppet-users...@googlegroups.com.
> To view this discussion on the web visit
> [2]https://groups.google.com/d/msgid/puppet-users/9e4e9385-8c6f-4b9f-95f1-6d502baf0048%40googlegroups.com.
> For more options, visit [3]https://groups.google.com/d/optout.
>
> References
>
> Visible links
> 1. mailto:puppet-users...@googlegroups.com
> 2. https://groups.google.com/d/msgid/puppet-users/9e4e9385-8c6f-4b9f-95f1-6d502baf0048%40googlegroups.com?utm_medium=email&utm_source=footer
> 3. https://groups.google.com/d/optout

Ken Barber

unread,
Jul 16, 2015, 11:17:28 PM7/16/15
to Puppet Users
Joao,

Take a look at this library, authored by my friend Eric:

https://github.com/dalen/puppet-puppetdbquery

It provides Puppet functions for querying PDB, its syntax is a wrapper
around our own PDB one, but should provide you with the tools to do
queries against PDB in a more arbitrary way hopefully avoiding the
need for your own curl/shell methodology. You might still need to
manipulate the data you receive using other tools, but it should be a
good start for what you want. If you get stuck further down the line,
respond to this thread.

We have plans to solidify this story, and make it closer to our core
offerings but I'm wary to get into a vapourware discussion until we
have something to show. For now, what I've provided is where you want
to look.

ken.

Joao Morais

unread,
Jul 17, 2015, 1:13:39 PM7/17/15
to puppet...@googlegroups.com


Em sexta-feira, 17 de julho de 2015 00:17:28 UTC-3, Ken Barber escreveu:
> Hello list.
>
> I'm trying to use PuppetDB to link a webserver cluster to an EJB cluster.
> Each webserver host need to reference a comma separated list of IPs provided
> by each EJB host
>
> Exporting and collecting resources works pretty nice but I think this isn't
> the better approach. I just need a variable with a hash or an array to
> iterate within an ERB template in order to build my list.

Joao,

Take a look at this library, authored by my friend Eric:

https://github.com/dalen/puppet-puppetdbquery

It provides Puppet functions for querying PDB, its syntax is a wrapper
around our own PDB one, but should provide you with the tools to do
queries against PDB in a more arbitrary way hopefully avoiding the
need for your own curl/shell methodology. You might still need to
manipulate the data you receive using other tools, but it should be a
good start for what you want. If you get stuck further down the line,
respond to this thread.

We have plans to solidify this story, and make it closer to our core
offerings but I'm wary to get into a vapourware discussion until we
have something to show. For now, what I've provided is where you want
to look.


Thanks Christopher and Ken. I'm doing some tests with puppetdbquery module and it apparently worked very well for my need.

Please let me know if I'm doing something nasty or if something could be improved. I need to create a comma separated list of remote IPs.

Nodes which are being referenced:

    define exporting (
        $ipbind,
        $env,
    ) {
    }

    ...

    @@exporting { "type_of_server":
        ipbind    => "<binding-ip>",
        my_system => "<my-system-id>",
        my_env    => "<my-environment>",
    }

Nodes that reference:

    $server_resources = query_resources("@@Exporting{my_system=<my-system-id> and my_env=<my-environment>}", "@@Exporting[type_of_server]")

All IPs are here:

    $server_resources[<iterate-here>]['parameters']['ipbind']

Even better if I could use join() (from stdlib) in order to create my list. =)

JM

Reply all
Reply to author
Forward
0 new messages