0
votes

I'm pretty new to chef. I'm using it to provision a vagrant development environment using the apache2-windows cookbook, which inconveniently has very little by way of documentation. I have managed to get it to install, and even play nicely with opscodes php cookbook, but I'm struggling to get it to set up a vhost.

So far I have added the vhosts 'extra' to /attributes/default.rb like so:

default['apache']['windows']['extras'] = ["vhosts"]

That successfully adds a 'vhosts.d' directory to apache root, includes httpd-vhosts.conf in httpd.conf, and adds an entry to httpd-vhosts.conf which includes *.conf in the 'vhosts.d' directory.

Unfortunately I can't quite figure out how to use the virtualhost resource provided with the recipe, which looks like it should be putting my vhosts into the 'vhosts.d' using the /templates/default/virtualhost.conf.erb template.

I have added the following to /recipes/default.rb

virtualhost "mysite.localhost" do
  server_aliases ["www.mysite.localhost"]
  docroot "/vagrant"
  action :create
end

but it fails, telling me 'No resource or method named 'virtualhost' for 'Chef::Recipe "default"'.

What am I missing? Is there something else I need to do to allow me to use the virtualhost resource in my recipe?

1

1 Answers

1
votes

It's one of the caveat with library cookbooks/LWRP their names are derived from the cookbook name.

Doc is HERE

If apache2-windows is not in the runlist you have to define it with depends 'apache2-windows' in your cookbook metadata.rb.

But the main problem here is that the virtualhost resource will be named apache2_windows_virtualhost due to 2 things:

  • The resource is derived from the cookbook name, so it become cookbook_resource
  • Ruby does not allow - in classes names, so they are 'magically' converted to _ for resources calls.

tl;dr; use this

apache2_windows_virtualhost "mysite.localhost" do
  server_aliases ["www.mysite.localhost"]
  docroot "/vagrant"
  action :create
end