厨师厨房测试,如何通过多个厨师食谱 AWS Opsworks 喜欢?



我尝试在本地 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]?类似于操作模式:

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文件。

最新更新