Before hiera you might have a define specifying what a vhost is, and then have 
a class with the defines all listed. You would include that class in your node 
definition, ensuring that this class was applied after the basic apache class. 
Sometimes people would put the defines right in the node, but putting stuff 
directly in the node got discouraged over time. It's basically what you did but 
having the defines in a class rather than in the node.

define thing::one ( $param1, $param2 ) {
  # resources here
}

class thing::ones {
  thing::one { 'first':
    param1 => 'string one',
    param2 => 'string two',
  }
  thing::one { 'second':
    param1 => 'string three',
    param2 => 'string four',
  }
}

node 'hostname' {
  include thing
  include thing::ones
}




On Sun, Jun 22, 2014 at 06:23:05PM -0700, Ben Ruset wrote:
>    Thanks for the answer. I grasp the fundamentals of what you're saying, but
>    right now I'm a little leery of delving into Hiera when I don't really
>    know the fundamentals of Puppet itself yet. My reading through those docs
>    would only confuse me more. (Not that those docs are probably not good -
>    it's just that I'm not sure I'm the target audience - yet.)
>    How would somebody accomplish this before Hiera was around? 
> 
>    On Sunday, June 22, 2014 2:45:52 PM UTC-4, Christopher Wood wrote:
> 
>      Short version: read up on hiera, data bindings, and create_resources.
> 
>      Details:
> 
>      It sounds like you might want to look into hiera (baked into puppet 3
>      and higher) and the create_resources function. Specifically that you
>      list the variable portions of things in your puppet configuration in
>      hiera, and then use the create_resources function to configure an
>      arbitrary number of those things. That way each vhost is another data
>      entry which you can more easily parse and validate than the equivalent
>      puppet code.
> 
>      Quick example:
> 
>      a) your hiera data file
> 
>      ---
>      apache::vhosts::vhosts:
>        '[1]www.example.com':
>          'default_vhost': true
>          'docroot': /var/www/html/[2]www.example.com
>          'logroot': /var/log/httpd/[3]www.example.com
>          'access_log_file': access_log
>          'error_log_file': error_log
>          'override': all
>        '[4]www.otherhost.com':
>          'default_vhost': false
>          'docroot': /var/www/html/[5]www.otherhost.com
>          'logroot': /var/log/httpd/[6]www.otherhost.com
>          'access_log_file': access_log
>          'error_log_file': error_log
>          'override': all
> 
>      b) a define representing one vhost, note variables named like yaml keys
> 
>      define apache::onevhost (
>        $default_vhost,
>        $docroot,
>        $logroot,
>        $access_log_file,
>        $error_log_file,
>        $override,
>      ) {
>        # your resource declarations here
>      }
> 
>      c) a class wrapping that define and the create_resources function, also
>      with some chaining/collecting so that the resources are applied in the
>      right order
> 
>      class apache::vhosts ( $vhosts ) {
>        include apache
>        create_resources('apache::onevhost', $vhosts)
>        Class['Apache'] -> Apache::Onevhost <| |>
>      }
> 
>      d) in your node definition (or better, in a profile included in a role)
>      you would include the apache::vhosts class
> 
>      include ::apache::vhosts
> 
>      Here's the read-until-eyes-bleed set of links:
> 
>      [7]http://docs.puppetlabs.com/hiera/1/
>      
> [8]https://ask.puppetlabs.com/question/117/how-can-i-use-data-bindings-in-puppet-3/
>      
> [9]http://docs.puppetlabs.com/puppet/latest/reference/lang_collectors.html
>      
> [10]http://docs.puppetlabs.com/references/latest/function.html#createresources
>      
> [11]http://docs.puppetlabs.com/puppet/latest/reference/lang_functions.html
>        (str2bool from stdlib could be important when declaring true/false in
>      yaml)
>      [12]http://docs.puppetlabs.com/guides/scope_and_puppet.html
>      [13]http://www.craigdunn.org/2012/05/239/
>      [14]http://garylarizza.com/blog/2014/02/17/puppet-workflow-part-1/
>      [15]http://garylarizza.com/blog/2014/02/17/puppet-workflow-part-2/
>      
> [16]https://ask.puppetlabs.com/question/1655/an-end-to-end-roleprofile-example-using-hiera/
> 
>      Now all that said, the optimal way to write up your home/work puppet
>      setup is the one that makes your life easier. The above represents my
>      opinion and no more. Your mileage may definitely vary and that's
>      perfectly fine too.
> 
>    --
>    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 [17]puppet-users+unsubscr...@googlegroups.com.
>    To view this discussion on the web visit
>    
> [18]https://groups.google.com/d/msgid/puppet-users/ca8e184e-e8a7-4b35-b9b6-e43ca8cd899e%40googlegroups.com.
>    For more options, visit [19]https://groups.google.com/d/optout.
> 
> References
> 
>    Visible links
>    1. http://www.example.com/
>    2. http://www.example.com/
>    3. http://www.example.com/
>    4. http://www.otherhost.com/
>    5. http://www.otherhost.com/
>    6. http://www.otherhost.com/
>    7. http://docs.puppetlabs.com/hiera/1/
>    8. 
> https://ask.puppetlabs.com/question/117/how-can-i-use-data-bindings-in-puppet-3/
>    9. http://docs.puppetlabs.com/puppet/latest/reference/lang_collectors.html
>   10. 
> http://docs.puppetlabs.com/references/latest/function.html#createresources
>   11. http://docs.puppetlabs.com/puppet/latest/reference/lang_functions.html
>   12. http://docs.puppetlabs.com/guides/scope_and_puppet.html
>   13. http://www.craigdunn.org/2012/05/239/
>   14. http://garylarizza.com/blog/2014/02/17/puppet-workflow-part-1/
>   15. http://garylarizza.com/blog/2014/02/17/puppet-workflow-part-2/
>   16. 
> https://ask.puppetlabs.com/question/1655/an-end-to-end-roleprofile-example-using-hiera/
>   17. mailto:puppet-users+unsubscr...@googlegroups.com
>   18. 
> https://groups.google.com/d/msgid/puppet-users/ca8e184e-e8a7-4b35-b9b6-e43ca8cd899e%40googlegroups.com?utm_medium=email&utm_source=footer
>   19. https://groups.google.com/d/optout

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/20140623015257.GA13290%40iniquitous.heresiarch.ca.
For more options, visit https://groups.google.com/d/optout.

Reply via email to