SlideShare a Scribd company logo
1 of 28
Download to read offline
Chef solo
The beginning
Background
It is efficient to automate things that
we do again and again, even it takes
some time
Background
Server setup is one of the most tedious and
boring task, which we have to do again and
again.
Look at your screen to see if the mysql
password request has come or not.
Why chef
● Idempotent: Safe to re run the script
● Thick Clients, Thin Server
● A level of platform independencies
● Rich collection of recipes (800+)
● Integration with Leading Cloud Providers
Terminology
Chef: Cooks a recipe for you,
they way you want
Recipe: A set of instructions for preparing
a particular dish
Cookbooks: Manages your recipe
Node: Configuration of your recipe
Knife: A tool to help you cook
Getting started
Root /
-- cookbooks
-- node.json
-- run_recipies.rb
Run the script
$ sudo chef-solo -c run_recipies.rb -j node.json
Getting started
● cookbooks
○ mysql
■ recipes
● default.rb
● another_recipie.rb
■ templates
● my.cnf
■ files
Using existing repo
Target: setup mysql with chef solo
● Pull the mysql cookbook in the cookbooks
folder
● Change the node.json to serve our need
Using existing repo
Sample node.json
{ "run_list": [ "recipe[mysql::server]",
"recipe[mysql::client]" ],
"mysql": { "server_root_password": "",
"server_repl_password": "",
"server_debian_password": "",
"bind_address": "0.0.0.0",
"allow_remote_root": true
}
}
Using existing repo
Run the script
$ sudo chef-solo -c run_recipies.rb -j node.json
RE Run the script any number of time
$ sudo chef-solo -c run_recipies.rb -j node.json
And it is safe :D
Creating own recipe
Create folder structure as follows
chef/
├── cookbooks
| └── mychefrepo
| ├── recipes
| | └── default.rb
| ├── templates
| └── files
└── solo.rb
default.rb
1 begin
2 require 'mysql'
3 rescue LoadError
4 Chef::Log.info("Missing gem 'mysql'")
5 end
6
7 ruby_block "Create replication user and database" do
8 block do
9 m = Mysql.new('localhost', "root", node[:mysql][:server_root_password])
10
11 command = %Q{
12 GRANT ALL ON *.*
13 TO '#{node[:mysql][:server_replication][:database_user]}'@'%'
14 IDENTIFIED BY
15 '#{node[:mysql][:server_replication][:database_password]}';
16 }
17 m.query(command)
18 m.query('FLUSH PRIVILEGES')
19 end
20 # only execute if mysql is running
21 only_if "pgrep 'mysqld$'"
22 end
default.rb
1 gem_package "bundler"
2 begin
3 require 'mysql'
4 rescue LoadError
5 Chef::Log.info("Missing gem 'mysql'")
6 end
default.rb
7 ruby_block "Create replication user and database" do
8 block do
9 m = Mysql.new('localhost', "root", node[:mysql][:server_root_password])
10
11 command = %Q{
12 GRANT ALL ON *.*
13 TO '#{node[:mysql][:server_replication][:database_user]}'@'%'
14 IDENTIFIED BY
15 '#{node[:mysql][:server_replication][:database_password]}';
16 }
17 m.query(command)
18 m.query('FLUSH PRIVILEGES')
19 end
20 # only execute if mysql is running
21 only_if "pgrep 'mysqld$'"
22 end
node.json
{ "run_list": [ "recipe[mysql::server]",
"recipe[mysql::client]",
"recipe[mychefrepo]" ],
"mysql": { "server_root_password": "",
"server_repl_password": "",
"server_debian_password": "",
"bind_address": "0.0.0.0",
"allow_remote_root": true,
"server_replication": {
"database": "moteel_production",
"database_user": "repl",
"database_password": "repl"}
}}
Run the script
Run the script
$ sudo chef-solo -c run_recipies.rb -j node.json
Commonly used resources
%w{rover fido bubbers}.each do |pet_name|
execute "feed_pet_#{pet_name}" do
command "echo 'Feeding: #{pet_name}'; touch '/tmp/#{pet_name}'"
not_if { ::File.exists?("/tmp/#{pet_name}")}
end
end
gem_package "bundler" do
options(:prerelease => true, :format_executable => false)
end
package "tar" do
version "1.16.1-1"
action :install
end
Commonly used resources
%w{rover fido bubbers}.each do |pet_name|
execute "feed_pet_#{pet_name}" do
command "echo 'Feeding: #{pet_name}'; touch '/tmp/#{pet_name}'"
not_if { ::File.exists?("/tmp/#{pet_name}")}
end
end
gem_package "bundler" do
options(:prerelease => true, :format_executable => false)
end
package "tar" do
version "1.16.1-1"
action :install
end
Commonly used resources
directory "/tmp/folder" do
owner "root"
group "root"
mode 0755
action :create
end
cookbook_file "/usr/local/bin/apache2_module_conf_generate.pl" do
source "apache2_module_conf_generate.pl"
mode 0755
owner "root"
end
template "/tmp/somefile" do
mode 00644
source "somefile.erb"
not_if { node[:some_value] }
end
Deploying to multiple servers
Problems
● Different servers might need different node.
json file to configure them
● You have to ssh into different servers and
and set up the prerequisites for chef
Deploying to multiple servers
Solution
1. Use chef server
○ Need to buy chef server service
OR
○ Maintain a chef server of your own
OR
2. Use scripts like capistrano and some ruby to
deploy from development machine
Using Capistrano
set :user, '...'
set :password, '........'
set :main_server, '***.**.***.**'
server main_server, :app, :primary => true
namespace :setup do
task :env, :depends => ["setup:install_prerequisite"], :roles => :app do
setup.install_prerequisite
cd_run "ruby change_local.rb #{user} #{main_server}"
cd_run "#{try_sudo} ./setup_base.sh"
cd_run "#{try_sudo} chef-solo -c run_recipies.rb -j local.json"
end
end
Using Capistrano
namespace :setup do
task :install_prerequisite, :roles => :app do
run "mkdir -p /home/#{user}/.ssh"
upload "deploy_keys/id_rsa", "/home/#{user}/.ssh/id_rsa"
upload "deploy_keys/id_rsa.pub", "/home/#{user}/.ssh/id_rsa.pub"
run "#{try_sudo} apt-get update"
run "#{try_sudo} apt-get -y install aptitude git unzip"
begin
run "cd /home/#{user} && git clone git@git.tasawr.com:ashraf/moteel-setup.git"
rescue
cd_run "git pull origin master"
end
run "#{try_sudo} aptitude install -y ruby1.9.1 ruby1.9.1-dev make"
run "#{try_sudo} gem install --no-rdoc --no-ri chef"
end
end
def cd_run(cmd)
run "cd /home/#{user}/moteel-setup && #{cmd}"
end
Using Capistrano
ruby_block "share the torrent file" do
block do
f = File.open(node['bittorrent']['torrent'],'rb')
#read the .torrent file and base64 encode it
enc = Base64.encode64(f.read)
data = {
'id'=>bittorrent_item_id(node['bittorrent']['file']),
'seed'=>node.ipaddress,
'torrent'=>enc
}
item = Chef::DataBagItem.new
item.data_bag('bittorrent')
item.raw_data = data
item.save
end
action :nothing
subscribes :create, resources(:bittorrent_torrent => node['bittorrent']['torrent'])
end
Deploying to multiple servers
1. Configure capistrano with the server
information
2. Install prerequisites with capistrano
3. Run a ruby or any program to update the
node.json file from the capistrano
information
4. Go get yourself a cup of coffee
Wait for the script to complete
References
● Quick start
● Chef DSL
● Chef resources
● Some cookbooks
Author
A.K.M. Ashrafuzzaman
Lead Software Engineer,
Tasawr Interactive.
www.ashrafuzzaman.com
ashraf@tasawr.com

