我试图了解如何正确使用配方中的环境属性。注意:我了解我的方法可能不是Chef的最佳做法。但是,我的目标是了解此处的数据流,而不必在生产应用程序中使用我的方法。
一些细节:
chef-zero
供应商(因此,我必须在我的环境中使用ruby文件,而不是由于主厨无用限制而无法使用JSON)。 ├── environments
├── vm.rb
├── roles
├── base.json
├── cookbooks
├── init
├── recipes
├── default.rb
├── Vagrantfile
这是我的文件
vm.rb
name "vm"
description "Configuration file for the Kukla Demo VM"
default_attributes(
custom_demo: {
title: 'My demo title',
description: 'My demo description'
))
base.json
{
"name": "base",
"description": "Base VM configuration",
"chef_type": "role",
"json_class": "Chef::Role",
"default_attributes": {},
"override_attributes": {},
"run_list": ["recipe[init::default]"]
}
default.rb
#
# Cookbook:: init
# Recipe:: default
#
# Copyright:: 2020, The Authors, All Rights Reserved.
print 'I am here!'
print node[:custom_demo]
Vagrantfile
中的主厨供应商>...
chef.nodes_path = 'nodes/'
chef.environments_path = 'environments/'
chef.roles_path = 'roles/'
chef.cookbooks_path = 'cookbooks/'
# Roles
chef.add_role "base"
...
[当我运行预配器时,我希望看到在厨师运行日志中打印的custom_demo
哈希。类似于:
... ==> Machine: Synchronizing Cookbooks: ==> Machine: [2020-02-07T20:37:15+00:00] INFO: Storing updated cookbooks/init/recipes/default.rb in the cache. ==> Machine: ==> Machine: - init (0.1.0) ==> Machine: Installing Cookbook Gems: ==> Machine: Compiling Cookbooks... ==> Machine: I am here! custom_demo => { :title => 'My demo title', :description => 'My demo description' } ==> Machine: Converging 0 resources ==> Machine: [2020-02-07T20:37:15+00:00] INFO: Chef Infra Client Run complete in 0.118042019 seconds ...
实际行为
相反,我得到:
... ==> Machine: Synchronizing Cookbooks: ==> Machine: [2020-02-07T20:37:15+00:00] INFO: Storing updated cookbooks/init/recipes/default.rb in the cache. ==> Machine: ==> Machine: - init (0.1.0) ==> Machine: Installing Cookbook Gems: ==> Machine: Compiling Cookbooks... ==> Machine: I am here! ==> Machine: Converging 0 resources ==> Machine: [2020-02-07T20:37:15+00:00] INFO: Chef Infra Client Run complete in 0.118042019 seconds ...
我的问题:
基于结果,我还有以下问题:
背景我试图了解如何正确使用配方中的环境属性。注意:我了解我的方法可能不是Chef的最佳做法。但是,我的目标是...
您所做的一切正确,您的期望是正确的。唯一缺少的是,您没有将环境分配给虚拟机。为此,您需要在Vagrantfile
中添加一行: