# I want to create multiple directories as well as in directories I want to create scripts with templates and want to insert different schema values for same scripts in placeholders in different folders. can anyone help me with this???

script.pp

class script {
$test_root = hiera('test_root')$clientnames = hiera('clientnames')
$adcs = hiera('adcs')$user = 'wild'
$usergroup = 'wild' # function call with lambda:$clientnames.each |String $clientid| { #$adcs.sort.each |String $adc| { file { "${test_root}/client/${clientid}/": ensure => directory, owner => "${user}",
group   => "${usergroup}", #mode => 0755, } file { "${test_root}/client/$clientid/scoring": ensure => directory, owner => "${user}",
group   => "${usergroup}", require => File["${aml_root}/client/$clientid"], } file { "${test_root}/client/$clientid/scoring/script.sh": ensure => file, #ensure => file, #mode => 0755, owner => "${user}",
group   => "${usergroup}", content => template('/etc/puppetlabs/code/environments/production/modules/wildron/templates/test.erb'), require => File["${aml_root}/client/$clientid/scoring"], } } }  template.pp <% Array(@adcs).each do |line| -%> #!/bin/ksh # Client schema configuration export AML_DB_CLIENT_SCHEMA=<%= line %> <% end -%>  hiera adcs: - 'schema1' - 'schema2' clientnames: - 'cid1' - 'cid2'  output: its creating all folders and scripts. But in scripts the output like same in all folders of clients #!/bin/ksh # Client schema configuration export AML_DB_CLIENT_SCHEMA=schema1 #!/bin/ksh # Client schema configuration export AML_DB_CLIENT_SCHEMA=schema2  But i want like : if its cid1 folder i want the schema name as schema1 in script if its cid2 i want the schema name as schema 2 in script Can any one help me out. Its urgent...!!!!!! edit retag close merge delete ## 1 Answer Sort by » oldest newest most voted Your template is looping over the $adcs array and creating a complete script with each loop. That's why your files look the way they do.

Try again with these changes:

class script {

$test_root = hiera('test_root')$clientnames = hiera('clientnames')
$adcs = hiera('adcs')$user        = 'wild'
$usergroup = 'wild'$clientnames.each |String $clientid| {$adcs.sort.each |String $adc| { file { "${test_root}/client/${clientid}/": ensure => directory, owner =>$user,
group  => $usergroup, } file { "${test_root}/client/${clientid}/scoring": ensure => directory, owner =>$user,
group  => $usergroup, } file { "${test_root}/client/${clientid}/scoring/script.sh": ensure => file, owner =>$user,
group   => \$usergroup,
content => template('wildron/test.erb'),
}
}
}
}


script.erb

#!/bin/ksh
# Client schema configuration
export AML_DB_CLIENT_SCHEMA=<%= @adc %>

more

I've edited the OP's question to put code blocks to make things slightly more readable, but the code sample didn't have any formatting in the underlying text representation from his message

( 2018-02-19 10:52:57 -0600 )edit

It also looks like one if his nested for loops in the code starts with a comment, so it isn't directly executable puppet code... unless I'm just parsing it Incorrectly

( 2018-02-19 10:59:35 -0600 )edit