More Related Content

What's hot

DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017Jumping Bean
 
#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to AnsibleCédric Delgehier
 
Chef or how to make computers do the work for us
Chef or how to make computers do the work for usChef or how to make computers do the work for us
Chef or how to make computers do the work for ussickill
 
Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015Alex S
 
Ansible roles done right
Ansible roles done rightAnsible roles done right
Ansible roles done rightDan Vaida
 
What Makes a Good Chef Cookbook? (May 2014 Edition)
What Makes a Good Chef Cookbook? (May 2014 Edition)What Makes a Good Chef Cookbook? (May 2014 Edition)
What Makes a Good Chef Cookbook? (May 2014 Edition)Julian Dunn
 
Automation and Ansible
Automation and AnsibleAutomation and Ansible
Automation and Ansiblejtyr
 
Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2Brian Schott
 
Drupal cambs ansible for drupal april 2015
Drupal cambs ansible for drupal april 2015Drupal cambs ansible for drupal april 2015
Drupal cambs ansible for drupal april 2015Ryan Brown
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricksbcoca
 
chef loves windows
chef loves windowschef loves windows
chef loves windowsMat Schaffer
 
Hacking ansible
Hacking ansibleHacking ansible
Hacking ansiblebcoca
 
Creating Reusable Puppet Profiles
Creating Reusable Puppet ProfilesCreating Reusable Puppet Profiles
Creating Reusable Puppet ProfilesBram Vogelaar
 
Vagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopVagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopLorin Hochstein
 
More tips n tricks
More tips n tricksMore tips n tricks
More tips n tricksbcoca
 
Ansible : what's ansible & use case by REX
Ansible :  what's ansible & use case by REXAnsible :  what's ansible & use case by REX
Ansible : what's ansible & use case by REXSaewoong Lee
 

What's hot (20)

Chef training - Day3
Chef training - Day3Chef training - Day3
Chef training - Day3
 
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
 
#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible
 
Chef or how to make computers do the work for us
Chef or how to make computers do the work for usChef or how to make computers do the work for us
Chef or how to make computers do the work for us
 
Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015
 
Ansible roles done right
Ansible roles done rightAnsible roles done right
Ansible roles done right
 
What Makes a Good Chef Cookbook? (May 2014 Edition)
What Makes a Good Chef Cookbook? (May 2014 Edition)What Makes a Good Chef Cookbook? (May 2014 Edition)
What Makes a Good Chef Cookbook? (May 2014 Edition)
 
Automation and Ansible
Automation and AnsibleAutomation and Ansible
Automation and Ansible
 
Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2
 
Drupal cambs ansible for drupal april 2015
Drupal cambs ansible for drupal april 2015Drupal cambs ansible for drupal april 2015
Drupal cambs ansible for drupal april 2015
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricks
 
chef loves windows
chef loves windowschef loves windows
chef loves windows
 
Hacking ansible
Hacking ansibleHacking ansible
Hacking ansible
 
Ansible - Introduction
Ansible - IntroductionAnsible - Introduction
Ansible - Introduction
 
Creating Reusable Puppet Profiles
Creating Reusable Puppet ProfilesCreating Reusable Puppet Profiles
Creating Reusable Puppet Profiles
 
Vagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopVagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptop
 
More tips n tricks
More tips n tricksMore tips n tricks
More tips n tricks
 
Chef
ChefChef
Chef
 
Ansible : what's ansible & use case by REX
Ansible :  what's ansible & use case by REXAnsible :  what's ansible & use case by REX
Ansible : what's ansible & use case by REX
 
Ansible - Crash course
Ansible - Crash courseAnsible - Crash course
Ansible - Crash course
 

Similar to Chef solo the beginning

Automating complex infrastructures with Puppet
Automating complex infrastructures with PuppetAutomating complex infrastructures with Puppet
Automating complex infrastructures with PuppetKris Buytaert
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with PuppetKris Buytaert
 
Cloud Automation with Opscode Chef
Cloud Automation with Opscode ChefCloud Automation with Opscode Chef
Cloud Automation with Opscode ChefSri Ram
 
Making Your Capistrano Recipe Book
Making Your Capistrano Recipe BookMaking Your Capistrano Recipe Book
Making Your Capistrano Recipe BookTim Riley
 
Cloud Automation with Opscode Chef
Cloud Automation with Opscode ChefCloud Automation with Opscode Chef
Cloud Automation with Opscode ChefSri Ram
 
