FWIW, this is my working solution and I think it is much better:

/etc/puppet/modules/profiles/manifests/logstash/config.pp:

class profiles::logstash::config {
  $brokers = $profiles::logstash::brokers
  $cluster = $profiles::logstash::cluster

  if (!empty($brokers)) and (empty($cluster)) {
    notice("This is a shipper.")
    logstash::configfile { 'output_broker':
      content => template('profiles/logstash/output_broker.erb'),
      order   => 100
    }
  } elsif (!empty($cluster)) and (!empty($brokers)) {
      notice("This is a central indexer.")
      logstash::configfile { 'input_broker':
        content => template('profiles/logstash/input_broker.erb'),
        order   => 10
      }
      logstash::configfile { 'output_es':
        content => template('profiles/logstash/output_es.erb'),
        order   => 100
      }
  }
}

/etc/puppet/modules/profiles/manifests/logstash/install.pp

class profiles::logstash::install() {
  $ensure = $profiles::logstash::enable ? {true => present, default => 
absent}
  $status = $profiles::logstash::start ? {true => enabled, default => 
disabled}

  class { '::logstash':
    ensure  => $ensure,
    status  => $status,
    version => $profiles::logstash::version
  }
}

/etc/puppet/modules/profiles/manifests/logstash.pp:

# == Class: profiles::logstash
#
# A basic module to manage logstash
#
# === Parameters
# [*version*]
#   The package version to install
#
# [*brokers*]
#   An array of brokers to use on this node
#
# [*enable*]
#   Should the service be enabled during boot time?
#
# [*start*]
#   Should the service be started by Puppet?
#
# Note: Values here are defaults and can be overriden by Hiera
#       see - /etc/puppet/data/node/<host>.yaml

class profiles::logstash(
   $version = "1.4.1-1_bd507eb",
   $brokers = ["172.16.14.30", "172.16.14.60"],
   $cluster = undef,
   $enable  = true,
   $start   = true
) {
   class{'profiles::logstash::install': } ->
   class{'profiles::logstash::config': } ->
   Class["profiles::logstash"]
}

And my YAML:

classes:
  - roles::logshipper

profiles::logstash::version: '1.4.1-1_bd507eb'
profiles::logstash::enable: true
profiles::logstash::start: false
profiles::logstash::brokers:
  - hostname1
  - hostname2

And my ERB files

/etc/puppet/modules/profiles/templates/logstash/

<% for @host in @brokers %>

input {
  redis {
    host      => "<%= @host %>"
    type      => "redis-input"
    data_type => "list"
    key       => "logstash"
  }
}

<% end %>

/etc/puppet/modules/profiles/templates/logstash/output_broker.erb:

<%
# iterate over brokers array passed in via Hiera and concatenate
# redis hosts for logstash configuration
host_string = "["
@brokers.each_with_index { |host,idx|
   host_string << "\"#{host}\"";
   host_string << "," if idx < @brokers.length-1
}
host_string << "]"
%>

output {
  redis {
    host => <%= host_string %>
    data_type => "list"
    key => "logstash"
  }
}

/etc/puppet/modules/profiles/templates/logstash/output_es.erb:

output {
  elasticsearch {
    cluster   => "<%= cluster %>"
    index     => "logstash-%{+YYYY.MM.dd.HH}"
  }
}



On Monday, June 2, 2014 11:11:32 AM UTC-4, jcbollinger wrote:
>
>
>
> On Thursday, May 29, 2014 2:39:15 PM UTC-5, Brian Wilkins wrote:
>>
>> Solved it using this tip.. it's odd but it works: 
>> http://serverfault.com/a/538877/26514
>>
>>
>
> That's odd only inasmuch as the original problem in that serverfault 
> question was different from yours.  The OP was trying to achieve a similar 
> structure to the one you are working on, though, so it is natural that what 
> worked for him also works for you.
>
> For what it's worth, I think your original problem was here:
>
> [...]
>
>   profiles::logstash::config { $name:
>        content => $content,
>        order   => $order,
>   }
>
> [...]
>
> The variables $content and $order had not been assigned any values in that 
> scope (class profiles::logstash::shipper), which is exactly what the error 
> message said.
>
> I think that create_resources() was a red herring.  It should have been 
> possible to use create_resources() more or less as you originally attempted 
> to do, though you should have specified the fully-qualified name of the 
> resource type ("profiles::logstash::config"), which you did not do.  
> Indeed, your final data structure appears still amenable to use with 
> create_resources().
>
>  
>
>> shipper.pp
>>
>> class profiles::logstash::shipper() {
>>
>>   $shipper_array = hiera_array('profiles::logstash::config_array')
>>
>>   define hash_extract() {
>>     $shipper_hash = hiera_hash('profiles::logstash::config_settings')
>>     $shipper_config = $shipper_hash[$name]
>>
>>     profiles::logstash::config {'shipper':
>>        content => $shipper_config['content'],
>>        order   => $shipper_config['order'],
>>     }
>>     notice($shipper_config['content'])
>>     notice($shipper_config['order'])
>>   }
>>
>>   hash_extract{$shipper_array:}
>>
>>   class { 'logstash':
>>     ensure  => 'present',
>>     version => '1.4.1-1_bd507eb',
>>     status  => 'enabled',
>>   }
>>   include logstash
>>
>
>
> Note that the 'include logstash' is completely redundant (but not directly 
> harmful) in that context because Class['profiles::logstash'] is already 
> declared (immediately prior).  It would be much better to declare the class 
> via its fully-qualified name, though, whichever form you use.
>
>  
>
>> }
>>
>>
>
> I urge you, however, to avoid nesting classes or defined types.  The 
> semantics are not necessarily what you expect (THAT was the serverfault 
> questioner's issue), it makes the class or definition harder to find, and 
> it contributes to confusion about the actual names of these things.
>
>
> 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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/b9ecbc6a-8991-4300-a368-b5f268437d15%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to