SlideShare a Scribd company logo
Начала DevOps: Opscode Chef
Day 3

Andriy Samilyak
samilyak@gmail.com
skype: samilyaka
Goals
●

New resources: file, cookbook_file

●

Berkshelf

●

DataBags

●

Deployment with Chef

●

Environments
Password protection
We need to close our site by
login/password in order to keep it private
admin/password
Password protection
HTTP Basic Authentication
<Directory <%= node['apache']['docroot_dir'] %>/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
AuthType Basic
AuthName "Restricted Files"
AuthBasicProvider file
AuthUserFile <%= node['apache']['dir'] %>/htpasswd
Require valid-user
</Directory>

Copy/paste from http://goo.gl/6sEYT5
htpasswd
We need this contents to be in
node['apache']['dir']/htpasswd
admin:$apr1$ejZO6aAi$9zUZFyNxkX7pHOfqnjs8/0

Copy/paste from http://goo.gl/6sEYT5
Google it!
'chef resource file'
Putting file to server #1
../cookbooks/webserver/recipes/default.rb

file "#{node['apache']['dir']}/htpasswd" do
owner 'root'
group node['apache']['root_group']
mode '0644'
backup false
content "admin:
$apr1$ejZO6aAi$9zUZFyNxkX7pHOfqnjs8/0"
end
Putting file to server #2
●

'content' attribute is not really scalable – what if
we need 2Kb of text inside?

●

Lets first comment out with # content attribute

●

create file
../cookbooks/webserver/files/default/htpasswd

●

and put root (not admin!) and password hash to it

●

Change resource from 'file' to 'cookbook_file'
Putting file to server #2
../cookbooks/webserver/recipes/default.rb
cookbook_file "#{node['apache']['dir']}/htpasswd" do
owner 'root'
group node['apache']['root_group']
mode '0644'
backup false
end
Welcome Berks-way!
gem install berkshelf
Test it with “berks -v”
-------------------------------------------------------------On Windows you'll need to add to chefrepo/.berkshelf/config.json:
"ssl": {
"verify": false
}
Move out community cookbooks
●

Add a line to Berksfile:
cookbook “cookbook” path: cookbooks/webserver

●

berks install ← download cookbook to local folder

●

berks upload ← upload cookbooks to Chef Server

●

remove 'apache2' folder from chef_repo
Where is cookbook now anyway?
Well done! Lets put it to git
git commit -a -m “Initial commit”
git push origin master
Berks locations
●

site:
cookbook "artifact", site:
"http://cookbooks.opscode.com/api/v1/cookbooks"
cookbook "artifact", site: :opscode

●

git:
cookbook "mysql", git: "https://github.com/opscodecookbooks/mysql.git", branch: "foodcritic"
Lets do it better now!

https://github.com/Youscribe/htpasswdcookbook
Goal: specify user/pass with cookbook
attributes
Copy/paste from http://goo.gl/6sEYT5
New cookbook in Berksfile
cookbook "htpasswd", git:
https://github.com/Youscribe/htpasswdcookbook.git
Example:
htpasswd "/etc/apache2/htpasswd" do
user node['webserver']['auth_user']
password node['webserver']['auth_pass']
end
Htpasswd - review
●

webserver/metadata.rb: add dependency

●

recipes/default.rb: add resource httpasswd

●

attributes/default.rb: add two attributes

●

berks update & berks upload
Managing users access

Site

User1/pass
User2/pass
User3/pass

Site Backend

User1/pass
User3/pass

Store Backend

User3/pass
DataBags
●

Reusable data containers

●

JSON

●

Search API
Managing user access - Plan
●

Keep user/pass with granted nodes

●

Find all users for current node

●