Cook Infrastructure with chef -- Justeat.IN
Cook Infrastructure with chef  -- Justeat.INCook Infrastructure with chef  -- Justeat.IN
Cook Infrastructure with chef -- Justeat.INRajesh Hegde
 
2019 Chef InSpec Jumpstart Part 2 of 2
2019 Chef InSpec Jumpstart Part 2 of 22019 Chef InSpec Jumpstart Part 2 of 2
2019 Chef InSpec Jumpstart Part 2 of 2Larry Eichenbaum
 
Cloud Automation with Opscode Chef
Cloud Automation with Opscode ChefCloud Automation with Opscode Chef
Cloud Automation with Opscode ChefSri Ram
 
[MDBCI] Mariadb continuous integration tool
[MDBCI] Mariadb continuous integration tool[MDBCI] Mariadb continuous integration tool
[MDBCI] Mariadb continuous integration toolOSLL
 
Architecting cloud
Architecting cloudArchitecting cloud
Architecting cloudTahsin Hasan
 
Distributed monitoring at Hyves- Puppet
Distributed monitoring at Hyves- PuppetDistributed monitoring at Hyves- Puppet
Distributed monitoring at Hyves- PuppetPuppet
 
Facebook的缓存系统
Facebook的缓存系统Facebook的缓存系统
Facebook的缓存系统yiditushe
 
Introduction to Chef
Introduction to ChefIntroduction to Chef
Introduction to Chefkevsmith
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentationSuresh Kumar
 
Philly security shell meetup
Philly security shell meetupPhilly security shell meetup
Philly security shell meetupNicole Johnson
 
Chef Provisioning a Chef Server Cluster - ChefConf 2015
Chef Provisioning a Chef Server Cluster - ChefConf 2015Chef Provisioning a Chef Server Cluster - ChefConf 2015
Chef Provisioning a Chef Server Cluster - ChefConf 2015Chef
 

Similar to Chef solo the beginning (20)

Cooking with Chef
Cooking with ChefCooking with Chef
Cooking with Chef
 
Automating complex infrastructures with Puppet
Automating complex infrastructures with PuppetAutomating complex infrastructures with Puppet
Automating complex infrastructures with Puppet
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with Puppet
 
Chef training - Day2
Chef training - Day2Chef training - Day2
Chef training - Day2
 
Cloud Automation with Opscode Chef
Cloud Automation with Opscode ChefCloud Automation with Opscode Chef
Cloud Automation with Opscode Chef
 
Making Your Capistrano Recipe Book
Making Your Capistrano Recipe BookMaking Your Capistrano Recipe Book
Making Your Capistrano Recipe Book
 
My SQL 101
My SQL 101My SQL 101
My SQL 101
 
Cloud Automation with Opscode Chef
Cloud Automation with Opscode ChefCloud Automation with Opscode Chef
Cloud Automation with Opscode Chef
 
infra-as-code
infra-as-codeinfra-as-code
infra-as-code
 
Cook Infrastructure with chef -- Justeat.IN
Cook Infrastructure with chef  -- Justeat.INCook Infrastructure with chef  -- Justeat.IN
Cook Infrastructure with chef -- Justeat.IN
 
2019 Chef InSpec Jumpstart Part 2 of 2
2019 Chef InSpec Jumpstart Part 2 of 22019 Chef InSpec Jumpstart Part 2 of 2
2019 Chef InSpec Jumpstart Part 2 of 2
 
Cloud Automation with Opscode Chef
Cloud Automation with Opscode ChefCloud Automation with Opscode Chef
Cloud Automation with Opscode Chef
 
[MDBCI] Mariadb continuous integration tool
[MDBCI] Mariadb continuous integration tool[MDBCI] Mariadb continuous integration tool
[MDBCI] Mariadb continuous integration tool
 
Architecting cloud
Architecting cloudArchitecting cloud
Architecting cloud
 
Distributed monitoring at Hyves- Puppet
Distributed monitoring at Hyves- PuppetDistributed monitoring at Hyves- Puppet
Distributed monitoring at Hyves- Puppet
 
Facebook的缓存系统
Facebook的缓存系统Facebook的缓存系统
Facebook的缓存系统
 
