Chef Installation
Chef Installation
- Install packaged
sudo yum update
sudo yum install opscode-manage
#sudo chef-server-ctl install opscode-manage
sudo opscode-manage-ctl reconfigure
sudo chef-server-ctl reconfigure
Try this way incase if you dont find opscode-manage in yum repository
Download the chef-manage-2.2.0-1.el6.x86_64.rpm and instal it
sudo rpm -ivh chef-manage-2.2.0-1.el6.x86_64.rpm
sudo chef-manage-ctl reconfigure
Use Chef management console to manage data bags, attributes, run-lists, roles,
environments, and cookbooks from a web user interface
- Navigate to Organisation -> Administration-> Click on start kit and you should
find a button to dowload the starter kit
- unzip the starter kit, this will create chef-repo directory at home location
- run below commands
cd ~/chef-repo
get the key from chef server at below location and copy to chef-
repo/.chef/trusted-certs
/home/vagrant/chef-repo/.chef/trusted_certs
$knife ssl check
$knife ssl fetch
$knife client list
FOR MAC:
https://opscode-omnibus-packages.s3.amazonaws.com/mac_os_x/10.8/x86_64/chefdk-
0.4.0-1.dmg
Login to https://vapps1.konylabs.net/ ( harrypotter/harry123)
click on organisation-> starter kit -> Downlaod starter kit
unzip the starter kit, this will create chef-repo directory at home location
run below commands
cd ~/chef-repo
$knife ssl fetch
$knife client list
chef-validator
***** Working on Workstation to upload a cookbook to server and deploy on node ****
knife cookbook site download learn_chef_httpd
tar -zxvf learn_chef_httpd-0.1.0.tar.gz -C cookbooks
rm learn_chef_httpd*.tar.gz
mv learn_chef_httpd cookbooks/
knife cookbook upload learn_chef_httpd
kinfe cookbook list
-- Important concepts/keywords
package- Used to manage packages on a node
service- Used to manage services on a node
user- Manage users on the node
group- Manage groups
template- Manage files with embedded ruby templates
cookbook_file- Transfer files from the files subdirectory in the cookbook to a
location on the node
file- Manage contents of a file on node
directory- Manage directories on node
execute- Execute a command on the node
cron- Edit an existing cron file on the node
---------------------------------------------
-- Roles and Environments:
Nice explanation form digital ocean below
https://www.digitalocean.com/community/tutorials/how-to-use-roles-and-environments-
in-chef-to-control-server-configurations
Roles:
-----
Chef's view of roles is almost entirely the same as the regular definition. A role
in Chef is a categorization that describes what a specific machine is supposed to
do. What responsibilities does it have and what software and settings should be
given to it.
- Create a role in two ways ( either json file DSL ruby file)
"production": [
"recipe[nginx::config_prod]"
],
"testing": [
"recipe[nginx::config_test]"
]
}
}
---------------------------------------------
The above role with json will directly creates on server, so no need to
upload
2) Using chef DSL script
vi web_server.rb
add below contents to the web_server.rb file
------------------------------
name "web_server"
description "A role to configure our front-line web servers"
run_list "recipe[apt]", "recipe[nginx]"
env_run_lists "production" => ["recipe[nginx::config_prod]"], "testing"
=> ["recipe[nginx::config_test]"]
default_attributes "nginx" => { "log_location" =>
"/var/log/nginx.log" }
override_attributes "nginx" => { "gzip" => "on" }
------------------------------
upload it using below command to chef server
knife role from file
]
},
"run_list": [
"role[web_server]"
]
}
--------------------------------
Thats it now instead of recipies we added a role to the node
-> To search list of nodes with given role, we can use below command
knife search "role:web_server AND chef_environment:_default" -a name
Environments:
-------------
In some ways, environments are fairly similar to roles. They are also used to
differentiate different servers, but instead of differentiating by the function of
the server, environments differentiate by the phase of development that a machine
belongs to.
Create an Environments
mkdir ~/chef-repo/environments
cd ~/chef-repo/environments
Same as role we can create it with ruby DSL or json file using knife directly
on server
Data bags:
--------=
A data bag is a collection of bits of JSON called data bag items, indexed by
an ID, that Chef allows us to use and search in our recipes. Let's use knife to
create our data bags
Type the following on your workstation to create a data bag called wp-sites.
--------------
sites = data_bag("wp-sites")
sites.each do |site|
opts = data_bag_item("wp-sites", site)
mysql_database opts["database"] do
connection ({:host => 'localhost', :username => 'root', :password
=> node['mysql']['server_root_password']})
action :create
end
----------------------
-------------------