Alex
2010-Dec-13 02:01 UTC
[Puppet Users] Create many similar files from an array in a module manifest
Hi, I want to create a single configuration file with one or two differences, many times. Therefore, i''d like to do the following in pseudo-code: files = [(a,b), (c,d), (e,f)...] foreach a,b in files: create_file(a,b) Which can then use what I think is a valid definition: define create_file($port, $fullserver) { file { "test.erb": content => template(''test.erb''), } } Sadly, it seems that I can not work out either a) How to do the "foreach" in the module manifest, to call the defined function many times with different paramaters b) Where to put the create_file function for puppet to actually recognise it. I have tried <moduledir>/plugins/puppet/parser/functions/ test.rb and <moduledir>/lib/puppet/parser/functions/test.rb, but get error "Could not retrieve catalog: Unknown function create_file" on the client. Any suggestions greatly appreciated! Cheers, Alex -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
PowerPaul86
2010-Dec-13 12:14 UTC
[Puppet Users] Re: Create many similar files from an array in a module manifest
I use the following in a class: /etc/puppet/manifests/classes/impuls_test.pp: $line = ''test'' $tomcatInstances = [ "tc6_a", "tc6_b", "tc6_c", "tc6_d", "tc6_e", "tc6_f", "tc6_g", "tc6_h", "tc6_i", "tc6_j" ] tc6conf { $tomcatInstances: } } and then the following definition: /etc/puppet/manifests/classes/definitions.pp: # Tomcat server.xml.erb und tomcat6.conf.erb shortcut define tc6conf(owner = root, group = root, mode = 644, backup = false, recurse = false, ensure = file) { file { "/tmp/$name-server.xml": mode => $mode, owner => $owner, group => $group, backup => $backup, recurse => $recurse, ensure => $ensure, content => template("$line/$name/server.xml.erb") } file { "/tmp/$name-tomcat6.conf": mode => $mode, owner => $owner, group => $group, backup => $backup, recurse => $recurse, ensure => $ensure, content => template("$line/$name/tomcat6.conf.erb") } } And matching template files /var/lib/puppet/templates/test/tc6_a/ server.xml.erb or in /etc/puppet/templates/ What it does is it deploys the template files server.xml.erb and tomcat6.conf for each tomcat to /tmp So what you get is /tmp/tc6_a-server.xml and /tmp/tc6_a-tomcat6.conf and so on. What I also would like to know is how to pass additional parameters to my defined function, like your $port or $fullserver. I hope that this helps you in any way. On Dec 13, 3:01 am, Alex <a...@davz.net> wrote:> Hi, > > I want to create a single configuration file with one or two > differences, many times. Therefore, i''d like to do the following in > pseudo-code: > > files = [(a,b), (c,d), (e,f)...] > foreach a,b in files: > create_file(a,b) > > Which can then use what I think is a valid definition: > define create_file($port, $fullserver) { > file { "test.erb": > content => template(''test.erb''), > } > > } > > Sadly, it seems that I can not work out either > a) How to do the "foreach" in the module manifest, to call the defined > function many times with different paramaters > b) Where to put the create_file function for puppet to actually > recognise it. I have tried <moduledir>/plugins/puppet/parser/functions/ > test.rb and <moduledir>/lib/puppet/parser/functions/test.rb, but get > error "Could not retrieve catalog: Unknown function create_file" on > the client. > > Any suggestions greatly appreciated! > > Cheers, > > Alex-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Felix Frank
2010-Dec-13 13:14 UTC
Re: [Puppet Users] Create many similar files from an array in a module manifest
On 12/13/2010 03:01 AM, Alex wrote:> Hi, > > I want to create a single configuration file with one or two > differences, many times. Therefore, i''d like to do the following in > pseudo-code: > > files = [(a,b), (c,d), (e,f)...] > foreach a,b in files: > create_file(a,b) > > Which can then use what I think is a valid definition: > define create_file($port, $fullserver) { > file { "test.erb": > content => template(''test.erb''), > } > }Define doesn''t define a function, it defines a resource type. You need no array, just use your define as: create_file { "/etc/foo1.conf": port => $a, fullserver => $b; "/etc/foo2.conf": port => $c, fullserver => $d; ... } You will want to change the define as follows: define create_file($port, $fullserver) { file { "$name": content => template(''test.erb''), } } file { "$name": ... } instead of a static name. Otherwise puppet *will* complain about multiple definition of File["test.erb"]. HTH, Felix -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.