SlideShare uma empresa Scribd logo
1 de 32
Baixar para ler offline
Leonardo Martins

leonardo.martins@walmart.com
Menu do dia
Conhecendo o Chef.
O que faz o Chef ?
Conceitos da infra-estrutura.
Conceitos do Chef.
Mão na massa.
Leonardo Martins - leonardo.martins@walmart.com
Conhecendo o Chef
Gerenciador de configuração.
Infraestrutura como código.
Manter o parque homogênio e atualizado.
Leonardo Martins - leonardo.martins@walmart.com
Conhecendo o Chef
Leonardo Martins - leonardo.martins@walmart.com
Conhecendo o Chef
CHEF - Server
Leonardo Martins - leonardo.martins@walmart.com
Quais são os pratos?
Criar arquivos e diretórios.
Manipula conteúdo de arquivos.
Criar usuários e grupos.
Muda a permissão de arquivos e diretórios.
Instala e remove pacotes.
Cron
Mount
Link simbólico
Leonardo Martins - leonardo.martins@walmart.com
Quais são os pratos?
Criar arquivos e diretórios.
Manipula conteúdo de arquivos.
!!!!
file '/tmp/bacon' do!
content 'bacon is delicious!'!
end!
!
directory '/opt/my/deep/directory' do!
owner 'root'!
group 'root'!
mode '0644'!
recursive true!
end!
!
!
Leonardo Martins - leonardo.martins@walmart.com
Quais são os pratos?
Criar usuários e grupos.
Muda a permissão de arquivos e diretórios.
user 'bacon'!
group ‘bacon' !
!
template ‘/opt/blacklist/blacklist' do!
source ‘my_blacklist.conf.erb'!
owner 'root'!
group 'root'!
mode '0644'!
end!
!
Leonardo Martins - leonardo.martins@walmart.com
Quais são os pratos?
!
!
!
!
package ‘apache2'!
package ‘nginx'!
!
cron 'weekly_restart' do!
weekday '1'!
minute '0'!
hour '0'!
command 'sudo reboot'!
end!
!
execute 'write status' do!
command 'echo "delicious" > /tmp/bacon'!
end!
Instala e remove pacotes.
Crontab
Executa shell script
Leonardo Martins - leonardo.martins@walmart.com
Temperos mais forte!
Roda comandos em ‘batch’
Faz pesquisa baseada em nome,role, OS.
Leonardo Martins - leonardo.martins@walmart.com
Conceitos da infra do Chef
Cookbook
Atributos Receitas Templates Bibliotecas Arquivos
CHEF - Server
Leonardo Martins - leonardo.martins@walmart.com
Mão na massa
Leonardo Martins - leonardo.martins@walmart.com
chef-apply receita.rb --log_level info!
chef-client
Mão na massa
Amigos para sempre!!! BFF!!!
https://docs.chef.io/chef/resources.html!
https://www.youtube.com/user/Opscode
Leonardo Martins - leonardo.martins@walmart.com
file "/tmp/hello.txt" do!
! content 'Welcome to Chef'!
end!
file "/tmp/hello.txt" do!
! content 'Welcome to Chef’!
! mode "0644"!
! owner "root"!
! group "root"!
! action :create /// action :delete!
end
%w{/tmp/hello.txt /tmp/hello_world.txt /tmp/world_of_warcraft.txt}.each do |files|!
! file “#{files}“ do!
! ! content 'Welcome to Chef’!
! ! mode “0644"!
! ! owner “root”!
! ! group “root”!
! ! action :create!
! end!
end
Mão na massa
Leonardo Martins - leonardo.martins@walmart.com
directory “/tmp/foo" do!
mode '0755'!
action :create!
end
Mão na massa
directory “/tmp/foo/bar/brazil" do!
mode '0755'!
action :create!
end
Leonardo Martins - leonardo.martins@walmart.com
directory “/tmp/foo" do!
mode '0755'!
action :create!
end
Mão na massa
directory “/tmp/foo/bar/brazil" do!
mode '0755'!
action :create!
end
directory “/tmp/foo/bar/brazil" do!
mode '0755'!
action :create!
recursive true!
end
directory “/tmp/foo/bar/brazil" do!
mode '0755'!
action :create!
owner "root"!
group "root"!
recursive true!
end
Leonardo Martins - leonardo.martins@walmart.com
- Criar os diretórios /var/log/wm-security-{1,2,3}/logs-dump/
Permissões - 0644
!
- Criar um arquivo /var/log/wm-security-3/logs-dump/wm-
test.txt
!
Permissões - 0600
Escrever dentro do arquivo “TOP SECRET”
Mão na massa
Leonardo Martins - leonardo.martins@walmart.com
package "nginx"!
package "vim"!
package “telnet" !
!
package “nginx” do!
! action :install!
! not_if "rpm -q nginx“ !
end!
!
package “squid” do!
! action :install!
! version “3.1.10-29.el6“!
! not_if "rpm -q squid“ !
end!
!
service "nginx" do!
! action [ :enable, :start ]!
end!
Mão na massa
Leonardo Martins - leonardo.martins@walmart.com
package "vim"!
package “telnet" !
!
package “nginx” do!
! action :install!
! not_if "rpm -q nginx“ !
end!
!
package “squid” do!
! action :install!
! version “3.1.10-29.el6“!
! not_if "rpm -q squid“ !
end!
!
service "nginx" do!
! action [ :enable, :start ]!
end!
!
file "/usr/share/nginx/html/index.html" do!
! content ‘NGINX de SEC '!
! mode "0644"!
! owner "root"!
! group "root"!
! action :create !
end!
Mão na massa
Leonardo Martins - leonardo.martins@walmart.com
Mão na massa
cron “Sar_monitor" do!
! minute "*/5”!
! hour "*”!
command “sar -u 1 3 >>/tmp/sar_log“!
end
Leonardo Martins - leonardo.martins@walmart.com
user "bacon" do!
supports :manage_home => true!
comment "Random User"!
uid 1234!
gid "users"!
home "/home/bacon"!
shell "/bin/bash"!
password "$1$JJJJJJJJJJJJJs."!
end!
!
!
$ echo "your_password"|openssl passwd -1 -stdin!
!
Mão na massa
Leonardo Martins - leonardo.martins@walmart.com
user "bacon"!
!!!
group “bacon"!
!
Mão na massa
Leonardo Martins - leonardo.martins@walmart.com
user "bacon" do!
supports :manage_home => true!
comment "Random User"!
uid 1234!
gid "users"!
home "/home/bacon"!
shell "/bin/bash"!
password "$1$JJJJJJJJJJJJJs."!
end!
!!
group "bacon" do!
action :modify!
members "zabbix"!
append true!
end!
Mão na massa
$ echo "your_password"|openssl passwd -1 -stdin!
!
Leonardo Martins - leonardo.martins@walmart.com
- Instalar o httpd
- Garantir que o httpd sempre esteja rodando
- Trocar o conteúdo do /var/www/html/index.html
- Criar o usuário spiderman, colocar uma senha.
- Criar o grupo marvel
- Colocar spiderman no grupo marvel
- Cron para monitorar o uso do disco (a cada 5 min.)
Mão na massa
Leonardo Martins - leonardo.martins@walmart.com
Café?!
Leonardo Martins - leonardo.martins@walmart.com
Cookbook
Atributos Receitas Templates Bibliotecas Arquivos
Mão na massa
Leonardo Martins - leonardo.martins@walmart.com
Mão na massa
knife cookbook create wm-lml-chefclass!
Leonardo Martins - leonardo.martins@walmart.com
file "/tmp/hello.txt" do!
! content 'Welcome to Chef’!
! mode "0644"!
! owner "root"!
! group "root"!
! action :create!
end
Mão na massa
template "/tmp/hello.txt" do!
! source ‘hello.txt.erb’!
! mode "0644"!
! owner "root"!
! group "root"!
end
Leonardo Martins - leonardo.martins@walmart.com
Mão na massa
template "/tmp/hello.txt" do!
! source ‘hello.txt.erb’!
! mode "0644"!
! owner "root"!
! group "root"!
! variable({!
:msg => node[‘wm-lml-chefclass‘]['msg'],!
})!
end
>>hello.txt.erb!
!
Olá <%= @msg %>, tudo bem?!
!
<%= node["hostname"] %>!
>>/attributes/default.rb!
!
default [:wm_lml_chefclass][:msg]= "mundo"
Leonardo Martins - leonardo.martins@walmart.com
Mão na massa
template “/etc/nginx/conf.d/chef_vh.conf” do!
variables({!
:vhost_name => node[‘wm-lml-chefclass‘]['vhost'],!
})!
owner "root"!
mode "0640"!
source “chef_vh.conf.erb”!
notifies :restart, 'service[nginx]', :delayed!
end
server {!
listen 80;!
server_name <%= @vhost_name %>;!
!
location / {!
root /usr/share/nginx/html;!
index index.html index.htm;!
}!
!
}
>>/attributes/default.rb!
!
default [:wm_lml_chefclass][:vhost]= "chef-class.qa.domain.intra"
Leonardo Martins - leonardo.martins@walmart.com
+10%
https://learn.chef.io/
http://docs.chef.io/chef/resources.html
http://docs.chef.io/
Leonardo Martins - leonardo.martins@walmart.com
Obrigado!!

