Chef infra 如何与厨师一起使用LWRP?

Chef infra 如何与厨师一起使用LWRP?,chef-infra,lwrp,Chef Infra,Lwrp,我是厨师的新手,我正在尝试设置一个包装食谱来管理日志。使用LWRP 如何使用LWRP管理配置文件 这是我到目前为止的包装食谱 recipes/default.rb include_recipe 'apt::default' include_recipe 'java::default' include_recipe 'logstash::server' default['logstash']['instance_default']['elasticsearch_cluster'] = 'exam

我是厨师的新手,我正在尝试设置一个包装食谱来管理日志。使用LWRP

如何使用LWRP管理配置文件

这是我到目前为止的包装食谱

recipes/default.rb

include_recipe 'apt::default'
include_recipe 'java::default'
include_recipe 'logstash::server'
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
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'
include_recipe 'apt'
include_recipe 'java'
include_recipe 'logstash::server'
属性/default.rb

include_recipe 'apt::default'
include_recipe 'java::default'
include_recipe 'logstash::server'
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
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'
include_recipe 'apt'
include_recipe 'java'
include_recipe 'logstash::server'
伯克斯菲尔

source "https://supermarket.chef.io"

metadata

cookbook 'logstash', git: 'https://github.com/lusis/chef-logstash.git'
根据文档,在中有一个使用LWRP的示例,但我不确定如何使用它

LWRP定义放在哪里?
包装烹饪书中的LWRP看起来像什么

更新

以下是我尝试过的:

recipe/default.rb中,我添加了以下内容

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
foobar
然后在
templates/default/config/foobar\u output\u elasticsearch.conf.erb
中,我有以下内容

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
foobar
然而,当我运行一个文件时,文件并没有被创建

更新2

根据irc频道中的cheeseplus,您应该能够像这样使用LWRP:

default['logstash']['instance_default']['config_templates_cookbook'] = 'config/foobar_output_elasticsearch.conf.erb'

不幸的是,它不起作用

更新3

我还尝试在我的default.rb中设置属性,如下所示:

default['logstash']['instance_default']['config_templates_cookbook'] = 'My-Wrapper-Cookobook'
default['logstash']['instance_default']['config_templates']['foobar'] = 'config/foobar_output_elasticsearch.conf.erb'
更新4

我还尝试过直接在资源中设置参数,但没有成功

logstash_config 'foobar' do
  templates_cookbook 'MY-Wrapper-Cookbook'
  templates 'config/foobar_output_elasticsearch.conf.erb'
  action [:create]
  notifies :restart, "logstash_service[#{name}]"
end
更新5

,我还尝试了以下语法

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'
}

我们发现,语法是正确的,并且可以工作,但是测试厨房文件没有加载正确的烹饪书

这是最终的工作输出

属性/default.rb

include_recipe 'apt::default'
include_recipe 'java::default'
include_recipe 'logstash::server'
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
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'
include_recipe 'apt'
include_recipe 'java'
include_recipe 'logstash::server'
recipes/default.rb

include_recipe 'apt::default'
include_recipe 'java::default'
include_recipe 'logstash::server'
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
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'
include_recipe 'apt'
include_recipe 'java'
include_recipe 'logstash::server'
.厨房

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

我也试着直接问作者。