Chef

Learn Chef Rally

De demo machine met vagrant/centos/virtualbox

vagrant box add bento/centos-7.2 --provider=virtualbox
vagrant init bento/centos-7.2
vagrant up
vagrant ssh
curl https://omnitruck.chef.io/install.sh | sudo bash -s -- -P chefdk -c stable -v 0.18.30

maak een file aan met chef (hello.rb)

file '/tmp/motd' do
content 'hello world'
end

verwijder een file (goodbye.rb)

file '/tmp/motd' do
action :delete
end

voer chef uit voor localhost

chef-client --local-mode hello.rb
chef-client --local-mode goodbye.rb

installeer een webserver en start deze met een introductie pagina

package 'httpd'
service 'httpd' do
    action [:enable, :start]
end

file '/var/www/html/index.html' do
  content '<html>
  <body>
    <h1>hello world</h1>
  </body>
</html>'
end

acties worden in volgorde uitgevoerd

chef generate cookbook cookbooks/learn_chef_httpd
chef generate template cookbooks/learn_chef_httpd index.html

een template in een recept

template '/var/www/html/index.html' do
  source 'index.html.erb'
end

uitvoeren van een recept

sudo chef-client --local-mode --runlist 'recipe[learn_chef_httpd]'

- Harold de Bruijn