Hi Richie,

There's a few options available with the Ruby ERB templating in Puppet,
depending on how you want to control the output, these pages are a good
introduction to ERB and Puppet.

  http://docs.puppetlabs.com/guides/templating.html
  http://docs.puppetlabs.com/learning/templates.html

Here's a few quick examples for you, based on your question.


option one: provide an array of all the component numbers required.

components = ['1','2','3']
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<% @components.each { |item| -%>
LAUNCH_STRING.Component<%= item %>="Blah"
PROCESS_FOOTPRINT.Component<%= item %>-"Blah"

<% } -%>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


option two: provide the number of components required

components = 4
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<% (1..@components).each { |item| -%>
LAUNCH_STRING.Component<%= item %>="Blah"
PROCESS_FOOTPRINT.Component<%= item %>-"Blah"

<% } -%>


option three: provide an array of component names, the component number is
extracted by index position in the array.

components = ['blah', 'Blah', 'blaH']
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<% @components.to_enum.with_index(1).each { |item, index| -%>
LAUNCH_STRING.Component<%= index %>="<%= item %>"
PROCESS_FOOTPRINT.Component<%= index %>-"<%= item %>"

<% } -%>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Regards
Jacob


On 4 November 2013 21:31, Richie Rees <richard.ree...@gmail.com> wrote:

> Hi,
>
> Here is my dilemma,  have a class that installs an rpm then copies over
> the configuration files. Static files are published as files, variable
> files are published using templates with variables provided from foreman
> smart variable.  The binaries being installed can be used to create
> multiple instances of the same application based on a session id. So if you
> put in three instances in the config file it will launch three instances,
> so it would look like this :-
>
> LAUNCH_STRING.Component1="Blah"
> PROCESS_FOOTPRINT.Component1-"Blah"
>
> LAUNCH_STRING.Component2="Blah"
> PROCESS_FOOTPRINT.Component2-"Blah"
>
> LAUNCH_STRING.Component3="Blah"
> PROCESS_FOOTPRINT.Component3-"Blah"
>
> The problem is how can I recursively add these to the template file from
> an integer variable based on the number of sessions required. I remember
> seeing you could do this but now I have gone back to find it all my
> "googling" turns up how to recursively copy directories over. I hope that
> explanation is clear enough.
>
> Thanks,
>
> Richie.
>
> --
> 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 puppet-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/73498c38-3f7f-4c31-8707-13cd38e7f17d%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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 puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/CAOQMBgx5jwUeRQq%2BL9Ko77s9ozkdj-S4kVRb%3DQtKjyXx04LmPA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to