Puppet Templates to cope with potential multiple sessions settings in the config file

28 views
Skip to first unread message

Richie Rees

unread,
Nov 4, 2013, 6:31:22 AM11/4/13
to puppet...@googlegroups.com
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.

Jacob Fleming-Gale

unread,
Nov 4, 2013, 5:38:40 PM11/4/13
to puppet...@googlegroups.com
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.


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


--
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...@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.

Reply all
Reply to author
Forward
0 new messages