Allyl Isocyanate
Allyl Isocyanate

Reputation: 13626

Install an apt package using chef.json on Vagrant solo-provisioner

I would like to install several arbitrary APT packages using Vagrants Chef solo provisioner.

chef.json seems to allow you to execute chef commands, but I'm unclear as to how to do this. Something like:

chef.json = {
  apt: {
    package: {'libssl-dev': {action: 'install'}}
  }

?

Upvotes: 2

Views: 652

Answers (2)

Matt
Matt

Reputation: 74879

Chef uses recipes to define resources that are executed on nodes via a chef-client.

  • A recipe is basically a definition of what to do (a script)
  • A resource is a particular element you are configuring (a file, a service, or package etc)
  • A node is the machine running chef-client

The json that you are setting up for chef-solo defines attributes which are like variables that your Chef can use to decide what to do.

So you have a hash of attributes for Chef to use, but you need a recipe that configures resources based on that hash to be executed on your node

In your case you need to configure the package resource

package "name" do
  some_attribute "value"
  action :action
end

The package resource supports lots of different package back ends, including apt so you don't need to worry about differences (except for package names).

To install the packages from your hash you can create a recipe like:

node[:apt][:package].each do |pkg,pkg_data|
    package pkg do
      action pkg_data[:action].to_sym
    end
end

Individual recipes are then packaged up into cookbooks which is a logical grouping of like recipes. Generally a cookbook would be for a piece of software, say httpd or mysql.

As Tensibia mentions, read through the Vagrant Chef-Solo docco for where to put your recipe/cookbook and run from there.

Upvotes: 3

Tensibai
Tensibai

Reputation: 15784

chef.json does not execute or define commands. It defines attributes for the node which can be used by recipes.

I would recomand reading THIS and THIS

Some of the json content is generated by vagrant like defining the runlist attribute with the chef.add_recipe keyword in the vagrantfile.

For your use case you should have a cookbook with a recipe parsing node['apt'] and using deb_package resource.

Upvotes: 1

Related Questions