我是Chef的新手,我在使用嵌套属性从data_bags获取值时遇到了一些问题。
{
"id": "bareos-fd",
"description": "Client resource of the Director itself.",
"address": "localhost",
"job": {
"backup-bareos-fd": {
"jobdefs": "DefaultJob"
},
"BackupCatalog": {
"description": "Backup the catalog database (after the nightly save)",
"jobdefs": "DefaultJob",
"level": "Full",
"fileset": "Catalog",
"schedule": "WeeklyCycleAfterBackup",
"run_before": "/usr/lib/bareos/scripts/make_catalog_backup.pl MyCatalog",
"run_after": "/usr/lib/bareos/scripts/delete_catalog_backup",
"bootstrap": "|/usr/bin/bsmtp -h localhost -f \\\"\\(Bareos\\) \\\" -s \\\"Bootstrap for Job %j\\\" root@localhost",
"priority": "11"
},
"RestoreFiles": {
"type": "Restore",
"fileset": "LinuxAll",
"storage": "File",
"pool": "Incremental",
"messages": "Standard",
"where": "/tmp/bareos-restores"
}
}
}
如何编写foreach来获取嵌套值(如BackupCatalog及其值?)
答案 0 :(得分:1)
从data_bag_item
返回的对象就像哈希:
bag = data_bag_item('something', 'bareos-fd')
bag['job']['BackupCatalog'].each do |key, value|
# ...
end