ohai
== Facter from Puppet- Chef Client and Chef Server: Behave similar to Puppet Master and Puppet Agent.
- Chef DK: A quick start toolbox for first-time use.
- Test Kitchen: Enables you to test and debug your cookbooks against virtualized environments.
- ChefSpec: Chef supports testing of your cookbooks. Chefspec is a tool similar to RSpec but modified to fit Chef.
- Create an Ubuntu 16.04 VM
- Open up ports 80 and 443
- Follow this guide.
- Install Management Console (also in above link).
- Make sure everything is up:
sudo chef-server-ctl status
andsudo chef-manage-ctl status
- Access the Web Management Console at
https://IP Addr
If you encounter 502 Bad Gateway
, use this StackOverflow.
kitchen console # Kitchen Console!
kitchen converge [INSTANCE|REGEXP|all] # Change instance state to ...
kitchen create [INSTANCE|REGEXP|all] # Change instance state to ...
kitchen destroy [INSTANCE|REGEXP|all] # Change instance state to ...
kitchen diagnose [INSTANCE|REGEXP|all] # Show computed diagnostic ...
kitchen doctor INSTANCE|REGEXP # Check for common system p...
kitchen exec INSTANCE|REGEXP -c REMOTE_COMMAND # Execute command on one or...
kitchen help [COMMAND] # Describe available comman...
kitchen init # Adds some configuration t...
kitchen list [INSTANCE|REGEXP|all] # Lists one or more instances
kitchen login INSTANCE|REGEXP # Log in to one instance
kitchen package INSTANCE|REGEXP # package an instance
kitchen setup [INSTANCE|REGEXP|all] # Change instance state to ...
kitchen test [INSTANCE|REGEXP|all] # Test (destroy, create, co...
kitchen verify [INSTANCE|REGEXP|all] # Change instance state to ...
kitchen version # Print Kitchen's version i...```
- Vagrant
- Virtualbox
- Chef DK
- Windows OS
- A good text editor like Atom.
Follow the commands in the quick-start guide above.
chef generate app first_cookbook
cd first_cookbook/
Edit the file cookbooks\first_cookbook\recipes\default.rb
and add the content:
file "#{ENV['HOME']}/test.txt" do
content 'This file was created by Chef!'
end
Save the file. Run
chef-client --local-mode --override-runlist first_cookbook
Expected Result: A file test.txt
should be created in your %HOME%
directory.
The chef generate
command created a lot of stub files.
│ .kitchen.yml # Contains a default Test Kitchen config with 2 test VMs.
│ README.md
│
├───.kitchen # Is automatically generated when you run kitchen commands.
│ └───logs
│ default-centos-7.log
│ default-ubuntu-1604.log
│ kitchen.log
│
├───cookbooks # Contains the cookbook files for "first_cookbook".
│ └───first_cookbook
│ │ Berksfile
│ │ chefignore
│ │ metadata.rb
│ │
│ ├───recipes
│ │ default.rb # This is where you add a recipe.
│ │
│ └───spec
│ │ spec_helper.rb
│ │
│ └───unit
│ └───recipes
│ default_spec.rb #
│
├───nodes
│ DGSLBLRHNW1.json
│
└───test
└───smoke
└───default
default_test.rb
- The file should have been autogenerated by your
chef generate
command. - By default it contains two
platforms
entries. These are test environments where your cookbook will be tested. - IF you run
kitchen list
you will see the output below.
kitchen list
Instance Driver Provisioner Verifier Transport Last Action Last Error
default-ubuntu-1604 Vagrant ChefZero Inspec Ssh <Not Created> <None>
default-centos-7 Vagrant ChefZero Inspec Ssh <Not Created> <None>
This will now create the VMs specified in our .kitchen.yml
.
- During VM creation, Vagrant + Virtualbox is used. Errors in Vagrant box download, or creation of VM, will cause the
kitchen create
command to fail.
In general, use the test subcommand to verify the end-to-end quality of a cookbook. Use the converge and verify subcommands during the normal the day-to-day development of a cookbook. (from https://docs.chef.io/ctl_kitchen.html)
chef-client -z -c .\client.rb -o provisioner
What we did:
-z
runs in Chef Zero mode i.e. without requiring an existing Chef Server.-c
loads the Chef client configuration from theclient.rb
file located in this directory.-o provisioner
creates a Run List with one cookbook. The cookbookprovisioner
is loaded from thecookbooks/
directory.