繁体   English   中英

厨师厨房测试,如何通过多个AWS Opsworks之类的厨师食谱?

[英]Chef kitchen tests, how to pass multiple Chef cookbooks AWS Opsworks like?

我尝试在本地的Centos 7 OS上测试Chef食谱。

我遵循https://learn.chef.io/modules/local-development/rhel/virtualbox/apply-a-cookbook#/

---
driver:
  # specifies the software that manages the machine. We're using the Vagrant Test Kitchen driver
  name: vagrant

provisioner:
  #  specifies how to run Chef. We use chef_zero because it enables you to mimic a Chef server environment on your local machine. This allows us to work with node attributes and other Chef server feature
  name: chef_zero
  chef_environment: dev # how to detect my JSON node config ?

verifier:
  # specifies which application to use when running automated tests. You'll learn more about automated testing in a future module.
  name: inspec

platforms:
  - name: centos-7

suites:
  - name: default
    run_list:
      # list of cookbooks
      - recipe[learn_chef_httpd::default]
    attributes:

如何用recipe[learn_chef_httpd::default]的完整目录替换recipe[learn_chef_httpd::default] 类似于opsworks模式

Config
Gemfile
LICENSE
README.md
Rakefile
foobar_app_drupal/
foobar_app_joomla/
foobar_app_magento/
foobar_app_magento2/
foobar_app_marello/
foobar_app_nginxconfig/
foobar_app_orocommerce/
foobar_app_orocrm/
foobar_app_phpapp/
foobar_app_prestashop/
foobar_app_satis/
foobar_app_symfony/
foobar_app_symfony3/
foobar_app_typo/
foobar_app_wordpress/
foobar_composer/
foobar_crontab/
foobar_efs/
foobar_htpasswd/
foobar_logs/
foobar_quanta/
foobar_sftp_users/
foobar_varnish/
dependencies/
deploy/
ebs/
gem_support/
haproxy/
memcached/
mod_php5_apache2/
mysql/
nginx/
opsworks_agent_monit/
opsworks_aws_flow_ruby/
opsworks_berkshelf/
opsworks_bundler/
opsworks_cleanup/
opsworks_commons/
opsworks_custom_cookbooks/
opsworks_ecs/
opsworks_ganglia/
opsworks_initial_setup/
opsworks_java/
opsworks_nodejs/
opsworks_postgresql/
opsworks_rubygems/
opsworks_shutdown/
opsworks_stack_state_sync/
packages/
passenger_apache2/

recipes/default.rb文件:

package 'httpd'

service 'httpd' do
  action [:enable, :start]
end

template '/var/www/html/index.html' do # ~FC033
  source 'index.html.erb'
end

也许我可以通过包括所有食谱来替换所有行? 请告诉我如何

也许像:

include_recipe 'opsworks_initial_setup/recipes/default.rb'
include_recipe 'foobar/recipes/setup.rb'

我也需要使用节点JSON配置。

如何包含此配置?

编辑 :我已经像您解释的那样修改了我的文件,但是现在,我在kitchen converge出现以下错误:

       System Info:
       ------------
       chef_version=14.5.33
       platform=centos
       platform_version=7.5.1804
       ruby=ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
       program_name=/opt/chef/bin/chef-client
       executable=/opt/chef/bin/chef-client


       Running handlers:
       [2018-10-02T14:22:32+00:00] ERROR: Running exception handlers
       Running handlers complete
       [2018-10-02T14:22:32+00:00] ERROR: Exception handlers complete
       Chef Client failed. 0 resources updated in 01 seconds
       [2018-10-02T14:22:32+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
       [2018-10-02T14:22:32+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
       [2018-10-02T14:22:32+00:00] FATAL: Chef::Exceptions::CookbookNotFound: Cookbook opsworks_initial_setup not found. If you're loading opsworks_initial_setup from another cookbook, make sure you configure the dependency in your metadata
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>>     Converge failed on instance <default-centos-7>.  Please see .kitchen/logs/default-centos-7.log for more details
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration

ssh到Centos实例:

[root@default-centos-7 kitchen]# cat /tmp/kitchen/cache/chef-stacktrace.out 
Generated at 2018-10-02 14:22:32 +0000
Chef::Exceptions::CookbookNotFound: Cookbook opsworks_initial_setup not found. If you're loading opsworks_initial_setup from another cookbook, make sure you configure the dependency in your metadata
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/cookbook/cookbook_collection.rb:39:in `block in initialize'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/ohai-14.5.4/lib/ohai/mash.rb:72:in `default'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/ohai-14.5.4/lib/ohai/mash.rb:72:in `default'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/run_context.rb:349:in `[]'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/run_context.rb:349:in `load_recipe'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/run_context.rb:306:in `block in include_recipe'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/run_context.rb:305:in `each'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/run_context.rb:305:in `include_recipe'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/dsl/include_recipe.rb:26:in `include_recipe'
/tmp/kitchen/cache/cookbooks/learn_chef_httpd/recipes/default.rb:20:in `from_file'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/mixin/from_file.rb:34:in `instance_eval'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/mixin/from_file.rb:34:in `from_file'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/cookbook_version.rb:199:in `load_recipe'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/run_context.rb:350:in `load_recipe'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/run_context/cookbook_compiler.rb:166:in `block in compile_recipes'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/run_context/cookbook_compiler.rb:163:in `each'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/run_context/cookbook_compiler.rb:163:in `compile_recipes'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/run_context/cookbook_compiler.rb:79:in `compile'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/run_context.rb:199:in `load'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/policy_builder/expand_node_object.rb:97:in `setup_run_context'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/client.rb:515:in `setup_run_context'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/client.rb:281:in `run'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/application.rb:303:in `run_with_graceful_exit_option'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/application.rb:279:in `block in run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/local_mode.rb:44:in `with_server_connectivity'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/application.rb:261:in `run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/application/client.rb:440:in `run_application'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/lib/chef/application.rb:66:in `run'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.5.33/bin/chef-client:25:in `<top (required)>'
/opt/chef/bin/chef-client:75:in `load'

您应该为您的供应商指定cookbook_path例如

至于包括,适当的格式之一是:

<cookbook name>::<recipe name>

因此,在您的情况下:

include_recipe 'opsworks_initial_setup::default'
include_recipe 'foobar::setup'

JSON配置可以通过环境文件传递:

provisioner:
  name: chef_zero
  environments_path: 'path/to/environments/directory'
  client_rb:
    environment: staging

您必须使用文档中描述的结构创建staging.json文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM