【问题标题】:Can I move parts of chef.json to databags?我可以将部分 chef.json 移动到数据包吗?
【发布时间】:2014-05-14 21:57:14
【问题描述】:

我正在使用 vagrant + chef-solo + barkshelf 插件。在我的 Vagrantfile 我有这个:

chef.json = {
  "postgresql" => {
    "password" => {
      "postgres" => "password"
    }
  },
  "database" => {
    "create" => ["chembl_18"]
  },
  "build_essential" => {
    "compiletime" => true
  }
}

如果我在这里添加更多配置,我的 Vagrantile 很快就会变得凌乱。我试图改变这一点,所以我创建了 databags/postgresql/json_attribs.json 文件,内容如下:

{
  "postgresql": {
    "password": {
      "postgres": "iloverandompasswordsbutthiswilldo"
    }
  }
}

并修改了我的 Vagrantfile 中的内容:

chef.json = {
  :postgresql => ["json_attribs"],
  "database" => {
    "create" => ["chembl_18"]
  },
...
}

但它不起作用,我得到:

==> default:  58>>   default['postgresql']['dir'] = "/etc/postgresql/#{node['postgresql']['version']}/main"
...
==> default: [2014-05-14T12:36:51+00:00] ERROR: Running exception handlers
==> default: [2014-05-14T12:36:51+00:00] ERROR: Exception handlers complete
==> default: [2014-05-14T12:36:51+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
==> default: [2014-05-14T12:36:51+00:00] FATAL: TypeError: can't convert String into Integer

那么我应该如何以及在哪里放置这些设置以便将它们分成几个单独的文件?

【问题讨论】:

    标签: vagrant chef-infra chef-solo berkshelf vagrantfile


    【解决方案1】:

    不,您不能在不更改配方代码的情况下将其移动到数据包中。

    属性(您通过 vagrant 配置提供)与数据包不同,后者也存储 JSON 数据。数据包中的数据只是在 Chef Server 中“闲置”,直到您在说明书中明确阅读。

    可以通过search()data_bag()data_bag_item() 函数读取数据包,请参阅documentation

    为避免混淆您的Vagrantfile,您应该使用rolewrapper cookbook

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-27
      • 1970-01-01
      • 2021-10-13
      • 2011-09-10
      • 1970-01-01
      • 2017-03-20
      • 2022-06-10
      • 1970-01-01
      相关资源
      最近更新 更多