Mais conteúdo relacionado

Destaque

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Training Opscode Chef

  • 2. Menu do dia Conhecendo o Chef. O que faz o Chef ? Conceitos da infra-estrutura. Conceitos do Chef. Mão na massa. Leonardo Martins - leonardo.martins@walmart.com
  • 3. Conhecendo o Chef Gerenciador de configuração. Infraestrutura como código. Manter o parque homogênio e atualizado. Leonardo Martins - leonardo.martins@walmart.com
  • 4. Conhecendo o Chef Leonardo Martins - leonardo.martins@walmart.com
  • 5. Conhecendo o Chef CHEF - Server Leonardo Martins - leonardo.martins@walmart.com
  • 6. Quais são os pratos? Criar arquivos e diretórios. Manipula conteúdo de arquivos. Criar usuários e grupos. Muda a permissão de arquivos e diretórios. Instala e remove pacotes. Cron Mount Link simbólico Leonardo Martins - leonardo.martins@walmart.com
  • 7. Quais são os pratos? Criar arquivos e diretórios. Manipula conteúdo de arquivos. !!!! file '/tmp/bacon' do! content 'bacon is delicious!'! end! ! directory '/opt/my/deep/directory' do! owner 'root'! group 'root'! mode '0644'! recursive true! end! ! ! Leonardo Martins - leonardo.martins@walmart.com
  • 8. Quais são os pratos? Criar usuários e grupos. Muda a permissão de arquivos e diretórios. user 'bacon'! group ‘bacon' ! ! template ‘/opt/blacklist/blacklist' do! source ‘my_blacklist.conf.erb'! owner 'root'! group 'root'! mode '0644'! end! ! Leonardo Martins - leonardo.martins@walmart.com
  • 9. Quais são os pratos? ! ! ! ! package ‘apache2'! package ‘nginx'! ! cron 'weekly_restart' do! weekday '1'! minute '0'! hour '0'! command 'sudo reboot'! end! ! execute 'write status' do! command 'echo "delicious" > /tmp/bacon'! end! Instala e remove pacotes. Crontab Executa shell script Leonardo Martins - leonardo.martins@walmart.com
  • 10. Temperos mais forte! Roda comandos em ‘batch’ Faz pesquisa baseada em nome,role, OS. Leonardo Martins - leonardo.martins@walmart.com
  • 11. Conceitos da infra do Chef Cookbook Atributos Receitas Templates Bibliotecas Arquivos CHEF - Server Leonardo Martins - leonardo.martins@walmart.com
  • 12. Mão na massa Leonardo Martins - leonardo.martins@walmart.com
  • 13. chef-apply receita.rb --log_level info! chef-client Mão na massa Amigos para sempre!!! BFF!!! https://docs.chef.io/chef/resources.html! https://www.youtube.com/user/Opscode Leonardo Martins - leonardo.martins@walmart.com
  • 14. file "/tmp/hello.txt" do! ! content 'Welcome to Chef'! end! file "/tmp/hello.txt" do! ! content 'Welcome to Chef’! ! mode "0644"! ! owner "root"! ! group "root"! ! action :create /// action :delete! end %w{/tmp/hello.txt /tmp/hello_world.txt /tmp/world_of_warcraft.txt}.each do |files|! ! file “#{files}“ do! ! ! content 'Welcome to Chef’! ! ! mode “0644"! ! ! owner “root”! ! ! group “root”! ! ! action :create! ! end! end Mão na massa Leonardo Martins - leonardo.martins@walmart.com
  • 15. directory “/tmp/foo" do! mode '0755'! action :create! end Mão na massa directory “/tmp/foo/bar/brazil" do! mode '0755'! action :create! end Leonardo Martins - leonardo.martins@walmart.com
  • 16. directory “/tmp/foo" do! mode '0755'! action :create! end Mão na massa directory “/tmp/foo/bar/brazil" do! mode '0755'! action :create! end directory “/tmp/foo/bar/brazil" do! mode '0755'! action :create! recursive true! end directory “/tmp/foo/bar/brazil" do! mode '0755'! action :create! owner "root"! group "root"! recursive true! end Leonardo Martins - leonardo.martins@walmart.com
  • 17. - Criar os diretórios /var/log/wm-security-{1,2,3}/logs-dump/ Permissões - 0644 ! - Criar um arquivo /var/log/wm-security-3/logs-dump/wm- test.txt ! Permissões - 0600 Escrever dentro do arquivo “TOP SECRET” Mão na massa Leonardo Martins - leonardo.martins@walmart.com
  • 18. package "nginx"! package "vim"! package “telnet" ! ! package “nginx” do! ! action :install! ! not_if "rpm -q nginx“ ! end! ! package “squid” do! ! action :install! ! version “3.1.10-29.el6“! ! not_if "rpm -q squid“ ! end! ! service "nginx" do! ! action [ :enable, :start ]! end! Mão na massa Leonardo Martins - leonardo.martins@walmart.com
  • 19. package "vim"! package “telnet" ! ! package “nginx” do! ! action :install! ! not_if "rpm -q nginx“ ! end! ! package “squid” do! ! action :install! ! version “3.1.10-29.el6“! ! not_if "rpm -q squid“ ! end! ! service "nginx" do! ! action [ :enable, :start ]! end! ! file "/usr/share/nginx/html/index.html" do! ! content ‘NGINX de SEC '! ! mode "0644"! ! owner "root"! ! group "root"! ! action :create ! end! Mão na massa Leonardo Martins - leonardo.martins@walmart.com
  • 20. Mão na massa cron “Sar_monitor" do! ! minute "*/5”! ! hour "*”! command “sar -u 1 3 >>/tmp/sar_log“! end Leonardo Martins - leonardo.martins@walmart.com
  • 21. user "bacon" do! supports :manage_home => true! comment "Random User"! uid 1234! gid "users"! home "/home/bacon"! shell "/bin/bash"! password "$1$JJJJJJJJJJJJJs."! end! ! ! $ echo "your_password"|openssl passwd -1 -stdin! ! Mão na massa Leonardo Martins - leonardo.martins@walmart.com
  • 22. user "bacon"! !!! group “bacon"! ! Mão na massa Leonardo Martins - leonardo.martins@walmart.com
  • 23. user "bacon" do! supports :manage_home => true! comment "Random User"! uid 1234! gid "users"! home "/home/bacon"! shell "/bin/bash"! password "$1$JJJJJJJJJJJJJs."! end! !! group "bacon" do! action :modify! members "zabbix"! append true! end! Mão na massa $ echo "your_password"|openssl passwd -1 -stdin! ! Leonardo Martins - leonardo.martins@walmart.com
  • 24. - Instalar o httpd - Garantir que o httpd sempre esteja rodando - Trocar o conteúdo do /var/www/html/index.html - Criar o usuário spiderman, colocar uma senha. - Criar o grupo marvel - Colocar spiderman no grupo marvel - Cron para monitorar o uso do disco (a cada 5 min.) Mão na massa Leonardo Martins - leonardo.martins@walmart.com
  • 25. Café?! Leonardo Martins - leonardo.martins@walmart.com
  • 26. Cookbook Atributos Receitas Templates Bibliotecas Arquivos Mão na massa Leonardo Martins - leonardo.martins@walmart.com
  • 27. Mão na massa knife cookbook create wm-lml-chefclass! Leonardo Martins - leonardo.martins@walmart.com
  • 28. file "/tmp/hello.txt" do! ! content 'Welcome to Chef’! ! mode "0644"! ! owner "root"! ! group "root"! ! action :create! end Mão na massa template "/tmp/hello.txt" do! ! source ‘hello.txt.erb’! ! mode "0644"! ! owner "root"! ! group "root"! end Leonardo Martins - leonardo.martins@walmart.com
  • 29. Mão na massa template "/tmp/hello.txt" do! ! source ‘hello.txt.erb’! ! mode "0644"! ! owner "root"! ! group "root"! ! variable({! :msg => node[‘wm-lml-chefclass‘]['msg'],! })! end >>hello.txt.erb! ! Olá <%= @msg %>, tudo bem?! ! <%= node["hostname"] %>! >>/attributes/default.rb! ! default [:wm_lml_chefclass][:msg]= "mundo" Leonardo Martins - leonardo.martins@walmart.com
  • 30. Mão na massa template “/etc/nginx/conf.d/chef_vh.conf” do! variables({! :vhost_name => node[‘wm-lml-chefclass‘]['vhost'],! })! owner "root"! mode "0640"! source “chef_vh.conf.erb”! notifies :restart, 'service[nginx]', :delayed! end server {! listen 80;! server_name <%= @vhost_name %>;! ! location / {! root /usr/share/nginx/html;! index index.html index.htm;! }! ! } >>/attributes/default.rb! ! default [:wm_lml_chefclass][:vhost]= "chef-class.qa.domain.intra" Leonardo Martins - leonardo.martins@walmart.com