Ask Your Question
2

How stable will the iterator (each) function be?

asked 2013-09-20 04:56:30 -0500

robrwo gravatar image

I've come across the each function in the experimental features for v3.2: http://docs.puppetlabs.com/puppet/3/reference/langexperimental3_2.html, e.g.

puppet apply --parser future -e '$a  = [1,2,3] $a.each |$value| { notice $value }'

I would really like to use something like this:

$sources.each |$src| {

  firewall { "100 allow connection on $port from $source":
      port => $port,
      source => $source,
  }

}

Since the firewall resource is already being created from another resource that's specified in hiera, it's difficult to specify separate entries for each firewall souce. The "each" function is exactly what Puppet has ... (more)

edit retag flag offensive close merge delete

Comments

I did find an alternative method of iterating over an array from here https://ask.puppetlabs.com/question/1041/how-to-iterate-over-an-array-and-create-a-resource-for-each/ but the syntax is unclear, and it relies on the ...(more)

robrwo gravatar imagerobrwo ( 2013-09-20 07:26:38 -0500 )edit

I have heard from people at PuppetLabs that the future parser can slow things down. In particular, the "each" iterator is treated as a custom resource that depends on other custom resources.

robrwo gravatar imagerobrwo ( 2014-02-06 08:24:27 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2014-01-23 08:19:04 -0500

robrwo gravatar image

updated 2014-04-11 03:56:16 -0500

The function is documented in the language reference at http://docs.puppetlabs.com/references/latest/function.html#each without any note that it is an experimental feature.

edit flag offensive delete link more
0

answered 2013-12-20 08:07:46 -0500

ffrank gravatar image

updated 2014-04-02 04:17:28 -0500

I believe this question is more suitable for the puppet-dev mailing list.

Note that you can achieve the effect even today using create_resources:

$data = { 
  ip1 => { port => <port1> },
  ip2 => { port => <port2> },
  ...
}
create_resources(my_firewall, $data)
define my_firewall($port) {
  $source = $name
  firewall { "100 allow connection on $port from $source":
    port => $port,
    source => $source,
  }
}

Code is untested, but carries the idea, I hope.

Also, nearer to your use case

$sources = { ip1 => {}, ip2 => {}, ... }
create_resources(my_firewall, $sources, { port => $port })

...the latter hash forming the parameter defaults for all the my_firewall resources that get spawned.

edit flag offensive delete link more

Comments

I know you can pass lists of resource names. I've never seen the use of hashes with create_resources in the way you've used it.

robrwo gravatar imagerobrwo ( 2014-02-06 08:26:07 -0500 )edit

And hopefully you won't ever again, because that was some weird code ;-) Will edit so it makes more sense.

ffrank gravatar imageffrank ( 2014-04-02 04:07:22 -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

1 follower

Stats

Asked: 2013-09-20 04:56:30 -0500

Seen: 2,490 times

Last updated: Apr 11 '14