FAQ
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. 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.


Example

# MY class

class test (
    $my_files = hiera_array ('my_files', ['test','test1']),
) {
     createFiles { $my_files: }
}

# My Defined type
define createFiles (
){
    file { "/tmp/${name}":
        template => "/etc/puppet/modules/test/template/test.erb"
    }
}

## My erb file

<% @proxy_realms.each do | realm | -%>
realm <% realm %> {
     pool = <%= @name %>-pool
     nostrip
}
<% end -%>

# here is my problem - In my ERB file each realm will be different for each
file generated. How can I call my defined type, generate a new file for
each type and have a array get generated based on the settings for that file
I tied creating a array called realm in the class definition but then each
file that got generated had the values for that array.

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

Search Discussions

  • Jcbollinger at Jun 7, 2013 at 1:36 pm

    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedJun 6, '13 at 8:04p
activeJun 7, '13 at 1:36p
posts2
users2
websitepuppetlabs.com

2 users in discussion

Jcbollinger: 1 post Johnny Costello: 1 post

People

Translate

site design / logo © 2022 Grokbase