Ask Your Question
0

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???

asked 2018-02-16 01:07:40 -0500

sreepadh gravatar image

updated 2018-02-19 10:53:41 -0500

DarylW gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-02-16 18:02:18 -0500

natemccurdy gravatar image

updated 2018-03-14 03:00:39 -0500

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 %>
edit flag offensive delete link more

Comments

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

DarylW gravatar imageDarylW ( 2018-02-19 10:52:57 -0500 )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

DarylW gravatar imageDarylW ( 2018-02-19 10:59:35 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2018-02-16 01:06:11 -0500

Seen: 46 times

Last updated: Mar 14