On Thursday, June 6, 2013 1:41:55 PM UTC-5, Johnny Costello
wrote:>
> I am using a defined type so that I can have an array and have the defined
> type generate a file based on each member of the array.
That''s a functional view of it, at least, but it is usually more
helpful
look at Puppet manifests from the perspective of modeling the target
configuration. From that perspective, the situation is something like:
"I''m using a defined type to manage several related files with
content
derived from the same template".
Don''t get me wrong: this is not about you communicate the problem to
us; it
is about how you think about it yourself. I hope to help you become a
better puppeteer by adopting a mindset more congruent with Puppet''s
natural
paradigm.
> However In the erb file I also have values that i want set specific to
> that file that is generated.
>
> When i call the defined type how do i pass in the values that i want used
> for that file from my class.
>
>
If you are using an array of resource titles to declare all the wanted
resources, then you don''t get to pass different parameters to different
instances. The instances can still be customized, however, by making the
defined type select the appropriate values from some shared data structure
or service, using the automatic $title (or $name) variable as a key. The
shared data might take the form of a hash-valued class variable, it might
reside in hiera, or it might manifest some other way. For example:
class test {
$my_files = [''test'',''test1'']
$realms = {
''test'' => [ ''realm1'',
''realm2'' ],
''test1'' => [ ''realm3'',
''realm4'' ]
}
test::proxy_realm_file { $my_files: }
}
define test::proxy_realm_file () {
$proxy_realms = $test::realms[${title}]
file { "/tmp/${title}":
ensure => ''file'',
content => template("test/test.erb")
}
}
For real-world use you would probably want to externalize the data (via
hiera, for instance); I omit that from the example to focus on the
technique I am demonstrating.
There are several other ways to approach this, some of them quite
different. For example, if you restructure your defined type a bit, you
could use the create_resources() function to declare all the wanted
instances based on a hash of instance titles and parameters.
John
--
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 puppet-users+unsubscribe@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.