- Staying OS Agnostic?
- Testing well
package 'httpd'
installs latest version of that package
service 'ntp' do
action [ :enable, :start ]
end
enabled on reboot and started
file '/etc/motd' do
content 'This computer is the property ...'
end
a file created with the content defined
action: delete
will delete the file
chef-apply --help
will send out the help block
chef-apply -e
execute inline command
chef-apply <file>
run the recipe
Declare out the attributes that make sense eg. action :create
chef --help
will send out the help block
chef generate <name>
generate a new app, cookbook, or component
chef generate cookbook apache
chef generate recipe server
Ensure you are git
ing everything
Read the README.md
first
chef-apply
is for a one-off on recipes
chef-client
is an agent that performs all the steps on a node rather than 'one-off'
chef-client --local-mode -r "recipe[apach::server]"
running the 'server' recipe from the 'apache' cookbook from the root dir of your cookbook repo
NOTE: the chef-client assumes /home/chef
unless you have a cookbooks
directory
chef-client --local-mode -r "recipe[apach::server],recipe[workstation::setup]"
This command runs multiple recipes NOTE: ensure there is no space around the comma(,)
include_recipe 'workstation::setup'
runs the recipe here. runs in the order provided if multiple include_recipe
s are there
- ChefDK
- RuboCop
- kitchen
- rubocop
- Write test case first
- Run virtual machine and fail
- Write code
- Run virtual machine and succeed
- Destroy virtual machine
kitchen create -> kitchen converge -> kitchen verify -> kitchen destroy
kitchen init
kitchen converge [INSTANCE|REGEX|all]
NOTE: converge doesn't kill the machine
kitchen verify [INSTANCE|REGEXP|all]
verifies the state of the machine after the cookbook runs
kitchen destroy
destroys a test instance
kitchen test
runs kitchen destroy
-> kitchen create
-> kitchen converge
-> kitchen verify
-> kitchen destroy
in that order
describe package('tree') do
it { should be_installed }
end
NOTE: there is a long directory where these specs live, see Writing Test
utilize ohai to gather information about your system as a JSON object
#{node['ipaddress']}
Use when we have formatted string interpolation in a file that will end up on the node
More information can be found at Template Resource
found at cookbooks/<cookbook>/templates/default/
chef generate template index.html
generates the file index.html.erb in templates/default/
under the cookbook
<%=
is known as a "angry squid/squid-rocket"
now from #{node['ipaddress']}
to <%= node['ipaddress'] %>
- Provision Server
- Install Chef
- Copy Web Server cookbook
- Apply the cookbook
- Download Starter Kit
- Allow the Keys for your org to be reset
Repo of all the cookbooks we need
knife
- command-line tool...interfaces between local and Chef Server
berks
- command-line tool...uploads cookbooks to the Chef Server
knife bootstrap
- installs chef tools if they are not already installed; configures to communicate with the Chef Server; runs chef-client to apply a default run list
knife node run_list add <node_name> "recipe[<some_recipe>]"
- add a recipe to the run list for a node
"Wrapper Cookbook" - add new attributes while keeping the core functionality of the original cookbook (Perferred)
╭─user@host ~/chef-repo/cookbooks/myhaproxy ‹system› ‹master*›
╰─$ knife node show node1 -a ipaddress node1:
ipaddress: ###.31.#.###
showing a node attribute example
Describes a node to better define its use
knife node run_list set node2 "role[load_balancer]"
example of changing a node to a role
knife ssh "role:web" -x <user> -P <password> "sudo chef-client"
example of telling a group of nodes under the "web" role to run chef-client
ohai is going to report back up to Chef Server
all_web_nodes = search('node','role:web')
example of a search added to an attribute
- Apply a node to an environment
- make search queries much more specific
- can define defferent functions of nodes that live on the same system
_default
is the default environment assigned to all nodes
NOTE: exists under /environments under your root cookbook dir
knife node environment set <node> acceptance
Example of making a "node" be placed into a environment
- Learn Chef
- Additional Skills
- Docs
- YouTube Chef Channel
- The Ship Show
- Food Fight
- ChefCon