Hi,

On 20/10/2015 23:06, yi zhao wrote:
Hi,
so we have a few template setup under my_module/templates/
like
create_pre_rac_setup.sh.erb
run_this_rac.sh.erb
....


and I write someting in init.pp

  $db_setup_home = "$dbnamehome/dbs/create_$dbname"
     file { "$db_setup_home/create_pre_rac_setup_$dbname.sh":
     ensure => 'file',
     content => template("${module_name}/create_pre_rac_setup.sh.erb"),
     mode => '0644',
     owner => 1001,
     group => 1000,
   }

    file { "$db_setup_home/run_this_rac_$dbname.sh":
     ensure => 'file',
     content => template("${module_name}/run_this_rac.sh.erb"),
     mode => '0644',
     owner => 1001,
     group => 1000,
   }

but if I have 500 templates, I would have to write 500 files which is against puppet thinking, is there a way to write a loop to read all template files under my_module/templates/
then just loop to create the files with the same naming standard?


Use a "define" for this: https://docs.puppetlabs.com/puppet/4.2/reference/lang_defined_types.html

To sketch a solution:

define rac_script($home, $source) {
    file { "${home}/${name}.sh:
        content => template("${source}/${name}.sh.erb",
        ...
    }
}

rac_script {
    [ 'create_pre_rac_setup', 'run_this_rac', ... ]:
        home => "$dbnamehome/dbs/create_$dbname",
        source => $module_name,
}

This would still need a list of all the scripts to deploy, but you can use e.g. https://github.com/puppetlabs/puppetlabs-stdlib/#get_module_path and https://docs.puppetlabs.com/references/latest/function.html#generate to create that list dynamically with a small script on the master, or create a custom function to do so in ruby.


Cheers, D.

--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/56275A4B.40501%40dasz.at.
For more options, visit https://groups.google.com/d/optout.

Reply via email to