0

我是 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 及其值?)

4

1 回答 1

1

data_bag_item从像哈希一样工作的对象返回:

bag = data_bag_item('something', 'bareos-fd')
bag['job']['BackupCatalog'].each do |key, value|
  # ...
end
于 2017-05-01T07:23:53.307 回答