0
我是廚師和測試廚房的新手,我試圖使用隨機JSON文件作爲屬性或環境(最好是屬性),但不幸的是我無法訪問JSON來自食譜的值。使用廚師和測試廚房訪問JSON值
我用下面的目錄結構:
uat
├── attributes
│ ├── dev.json
│ ├── .kitchen
│ │ └── logs
│ │ └── kitchen.log
│ └── prod.json
├── Berksfile
├── Berksfile.lock
├── chefignore
├── environments
│ ├── dev.json
│ └── prod.json
├── Gemfile
├── Gemfile.lock
├── .kitchen
│ ├── default-windows.yml
│ └── logs
│ ├── default-windows.log
│ └── kitchen.log
├── .kitchen.yml
├── metadata.rb
└── recipes
├── default.rb
├── prep.rb
└── service_install.rb
這是.kitchen.yml:
---
driver:
name: machine
username: sample_user
password: sample_pass
hostname: 192.168.1.102
port: 5985
provisioner:
name: chef_zero
json_attributes: true
environments_path: 'environments/dev'
platforms:
- name: windows
suites:
- name: default
run_list:
- recipe[uat::default]
這是dev.json:
{
"groupID": "Project-name",
"directoryName": "sample_folder",
"environmentType": "UAT",
}
這是配方prep.rb:
directory "C:/Users/test/#{node['directoryName']}" do
recursive true
action :create
end
如果我創建something.rb在屬性文件夾,並與內容:默認[ '目錄名'] = 'sample_folder',它像魅力一樣工作,但我需要使用JSON文件來存儲公司範圍內的參數。
你能幫我找到我做錯了什麼嗎?
謝謝,那很好用。 是否有使用JSON不使用default_argument道: '{ 「default_attributes」:{} } ' – user3283749
不,你一定要配合環境對象的架構。 – coderanger