Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Chef as a provisioner

Chef as a provisioner

Part two of a talk about Vagrant. You should also view the presentation that came in between http://www.slideshare.net/hijoerayme/puppet-presentation-17330477

Andy Gale

March 18, 2013
Tweet

More Decks by Andy Gale

Other Decks in Technology

Transcript

  1. as a provisioner Tuesday, 19 March 13

  2. Provisioners Vagrant::Config.run do |config| config.vm.provision :chef_solo do |chef| chef.roles_path =

    "roles" chef.add_role("vm") end end Chef Solo: Tuesday, 19 March 13
  3. Provisioners Vagrant::Config.run do |config| config.vm.provision :chef_server do |chef| chef.chef_server_url =

    "http://chef.inter.net" chef.add_role("vm") end end Chef Server: Tuesday, 19 March 13
  4. • chef-solo ship cookbooks with your code • chef-server store

    cookbooks in a chef server Tuesday, 19 March 13
  5. Very brief overview Cookbooks Collections of recipes, templates and other

    configuration attributes to get stuff done. Recipes Chunks of Ruby code that describe what stuff we need to do to get that stuff done. Tuesday, 19 March 13
  6. Very brief overview Node A virtual machine, cloud server or

    server Resource Creates a user, expands a template, installs a package etc Tuesday, 19 March 13
  7. Very brief overview Attribute Port number, database name, file location

    etc Template A template which you create a file from inserting variables Tuesday, 19 March 13
  8. package "ntp" do action :install end template "/etc/ntp.conf" do source

    "ntp.conf.erb" owner "root" group "root" mode 0644 notifies :restart, resources(:service => "ntp") end service "ntp" do action :start end Install package Create config file from template Define service and start NTP Restart service when config file changes Tuesday, 19 March 13
  9. https://github.com/contenthub/ch-wordpress Example to setup Wordpress Tuesday, 19 March 13

  10. Opscode Community Cookbooks Tuesday, 19 March 13

  11. include_recipe "mysql::ruby" include_recipe "apt" include_recipe "build-essential" include_recipe "apache2" include_recipe "mysql::server"

    include_recipe "php" include_recipe "php::module_mysql" include_recipe "apache2::mod_php5" include_recipe "database" Include community cookbooks Tuesday, 19 March 13
  12. mysql_connection_info = {:host => "localhost", :username => 'root', :password =>

    node['mysql']['server_root_password']} database node['ch-wordpress']['db']['database'] do connection mysql_connection_info provider Chef::Provider::Database::Mysql action :create end mysql_database_user node['ch-wordpress']['db']['user'] do connection mysql_connection_info password node['ch-wordpress']['db']['password'] database_name node['ch-wordpress']['db']['database'] privileges [:select,:update,:insert,:create,:delete] action :grant end Database cookbook Tuesday, 19 March 13
  13. directory node['ch-wordpress']['dir'] do mode 0755 owner "root" group "root" action

    :create end Database cookbook Tuesday, 19 March 13
  14. remote_file node['ch-wordpress']['dir'] + "/wordpress.salt.php" do source "https://api.wordpress.org/secret-key/1.1/salt/" action :create_if_missing mode

    "0644" end salt_data = '' ruby_block "fetch-wordpress-salt" do block do salt_data = '<?php ' + File.read( node['ch-wordpress']['dir'] + '/wordpress.salt.php') end action :create end Ruby Code in Recipe! Tuesday, 19 March 13
  15. template node['ch-wordpress']['dir'] + '/wp-config.php' do source "wp-config.php.erb" mode 0755 owner

    "root" group "root" variables( :database => node['ch-wordpress']['db']['database'], :user => node['ch-wordpress']['db']['user'], :password => node['ch-wordpress']['db']['password'], :salt_data => salt_data) end Template resource Tuesday, 19 March 13
  16. <VirtualHost *:80> ServerName <%= @params[:server_name] %> DocumentRoot <%= @params[:docroot] %>

    <Directory <%= @params[:docroot] %>> Options FollowSymLinks AllowOverride FileInfo Options AllowOverride All Order allow,deny Allow from all </Directory> <Directory /> Options FollowSymLinks AllowOverride None </Directory> </VirtualHost> .erb template Tuesday, 19 March 13
  17. web_app node['ch-wordpress']['host'] do template "ch-wordpress.conf.erb" docroot node['ch-wordpress']['dir'] server_name node['ch-wordpress']['host'] end

    apache2 cookbook provides web_app Tuesday, 19 March 13
  18. • Community cookbooks http://community.opscode.com/ • IRC #chef on freenode •

    Foodfight show podcast http://foodfightshow.org/index.html • Ask me andygale@andy-gale.com • Read my book! You’re not alone Tuesday, 19 March 13
  19. Tuesday, 19 March 13

  20. Read my book! Tuesday, 19 March 13

  21. Questions on Vagrant, Puppet or Chef? Tuesday, 19 March 13