How to create a virtual host with a tramp and a chef

I installed my first stray car, with cookbooks loaded through a knife.

I am stuck in setting up a virtual host.

Here is my Vagrantfile:

Vagrant.configure("2") do |config| config.vm.box = "precise32" config.vm.box_url = "http://files.vagrantup.com/precise32.box" config.vm.network :forwarded_port, guest: 80, host: 8080 config.vm.network :private_network, ip: "192.168.33.10" config.vm.provision :chef_solo do |chef| chef.json = { "mysql" => { "server_root_password" => "admin", "server_repl_password" => "admin", "server_debian_password" => "admin" }, "apache" => { "listen_address" => "0.0.0.0" } } chef.add_recipe "apt" chef.add_recipe "vim" chef.add_recipe "openssl" chef.add_recipe "apache2" chef.add_recipe "mysql" chef.add_recipe "mysql::server" chef.add_recipe "php" # chef.add_recipe "php::module_apc" chef.add_recipe "php::module_curl" chef.add_recipe "php::module_mysql" chef.add_recipe "apache2::mod_php5" chef.add_recipe "apache2::mod_rewrite" end web_app "blog_site" do server_name "blog" server_aliases [ "blog.#{node['domain']}", node['fqdn'] ] docroot "/var/www/blog_site" end # end 

I saw here that if I want to set up a virtual host through apache cooking, I have to use the definition of "web_app".

I added web_app to the stray file, but I get this error

 in `block in <top (required)>': undefined method `web_app' for main:Object (NoMethodError) 

which means (I think) that the syntax is incorrect :)

How can i fix this? Where does the definition of "web_app" go?

+4
source share
2 answers

The web_app call should go into the recipe.

For example, you can create a heap of my-site in a directory, also called my-site . Must have at least 3 files:

  • my-site/metadata.rb with basic metadata:

     name "my-site" description "Adds Apache domain configuration for my site" 
  • my-site/recipes/default.rb :

     include_recipe "apache2" web_app "my_site" do server_name "my-site.localhost" server_aliases ["www.my-site.localhost"] docroot "/vagrant" end 
  • my-site/templates/default/web_app.conf.erb - copy the contents from the sample template from apache2 cookbook ( apache2/templates/default/web_app.conf.erb ).

Please note that I am using "my-site.localhost" as ServerName. You must replace it with your domain name because node['fqdn'] and node['domain'] not defined in your code. DocRoot should also be the right path for your site - it will probably be your synchronized directory, which defaults to "/vagrant" (you can change it).

You can also add 192.168.33.10 my-site.localhost to your hosts file on the host machine (your actual OS).

I wrote an introductory entry about Vagrant and Chef solo, this may be useful for you: http://scriptin.imtqy.com/2013-05-09/vagrant-chef-intro.html

+15
source

It should go into the recipe for the cookbook, which you should write, because it (apparently, I don’t know how good a Apache cookbook is) is unable to configure Apache virtual hosts through the usual node configuration ( chef.json ).

+1
source

Source: https://habr.com/ru/post/1480975/


All Articles