Generate htpasswd by adding hash for
each user
DataBags as files
chef_repo
data_bags
htpasswd
user1.json
user2.json
user3.json
user1.json
{
"id": "user1",
"pass": "password",
"nodes" : ["yournode1", "yournode2"]
}
Data bag CLI
knife data bag create htpasswd
knife data bag from file htpasswd user1.json
knife data bag from file htpasswd
data_bags/htpasswd/*
knife search htpasswd "(id:user1)"
knife search htpasswd "(nodes:yournode)"
Search API
search(:htpasswd, "nodes:#{node.name}") do |user|
#add line to file user['pass']
end
Just an example of solution...
file "#{node['apache']['dir']}/htpasswd" do
action :delete
end
search(:htpasswd, "nodes:#{node.name}") do |user|
htpasswd "#{node['apache']['dir']}/htpasswd" do
user user['id']
password user['pass']
notifies :reload, 'service[apache2]'
end
end

More Related Content

ODP
Chef training Day5
ODP
Chef training Day4
ODP
Chef training - Day2
PDF
Infrastructure = Code
PPTX
NLIT 2011: Chef & Capistrano
KEY
Cooking with Chef
PDF
Getting Started with Ansible
PPTX
Cook Infrastructure with chef -- Justeat.IN
Chef training Day5
Chef training Day4
Chef training - Day2
Infrastructure = Code
NLIT 2011: Chef & Capistrano
Cooking with Chef
Getting Started with Ansible
Cook Infrastructure with chef -- Justeat.IN

What's hot (20)

PDF
Cookbook testing with KitcenCI and Serverrspec
PDF
Docker Docker Docker Chef
PPTX
Orchestration? You Don't Need Orchestration. What You Want is Choreography.
PPTX
What Makes a Good Chef Cookbook? (May 2014 Edition)
PDF
Introduction to chef framework
PDF
Practical Chef and Capistrano for Your Rails App
PDF
Frontend JS workflow - Gulp 4 and the like
PDF
Chef infrastructure as code - paris.rb
PDF
Automating your workflow with Gulp.js
PDF
Deploying Rails Apps with Chef and Capistrano
PPTX
DevOps Hackathon: Session 3 - Test Driven Infrastructure
PDF
Ansible introduction - XX Betabeers Galicia
PPTX
Vagrant introduction for Developers
PDF
Using Test Kitchen for testing Chef cookbooks
PDF
A quick intro to Ansible
PDF
Infrastructure = code - 1 year later
PPTX
Ansible intro
PDF
Cookbook refactoring & abstracting logic to Ruby(gems)
PDF
Cloud Automation with Opscode Chef
PPTX
DevOps Hackathon - Session 1: Vagrant
Cookbook testing with KitcenCI and Serverrspec
Docker Docker Docker Chef
Orchestration? You Don't Need Orchestration. What You Want is Choreography.
What Makes a Good Chef Cookbook? (May 2014 Edition)
Introduction to chef framework
Practical Chef and Capistrano for Your Rails App
Frontend JS workflow - Gulp 4 and the like
Chef infrastructure as code - paris.rb
Automating your workflow with Gulp.js
Deploying Rails Apps with Chef and Capistrano
DevOps Hackathon: Session 3 - Test Driven Infrastructure
Ansible introduction - XX Betabeers Galicia
Vagrant introduction for Developers
Using Test Kitchen for testing Chef cookbooks
A quick intro to Ansible
Infrastructure = code - 1 year later
Ansible intro
Cookbook refactoring & abstracting logic to Ruby(gems)
Cloud Automation with Opscode Chef
DevOps Hackathon - Session 1: Vagrant
Ad

Viewers also liked (19)

PDF
Osaaminen uuden yrityksen johtajan näkökulmasta
PDF
Powerful Ways To End Emails and Blog Posts
PPT
Proxecto 6º o medio no que vivimos
PDF
NLP meetup 2016.10.05 - Szekeres Péter: Neticle
PDF
Presentation1
PPT
Универсальный энергосберегающий режущий аппарат
PDF
קורס מגיק למפתחים
PPTX
Some Notes On "Inclusion" - Pat Kane for Creative Scotland
PDF
Ux paper prototyping
PDF
Philadelphia Best Places to Work Roadshow | OpenTable
PDF
Daily Newsletter: 16th December, 2010
PDF
Chef training - Day1
PPTX
How effective is the combination of your main
PPT
производство биомелиоранта
PPTX
Nuevas tecnologías de la
PPT
Customer service communities
PPT
EVALUATION QUESTION: 05
PDF
Communitymanager
PPTX
Wykładzina vol. 14 Teatr Narodowy Opera Narodowa
Osaaminen uuden yrityksen johtajan näkökulmasta
Powerful Ways To End Emails and Blog Posts
Proxecto 6º o medio no que vivimos
NLP meetup 2016.10.05 - Szekeres Péter: Neticle
Presentation1
Универсальный энергосберегающий режущий аппарат
קורס מגיק למפתחים
Some Notes On "Inclusion" - Pat Kane for Creative Scotland
Ux paper prototyping
Philadelphia Best Places to Work Roadshow | OpenTable
Daily Newsletter: 16th December, 2010
Chef training - Day1
How effective is the combination of your main
производство биомелиоранта
Nuevas tecnologías de la
Customer service communities
EVALUATION QUESTION: 05
Communitymanager
Wykładzina vol. 14 Teatr Narodowy Opera Narodowa
Ad

Similar to Chef training - Day3 (20)

PDF
IT Automation with Chef
PDF
Chef - Administration for programmers
PDF
Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...
PDF
PPTX
London Community Summit 2016 - Fresh New Chef Stuff
PPTX
Chef introduction
PDF
Node setup, resource, and recipes - Fundamentals Webinar Series Part 2
PDF
Introduction to Cooking with Chef
PDF
MadridDevops September 2014: "From chef09 to chef11, one approach to devops"
PPTX
Chef advance
PPTX
Chef advance
KEY
Chef 0.8, Knife and Amazon EC2
PDF
Introduction to Chef - April 22 2015
PDF
Cooking Perl with Chef: Real World Tutorial with Jitterbug
PDF
Cloud Automation with Opscode Chef
PDF
Chef conf-2014
PDF
The Berkshelf Way
PPTX
Chef + AWS + CodeIgniter
PPTX
Kickstarter - Chef Opswork
PPTX
Chef Jumpstart
IT Automation with Chef
Chef - Administration for programmers
Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...
London Community Summit 2016 - Fresh New Chef Stuff
Chef introduction
Node setup, resource, and recipes - Fundamentals Webinar Series Part 2
Introduction to Cooking with Chef
MadridDevops September 2014: "From chef09 to chef11, one approach to devops"
Chef advance
Chef advance
Chef 0.8, Knife and Amazon EC2
Introduction to Chef - April 22 2015
Cooking Perl with Chef: Real World Tutorial with Jitterbug
Cloud Automation with Opscode Chef
Chef conf-2014
The Berkshelf Way
Chef + AWS + CodeIgniter
Kickstarter - Chef Opswork
Chef Jumpstart

More from Andriy Samilyak (12)

PPTX
Kaizen Magento Support - 2
ODP
Kaizen Magento support
PDF
Amazon Cognito + Lambda + S3 + IAM
PPTX
MageClinic: Affiliative program
PPTX
Magento - choosing Order Management SaaS
PPTX
TOCAT Introduction (English)
PPTX
TOCAT Introduction
ODP
Как мы играли в DevOps и как получился Magento Autoscale
ODP
Magento autoscaling
ODP
DevOps in realtime
ODP
Synthetic web performance testing with Selenium
ODP
DevOps в реальном времени
Kaizen Magento Support - 2
Kaizen Magento support
Amazon Cognito + Lambda + S3 + IAM
MageClinic: Affiliative program
Magento - choosing Order Management SaaS
TOCAT Introduction (English)
TOCAT Introduction
Как мы играли в DevOps и как получился Magento Autoscale
Magento autoscaling
DevOps in realtime
Synthetic web performance testing with Selenium
DevOps в реальном времени

Recently uploaded (20)

PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPT
Teaching material agriculture food technology
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
A Presentation on Artificial Intelligence
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Cloud computing and distributed systems.
PDF
Modernizing your data center with Dell and AMD
PPTX
Big Data Technologies - Introduction.pptx
20250228 LYD VKU AI Blended-Learning.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Dropbox Q2 2025 Financial Results & Investor Presentation
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Teaching material agriculture food technology
The Rise and Fall of 3GPP – Time for a Sabbatical?
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Advanced methodologies resolving dimensionality complications for autism neur...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
A Presentation on Artificial Intelligence
Reach Out and Touch Someone: Haptics and Empathic Computing
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Spectral efficient network and resource selection model in 5G networks
Diabetes mellitus diagnosis method based random forest with bat algorithm
Cloud computing and distributed systems.
Modernizing your data center with Dell and AMD
Big Data Technologies - Introduction.pptx

Chef training - Day3

  • 1. Начала DevOps: Opscode Chef Day 3 Andriy Samilyak samilyak@gmail.com skype: samilyaka
  • 2. Goals ● New resources: file, cookbook_file ● Berkshelf ● DataBags ● Deployment with Chef ● Environments
  • 3. Password protection We need to close our site by login/password in order to keep it private admin/password
  • 4. Password protection HTTP Basic Authentication <Directory <%= node['apache']['docroot_dir'] %>/> Options Indexes FollowSymLinks MultiViews AllowOverride None AuthType Basic AuthName "Restricted Files" AuthBasicProvider file AuthUserFile <%= node['apache']['dir'] %>/htpasswd Require valid-user </Directory> Copy/paste from http://goo.gl/6sEYT5
  • 5. htpasswd We need this contents to be in node['apache']['dir']/htpasswd admin:$apr1$ejZO6aAi$9zUZFyNxkX7pHOfqnjs8/0 Copy/paste from http://goo.gl/6sEYT5
  • 7. Putting file to server #1 ../cookbooks/webserver/recipes/default.rb file "#{node['apache']['dir']}/htpasswd" do owner 'root' group node['apache']['root_group'] mode '0644' backup false content "admin: $apr1$ejZO6aAi$9zUZFyNxkX7pHOfqnjs8/0" end
  • 8. Putting file to server #2 ● 'content' attribute is not really scalable – what if we need 2Kb of text inside? ● Lets first comment out with # content attribute ● create file ../cookbooks/webserver/files/default/htpasswd ● and put root (not admin!) and password hash to it ● Change resource from 'file' to 'cookbook_file'
  • 9. Putting file to server #2 ../cookbooks/webserver/recipes/default.rb cookbook_file "#{node['apache']['dir']}/htpasswd" do owner 'root' group node['apache']['root_group'] mode '0644' backup false end
  • 10. Welcome Berks-way! gem install berkshelf Test it with “berks -v” -------------------------------------------------------------On Windows you'll need to add to chefrepo/.berkshelf/config.json: "ssl": { "verify": false }
  • 11. Move out community cookbooks ● Add a line to Berksfile: cookbook “cookbook” path: cookbooks/webserver ● berks install ← download cookbook to local folder ● berks upload ← upload cookbooks to Chef Server ● remove 'apache2' folder from chef_repo Where is cookbook now anyway?
  • 12. Well done! Lets put it to git git commit -a -m “Initial commit” git push origin master
  • 13. Berks locations ● site: cookbook "artifact", site: "http://cookbooks.opscode.com/api/v1/cookbooks" cookbook "artifact", site: :opscode ● git: cookbook "mysql", git: "https://github.com/opscodecookbooks/mysql.git", branch: "foodcritic"
  • 14. Lets do it better now! https://github.com/Youscribe/htpasswdcookbook Goal: specify user/pass with cookbook attributes Copy/paste from http://goo.gl/6sEYT5
  • 15. New cookbook in Berksfile cookbook "htpasswd", git: https://github.com/Youscribe/htpasswdcookbook.git
  • 16. Example: htpasswd "/etc/apache2/htpasswd" do user node['webserver']['auth_user'] password node['webserver']['auth_pass'] end
  • 17. Htpasswd - review ● webserver/metadata.rb: add dependency ● recipes/default.rb: add resource httpasswd ● attributes/default.rb: add two attributes ● berks update & berks upload
  • 18. Managing users access Site User1/pass User2/pass User3/pass Site Backend User1/pass User3/pass Store Backend User3/pass
  • 20. Managing user access - Plan ● Keep user/pass with granted nodes ● Find all users for current node ● Generate htpasswd by adding hash for each user
  • 23. Data bag CLI knife data bag create htpasswd knife data bag from file htpasswd user1.json knife data bag from file htpasswd data_bags/htpasswd/* knife search htpasswd "(id:user1)" knife search htpasswd "(nodes:yournode)"
  • 24. Search API search(:htpasswd, "nodes:#{node.name}") do |user| #add line to file user['pass'] end
  • 25. Just an example of solution... file "#{node['apache']['dir']}/htpasswd" do action :delete end search(:htpasswd, "nodes:#{node.name}") do |user| htpasswd "#{node['apache']['dir']}/htpasswd" do user user['id'] password user['pass'] notifies :reload, 'service[apache2]' end end