Ask Your Question
0

question on hash and referencing in template

asked 2015-04-15 13:03:16 -0500

dhirenp gravatar image

updated 2015-04-15 21:48:13 -0500

GregLarkin gravatar image

hi, question on hash and template.

if i have a hash as such:

$job_hash = {
  'foo' => {
    ensure => 'present',
    enabled => 1,
    config => template('jenkins/build-mvn-master.xml.erb')
  },
  'foo2' => {
    ensure => 'present',
    enabled => 1,
    config => template('jenkins/build-mvn-master.xml.erb')
  }
}

how can i reference 'foo' and 'foo2' in the template?

Thanks

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2015-04-24 08:27:38 -0500

JohnsonEarls gravatar image

The naive answer is:

<%= @job_hash['foo'] %>
<%= @job_hash['foo2'] %>

However, because you're processing the template inside the definition of $job_hash, the job_hash variable will not be available within the template. I don't believe there is any way to directly get what you are asking to work, because of the Puppet rules against variable reassignment.

If config is the same between the 'foo' and 'foo2' hash entries anyway, why not just make it a separate variable?

$job_hash = {
    'foo' => {
        ensure => 'present',
        enabled => 1
    },
    'foo2' => {
        ensure => 'present',
        enabled => 1
    },
}
$config = template('...')

Then the template would have no problems accessing the job hash entries using the "naive" answer above.

edit flag offensive delete link more
0

answered 2015-04-24 09:49:08 -0500

HBlock gravatar image

If I understand correctly, you want to create two files (foo and foo2) based on the same template? If that is the case you could use the create_resources function: https://docs.puppetlabs.com/reference...
That would be create_resources('file',$job_hash) In that case you could reference 'foo' / 'foo2' with @title.

edit flag offensive delete link more

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: 2015-04-15 13:03:16 -0500

Seen: 249 times

Last updated: Apr 24 '15