Question

I'm using vagrant + chef-solo + barkshelf plugin. In my Vagrantfile I have this:

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

if I add some more configuration here, my Vagrantile will quickly become messy. I was trying to chenge this, so I've created databags/postgresql/json_attribs.json file with following content:

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

and modified contents in my Vagrantfile:

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

But it doesn't work, I'm getting:

==> 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

So how and where should I place this settings in order to split them into several separate files?

Was it helpful?

Solution

No, you can't just move it to a data bag without changing the recipe code.

Attributes (that you are supplying through your vagrant config) are distinct from data bags, which also store JSON data. Data in data bags is just "lying around" in Chef Server until you read it explicitly in your cookbooks.

Reading from data bags can happen through the search(), data_bag() and data_bag_item() functions, see documentation.

To avoid cluttering your Vagrantfile, you should either use a role or a wrapper cookbook.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top