Introduction to Chef
Introduction to ChefIntroduction to Chef
Introduction to Chef
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Philly security shell meetup
Philly security shell meetupPhilly security shell meetup
Philly security shell meetup
 
Chef Provisioning a Chef Server Cluster - ChefConf 2015
Chef Provisioning a Chef Server Cluster - ChefConf 2015Chef Provisioning a Chef Server Cluster - ChefConf 2015
Chef Provisioning a Chef Server Cluster - ChefConf 2015
 

Recently uploaded

Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 

Recently uploaded (20)

Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 

Chef solo the beginning

  • 2. Background It is efficient to automate things that we do again and again, even it takes some time
  • 3. Background Server setup is one of the most tedious and boring task, which we have to do again and again. Look at your screen to see if the mysql password request has come or not.
  • 4. Why chef ● Idempotent: Safe to re run the script ● Thick Clients, Thin Server ● A level of platform independencies ● Rich collection of recipes (800+) ● Integration with Leading Cloud Providers
  • 5. Terminology Chef: Cooks a recipe for you, they way you want Recipe: A set of instructions for preparing a particular dish Cookbooks: Manages your recipe Node: Configuration of your recipe Knife: A tool to help you cook
  • 6. Getting started Root / -- cookbooks -- node.json -- run_recipies.rb Run the script $ sudo chef-solo -c run_recipies.rb -j node.json
  • 7. Getting started ● cookbooks ○ mysql ■ recipes ● default.rb ● another_recipie.rb ■ templates ● my.cnf ■ files
  • 8. Using existing repo Target: setup mysql with chef solo ● Pull the mysql cookbook in the cookbooks folder ● Change the node.json to serve our need
  • 9. Using existing repo Sample node.json { "run_list": [ "recipe[mysql::server]", "recipe[mysql::client]" ], "mysql": { "server_root_password": "", "server_repl_password": "", "server_debian_password": "", "bind_address": "0.0.0.0", "allow_remote_root": true } }
  • 10. Using existing repo Run the script $ sudo chef-solo -c run_recipies.rb -j node.json RE Run the script any number of time $ sudo chef-solo -c run_recipies.rb -j node.json And it is safe :D
  • 11. Creating own recipe Create folder structure as follows chef/ ├── cookbooks | └── mychefrepo | ├── recipes | | └── default.rb | ├── templates | └── files └── solo.rb
  • 12. default.rb 1 begin 2 require 'mysql' 3 rescue LoadError 4 Chef::Log.info("Missing gem 'mysql'") 5 end 6 7 ruby_block "Create replication user and database" do 8 block do 9 m = Mysql.new('localhost', "root", node[:mysql][:server_root_password]) 10 11 command = %Q{ 12 GRANT ALL ON *.* 13 TO '#{node[:mysql][:server_replication][:database_user]}'@'%' 14 IDENTIFIED BY 15 '#{node[:mysql][:server_replication][:database_password]}'; 16 } 17 m.query(command) 18 m.query('FLUSH PRIVILEGES') 19 end 20 # only execute if mysql is running 21 only_if "pgrep 'mysqld$'" 22 end
  • 13. default.rb 1 gem_package "bundler" 2 begin 3 require 'mysql' 4 rescue LoadError 5 Chef::Log.info("Missing gem 'mysql'") 6 end
  • 14. default.rb 7 ruby_block "Create replication user and database" do 8 block do 9 m = Mysql.new('localhost', "root", node[:mysql][:server_root_password]) 10 11 command = %Q{ 12 GRANT ALL ON *.* 13 TO '#{node[:mysql][:server_replication][:database_user]}'@'%' 14 IDENTIFIED BY 15 '#{node[:mysql][:server_replication][:database_password]}'; 16 } 17 m.query(command) 18 m.query('FLUSH PRIVILEGES') 19 end 20 # only execute if mysql is running 21 only_if "pgrep 'mysqld$'" 22 end
  • 15. node.json { "run_list": [ "recipe[mysql::server]", "recipe[mysql::client]", "recipe[mychefrepo]" ], "mysql": { "server_root_password": "", "server_repl_password": "", "server_debian_password": "", "bind_address": "0.0.0.0", "allow_remote_root": true, "server_replication": { "database": "moteel_production", "database_user": "repl", "database_password": "repl"} }}
  • 16. Run the script Run the script $ sudo chef-solo -c run_recipies.rb -j node.json
  • 17. Commonly used resources %w{rover fido bubbers}.each do |pet_name| execute "feed_pet_#{pet_name}" do command "echo 'Feeding: #{pet_name}'; touch '/tmp/#{pet_name}'" not_if { ::File.exists?("/tmp/#{pet_name}")} end end gem_package "bundler" do options(:prerelease => true, :format_executable => false) end package "tar" do version "1.16.1-1" action :install end
  • 18. Commonly used resources %w{rover fido bubbers}.each do |pet_name| execute "feed_pet_#{pet_name}" do command "echo 'Feeding: #{pet_name}'; touch '/tmp/#{pet_name}'" not_if { ::File.exists?("/tmp/#{pet_name}")} end end gem_package "bundler" do options(:prerelease => true, :format_executable => false) end package "tar" do version "1.16.1-1" action :install end
  • 19. Commonly used resources directory "/tmp/folder" do owner "root" group "root" mode 0755 action :create end cookbook_file "/usr/local/bin/apache2_module_conf_generate.pl" do source "apache2_module_conf_generate.pl" mode 0755 owner "root" end template "/tmp/somefile" do mode 00644 source "somefile.erb" not_if { node[:some_value] } end
  • 20. Deploying to multiple servers Problems ● Different servers might need different node. json file to configure them ● You have to ssh into different servers and and set up the prerequisites for chef
  • 21. Deploying to multiple servers Solution 1. Use chef server ○ Need to buy chef server service OR ○ Maintain a chef server of your own OR 2. Use scripts like capistrano and some ruby to deploy from development machine
  • 22. Using Capistrano set :user, '...' set :password, '........' set :main_server, '***.**.***.**' server main_server, :app, :primary => true namespace :setup do task :env, :depends => ["setup:install_prerequisite"], :roles => :app do setup.install_prerequisite cd_run "ruby change_local.rb #{user} #{main_server}" cd_run "#{try_sudo} ./setup_base.sh" cd_run "#{try_sudo} chef-solo -c run_recipies.rb -j local.json" end end
  • 23. Using Capistrano namespace :setup do task :install_prerequisite, :roles => :app do run "mkdir -p /home/#{user}/.ssh" upload "deploy_keys/id_rsa", "/home/#{user}/.ssh/id_rsa" upload "deploy_keys/id_rsa.pub", "/home/#{user}/.ssh/id_rsa.pub" run "#{try_sudo} apt-get update" run "#{try_sudo} apt-get -y install aptitude git unzip" begin run "cd /home/#{user} && git clone git@git.tasawr.com:ashraf/moteel-setup.git" rescue cd_run "git pull origin master" end run "#{try_sudo} aptitude install -y ruby1.9.1 ruby1.9.1-dev make" run "#{try_sudo} gem install --no-rdoc --no-ri chef" end end def cd_run(cmd) run "cd /home/#{user}/moteel-setup && #{cmd}" end
  • 24. Using Capistrano ruby_block "share the torrent file" do block do f = File.open(node['bittorrent']['torrent'],'rb') #read the .torrent file and base64 encode it enc = Base64.encode64(f.read) data = { 'id'=>bittorrent_item_id(node['bittorrent']['file']), 'seed'=>node.ipaddress, 'torrent'=>enc } item = Chef::DataBagItem.new item.data_bag('bittorrent') item.raw_data = data item.save end action :nothing subscribes :create, resources(:bittorrent_torrent => node['bittorrent']['torrent']) end
  • 25. Deploying to multiple servers 1. Configure capistrano with the server information 2. Install prerequisites with capistrano 3. Run a ruby or any program to update the node.json file from the capistrano information 4. Go get yourself a cup of coffee
  • 26. Wait for the script to complete
  • 27. References ● Quick start ● Chef DSL ● Chef resources ● Some cookbooks
  • 28. Author A.K.M. Ashrafuzzaman Lead Software Engineer, Tasawr Interactive. www.ashrafuzzaman.com ashraf@tasawr.com