Reputation: 18427
I'm new to chef, and I'm trying to setup a wrapper cookbook to manage logstash. The cookbook I am wrapping uses LWRP.
How do you manage a config file using a LWRP?
Here is the wrapper cookbook that I have so far
recipes/default.rb
include_recipe 'apt::default'
include_recipe 'java::default'
include_recipe 'logstash::server'
attributes/default.rb
default['logstash']['instance_default']['elasticsearch_cluster'] = 'example-elasticsearch'
default['logstash']['instance_default']['elasticsearch_ip'] = 'elasticsearch01.example.com'
default['logstash']['instance_default']['elasticsearch_port'] = '9200'
default['logstash']['instance_default']['elasticsearch_embedded'] = false
Berksfile
source "https://supermarket.chef.io"
metadata
cookbook 'logstash', git: 'https://github.com/lusis/chef-logstash.git'
According to the documentation, there is an example of using a LWRP in the .kitchen.yml, but I'm not sure how to use it.
Where do I put the LWRP definitions?
What does a LWRP look like inside a wrapper cookbook?
Update
Here is what I have tried:
In recipe/default.rb
I've added the following
include_recipe 'apt::default'
include_recipe 'java::default'
include_recipe 'logstash::server'
logstash_config 'config/foobar_output_elasticsearch.conf.erb' do
action [:create]
notifies :restart, "logstash_service[#{name}]"
end
Then inside templates/default/config/foobar_output_elasticsearch.conf.erb
I have the following
foobar
Yet when I run a kitchen converge, the file is not created
Update2
According to cheeseplus in the irc channel, you should be able to use a LWRP like so:
default['logstash']['instance_default']['config_templates_cookbook'] = 'config/foobar_output_elasticsearch.conf.erb'
https://github.com/lusis/chef-logstash/issues/367
Unfortunately it doesn't work.
Update3
I've also tried setting attributes in my default.rb like so:
default['logstash']['instance_default']['config_templates_cookbook'] = 'My-Wrapper-Cookobook'
default['logstash']['instance_default']['config_templates']['foobar'] = 'config/foobar_output_elasticsearch.conf.erb'
Update4
I've also tried setting the parameters in the resource directly with no luck.
logstash_config 'foobar' do
templates_cookbook 'MY-Wrapper-Cookbook'
templates 'config/foobar_output_elasticsearch.conf.erb'
action [:create]
notifies :restart, "logstash_service[#{name}]"
end
Update5
Looking at this example, I've also tried the following syntax.
default['logstash']['instance_default']['config_templates'] = {
'input_redis' => 'config/input_redis.conf.erb',
'filter_syslog' => 'config/filter_syslog.conf.erb',
'output_elasticsearch' => 'config/output_elasticsearch.conf.erb',
'foobar' => 'config/foobar_output_elasticsearch.conf.erb'
}
Upvotes: 1
Views: 1489
Reputation: 18427
Figured it out, The syntax was correct and working, however the test kitchen file wasn't loading the correct cookbooks.
Here is the final working output
attributes/default.rb
default['logstash']['instance_default']['elasticsearch_cluster'] = 'foobar-elasticsearch'
default['logstash']['instance_default']['elasticsearch_ip'] = 'elasticsearch01.example.com'
default['logstash']['instance_default']['elasticsearch_port'] = '9200'
default['logstash']['instance_default']['elasticsearch_embedded'] = false
default['logstash']['instance_default']['config_templates_cookbook'] = 'foobar-Logstash-Indexer'
default['logstash']['instance_default']['config_templates']['foobar'] = 'config/foobar_output_elasticsearch.conf.erb'
recipes/default.rb
include_recipe 'apt'
include_recipe 'java'
include_recipe 'logstash::server'
.kitchen.yml
---
driver:
name: vagrant
driver_config:
require_chef_omnibus: true
use_vagrant_berkshelf_plugin: true
customize:
memory: 512
cpus: 1
provisioner:
name: chef_solo
platforms:
- name: ubuntu-12.04
- name: centos-5.10
- name: centos-6.5
- name: centos-7.0
- name: fedora-20
- name: debian-7.6
suites:
- name: server
run_list:
- recipe[apt::default]
- recipe[java::default]
# - recipe[logstash::server]
- recipe[foobar-Logstash-Indexer::default]
Upvotes: 1