Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Sadly, even if you go about and use a custom "define" to iterate over an array upon splitting your custom fact on a comma, the result will be rather not what you expect and not even close to a "for each" loop -- aside of causing you a headache, probably.</p> <p>Said that, I am not sure if this is what you want to achieve, but have a look at this approach:</p> <pre><code>$fact = '1.1.1.1,2.2.2.2,3.3.3.3' $servers = split($::fact, ',') $count = size($servers) $names = bracket_expansion("host[01-${count}].address") file { '/tmp/test.txt': content =&gt; inline_template('&lt;%= @servers.each_with_index.map {|v,i| "#{v}\t\t#{@names[i]}\n" } %&gt;'), ensure =&gt; present } </code></pre> <p>What we have there are two custom functions: size() and bracket_expansion(); which we then use values that they provide inside a hack that leverages the inline_template() function to render content of the file utilising parallel access to two arrays -- one with IP addresses from your fact and one with host names that should follow.</p> <p>The result is a follows:</p> <pre><code>matti@acrux ~ $ cat | puppet apply $fact = '1.1.1.1,2.2.2.2,3.3.3.3' $servers = split($::fact, ',') $count = size($servers) $names = bracket_expansion("host[01-${count}].address") file { '/tmp/test.txt': content =&gt; inline_template('&lt;%= @servers.each_with_index.map {|v,i| "#{v}\t\t#{@names[i]}\n" } %&gt;'), ensure =&gt; present } notice: /Stage[main]//File[/tmp/test.txt]/ensure: created notice: Finished catalog run in 0.07 seconds matti@acrux ~ $ cat /tmp/test.txt 1.1.1.1 host01.address 2.2.2.2 host02.address 3.3.3.3 host03.address matti@acrux ~ $ </code></pre> <p>Both size() and bracket_expansion() functions can be found here:</p> <p><a href="https://github.com/kwilczynski/puppet-functions/tree/master/lib/puppet/parser/functions/">https://github.com/kwilczynski/puppet-functions/tree/master/lib/puppet/parser/functions/</a></p> <p>I hope this helps a little :-)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload