Ask Your Question

How to form an array from the attribute of the resources collected using resource collector?

asked 2015-11-02 21:58:43 -0600

VeekshaVasanth gravatar image

updated 2015-11-04 01:12:04 -0600

GregLarkin gravatar image

I have the definition of resource to be exported as below:

@@host { $::fqdn:
  ensure => 'present',
  host_aliases => [$::hostname],
  ip => $::ipaddress,
  tag => 'classroom',

And if i use above resource on certain nodes and later collect the host resource tagged 'classroom' as below:

Host <<| tag == 'classroom' |>>

Then, how can i form a array of ip addresses (ip attribute of host resource) of all the hosts tagged classroom?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-11-04 01:14:57 -0600

GregLarkin gravatar image

I can't think of a way to do that in the standard Puppet DSL. However, you could potentially write a custom function that iterates all of the host resources in the catalog, creates an array of their IP addresses and returns that to a variable in your manifest.

What are you trying to achieve? Perhaps there's another way to solve it without resorting to a custom function.

edit flag offensive delete link more


I want array of IPs of the required hosts to use it in a template. Could you provide a snippet of custom function that can be used to achieve it? And also share the other approach without custom function ?

VeekshaVasanth gravatar imageVeekshaVasanth ( 2015-11-04 21:36:27 -0600 )edit

I don't have any sample code, I just meant that it could be done. However, I remember that this Forge module exists: You could use it to transmit variable values from one host to another and perhaps build a list of the IP addresses. YMMV

GregLarkin gravatar imageGregLarkin ( 2015-11-05 22:27:03 -0600 )edit

Thanks for the information GregLarkin!

VeekshaVasanth gravatar imageVeekshaVasanth ( 2015-11-22 21:21:37 -0600 )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

1 follower


Asked: 2015-11-02 21:41:43 -0600

Seen: 156 times

Last updated: Nov 04 '15