ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
What is Chef?
Infrastructure management framework
?? : ??? polo149278@hotmail.com
1
Information
? Opscode? Chef? ?? ??? ???
??? ???? ????
http://www.opscode.com/chef/
? Author Yukihiko Sawanobori

HiganWorks LLC(Japan)

2
Index
1. Introduction
2. Inventory
3. Convergence

4. Resource Correction
5. Configration Management

(Automaticaly/Configration first)

3
1. Introduction

4
Q. Chef? ???
?? ?? ????

5
A. ????.
??? ?????? ???
?, ??? ??? ????
OPS? ??????.
¡ù???? ?? ?? ?? ???? ??.
6
Q. DevOps?? ?? ???
???,
Developer? Operater?
?? ?? ?? ????
7
A. ??? ???,
OPS? ??? ???
???? ????.
¡ùDevOps? ??? ?? ?? ??? ??.
¡ùOhai? Chef::Providers? ????? ?? ?? ??
? ???.
8
Chef? ?? ??? 1
? ???? ???? ??? ?? ??

? ???? ??? ??? ?? ??? ??
??? ??
? ChefServer? ??? ???? ??.
? ??????? ChefServer? ???.

9
Chef? ?? ??? 2
? Cookbook? ????? ??? ?? ??? ????.
? Role/Node? Override Attribute? ChefServer?? ??

? ??? Cookbook? ????? ???? ??.
? ?? ??? ???? ??? ???? ?? ???

?? ?? ??? ????.
? ??? ?? ????? ?? ???? ChefServer ?
? ?? ????? ??? ?? ?????.

10
2. Inbentory

11
?? ???? ??????
? Chef-Client(Chef-solo)? ???? ??
?? ??? ???? ??? ????
????.
? Chef? ?? ????? ???? ??

?? ??? ???? ???? ??!

12
??? OHAI?.
? Ohai(https://github.com/opscode/ohai)
? quot: Ohai detects data about your
operating system.
? ????: Chef? ??, Ohai? ??(?? ?
?)
http://qiita.com/items/5ce72101f8dee906ccb4
? OS/??? ???? ?? ??? ??
13
OHAI ?? ??,???? ???? ??
# platform [ and platform_version ? ] should be lower case to avoid dealing with RedHat/Redhat/redhat matching
if File.exists?("/etc/oracle-©\release")
contents = File.read("/etc/oracle-©\release").chomp
platform "oracle"
platform_version get_redhatish_version(contents)
elsif File.exists?("/etc/enterprise-©\release")
contents = File.read("/etc/enterprise-©\release").chomp
platform "oracle"
platform_version get_redhatish_version(contents)
elsif File.exists?("/etc/debian_version")
# Ubuntu and Debian both have /etc/debian_version
# Ubuntu should always have a working lsb, debian does not by default
if lsb[:id] =~ /Ubuntu/i
platform "ubuntu"
platform_version lsb[:release]
else
if File.exists?("/usr/bin/raspi-©\config")
platform "raspbian"
else
platform "debian"
end
platform_version File.read("/etc/debian_version").chomp
end
elsif File.exists?("/etc/redhat-©\release")
contents = File.read("/etc/redhat-©\release").chomp
platform get_redhatish_platform(contents)
platform_version get_redhatish_version(contents)
elsif File.exists?("/etc/system-©\release")
contents = File.read("/etc/system-©\release").chomp
platform get_redhatish_platform(contents)
platform_version get_redhatish_version(contents)
elsif File.exists?('/etc/gentoo-©\release')
platform "gentoo"

??? ??? ??
???? ??

14
AWS(EC2) ?? ???? ????!
def has_ec2_mac?
network[:interfaces].values.each do |iface|
unless iface[:arp].nil?
if iface[:arp].value?("fe:ff:ff:ff:ff:ff")
Ohai::Log.debug("has_ec2_mac? == true")
return true
end
end
end
Ohai::Log.debug("has_ec2_mac? == false")
false
end
def looks_like_ec2?
# Try non-©\blocking connect so we don't "block" if
# the Xen environment is *not* EC2
hint?('ec2') || has_ec2_mac? && can_metadata_connect?
(EC2_METADATA_ADDR,80)
end

?? ???? ??

if looks_like_ec2?
Ohai::Log.debug("looks_like_ec2? == true")

15
???? ????
? ??? ?? ???? ? ? ??.
? ??? ?? ??? ? ? ??.
? ?? ??? ?? ??? ??? ? ??.
? Ex) ec2?? IP? ?? public hostname?
?? ??? ???? ?¡­

16
Cookbook DSL ??
package ¡®nginx¡¯ do
action :install
end
?? ??, ??????

? Redhat ????? yum/rpm? ??
? Debian ????? apt/deb? ??
? Solaris ????? pkgin/pkg? ??
Chef::Runner? ?? ??? ?????
nginx? ??? ??? ??? ????.
17
Inventory ??

? Chef-Clinet/Chef-solo? ??? ??
? Chef Server? ??? Inventory?
SearchAPI? ?? ?? ?? ??? ?
? ??

18
3. Convergence

19
? Build / Setup
? Convergence

20
Convergence ?
? Chef??? ?? ?? ???
Convergence(??)??? ??? ??.

? (????) ????? ???? ???
???? ?? ??, Client? ??? ?

? ??? ??? ???? ??? ??
?? ??? ???? ?? ???? ?
? ????.
21
?? ????
? ?? ??? ??? ???? ??? ??
? ??

? ???? ???? ¡¸???¡¹, ? ??? ?
??? ??? ¡°??¡±??.
(¡ùCookbook? ????? ????.)
? ??? Resouce Corection??? ????.

22
4. Resouce Correcton

23
??? ???? ???
Resouce/state?? ??

24
?? ???? ?? RESOURCE? ??
? ??? ?? = ???
? ? : ???

? ?? ???? / ????
? ? : ???
? ???? / ?? ???
? ??
? ???? / ????? / ????
25
Curennt Resouce? New Resouce
1.

Client/Solo? ??? ?
??? ??=New
Resorce

2.

?? ???? ???
=Current Resorce

3.

Current Resorce? ??
? ??

¡ù ???? ?? ??? ?
?

[New Resorce]
File (
:path => ¡°/etc/hoge¡±,
:owner => ¡°root¡±,
:mode => 0644,
:content => ¡°piyo¡±)
[Current Resorce]
File (
:path => ¡°/etc/hoge¡±,
:owner => ¡°root¡±,
:mode => 0600,
:content => ¡°hoge¡±)

26

Converge!
Current Resouce ???? ??
??? ???=PackMan? ??

??? ??? ????.
Chef::Log.debug("#{@new_resource} checking pacman for #{@new_resource.package_name}")
status = popen4("pacman -©\Qi #{@new_resource.package_name}") do |pid, stdin, stdout, stderr|
stdout.each do |line| line.force_encoding(Encoding::UTF_8) if line.respond_to?(:force_encoding)
case line
when /^Version(s?)*: (.+)$/
Chef::Log.debug("#{@new_resource} current version is #{$2}")
@current_resource.version($2)
end

???? ???? ??¡­

27
New Resource ?? ??
???? ?? ??? ??
def install_package(name, version)
run_command_with_systems_locale(
:command => "pacman --sync --noconfirm --noprogressbar#{expand_options(@new_resource.options)} #{name}"
)
end

Cron ?? ??? ?? ?? Source
if @cron_exists
unless cron_different?
Chef::Log.debug("Skipping existing cron entry '#{@new_resource.name}'")
return
end
read_crontab.each_line do |line|
case line.chomp
when "# Chef Name: #{@new_resource.name}"
cron_found = true

28
RESOURCE? ???
? ??? Resouce Correction
? CookBook ???= New Resource

? Current Resouce? New Resource? ?? S
tatus? ??
? = > Client/Solo? ? ??? ???? ??
??, ?? ??? ??? ??, ?? ??
??? ??? ?? ??
29
5. Configration Management
(Automaticaly/Configration First)

30
?? ??? ?????.

31
?? ??? ???
Chef-Server

Chef-Clinet

Node

? Inventory ??/??(Ohai ??)
? ??? ??
? H/W ??

Node

? N/W ??
Attribute Override
Role ???Runlist ??

32
Env / Role? ?? ??
Server? ????? ???? ?? ??

Chef-Server

Node

Node

Recipe[nagios-server]
?Role[Nagis-Client]?? Node? IP? ?
?? ????.
??? ?? Node? Attribute?? ?? ?
?? ??

Recipe[nagios-client]
?Role[Nagis-Server]?? Node? IP??
??? ??
??? ?? ???? ????? ??

Role[Nagios-Server]

Role[Nagios-Client]
33
??? ?? ??? ??
?? ??? ???? ??
(Configuration Management
First)

34
??? Node? Role? ??=???? ??? ??
Chef-Server

Node

New
Node

Role? ??=Server
? ??????.

Node
. Nagios? ?? ??
? ????.

Recipe[nagios-server]

. Role[Nagios-Server]? ?Role[Nagis-Client] ?? Node? IP? ?
Recipe[nagios-client]
?Role[Nagis-Server]?? Node? IP??Client? Node ??? ??? ????.
? ???? ?? ???
??? ??
??? ?? Node? Attribute?? ?? ?
?? ??? ?????.

??? ?? ???? ????? ??

?? ??

Role[Nagios-Server]

Role[Nagios-Client]
35
?? ??=?? ??

? Chef ?? ??? ??=?? ?? ?

?? ?????
? Client ?? ??? ??????.
? ?? ???? ?? ?? ????.

36
???
? Chef? ?? ? ?? ???? ??
???? ?? ?? ???? ???

??? ??.
? Solo? ??? ??? ?? ???
?? ?? ??? ??? ??.
??? Active Directory? ???? ????? ??? ???, ?
? ????.
37

More Related Content

Whatischef korean

  • 1. What is Chef? Infrastructure management framework ?? : ??? polo149278@hotmail.com 1
  • 2. Information ? Opscode? Chef? ?? ??? ??? ??? ???? ???? http://www.opscode.com/chef/ ? Author Yukihiko Sawanobori HiganWorks LLC(Japan) 2
  • 3. Index 1. Introduction 2. Inventory 3. Convergence 4. Resource Correction 5. Configration Management (Automaticaly/Configration first) 3
  • 5. Q. Chef? ??? ?? ?? ???? 5
  • 6. A. ????. ??? ?????? ??? ?, ??? ??? ???? OPS? ??????. ¡ù???? ?? ?? ?? ???? ??. 6
  • 7. Q. DevOps?? ?? ??? ???, Developer? Operater? ?? ?? ?? ???? 7
  • 8. A. ??? ???, OPS? ??? ??? ???? ????. ¡ùDevOps? ??? ?? ?? ??? ??. ¡ùOhai? Chef::Providers? ????? ?? ?? ?? ? ???. 8
  • 9. Chef? ?? ??? 1 ? ???? ???? ??? ?? ?? ? ???? ??? ??? ?? ??? ?? ??? ?? ? ChefServer? ??? ???? ??. ? ??????? ChefServer? ???. 9
  • 10. Chef? ?? ??? 2 ? Cookbook? ????? ??? ?? ??? ????. ? Role/Node? Override Attribute? ChefServer?? ?? ? ??? Cookbook? ????? ???? ??. ? ?? ??? ???? ??? ???? ?? ??? ?? ?? ??? ????. ? ??? ?? ????? ?? ???? ChefServer ? ? ?? ????? ??? ?? ?????. 10
  • 12. ?? ???? ?????? ? Chef-Client(Chef-solo)? ???? ?? ?? ??? ???? ??? ???? ????. ? Chef? ?? ????? ???? ?? ?? ??? ???? ???? ??! 12
  • 13. ??? OHAI?. ? Ohai(https://github.com/opscode/ohai) ? quot: Ohai detects data about your operating system. ? ????: Chef? ??, Ohai? ??(?? ? ?) http://qiita.com/items/5ce72101f8dee906ccb4 ? OS/??? ???? ?? ??? ?? 13
  • 14. OHAI ?? ??,???? ???? ?? # platform [ and platform_version ? ] should be lower case to avoid dealing with RedHat/Redhat/redhat matching if File.exists?("/etc/oracle-©\release") contents = File.read("/etc/oracle-©\release").chomp platform "oracle" platform_version get_redhatish_version(contents) elsif File.exists?("/etc/enterprise-©\release") contents = File.read("/etc/enterprise-©\release").chomp platform "oracle" platform_version get_redhatish_version(contents) elsif File.exists?("/etc/debian_version") # Ubuntu and Debian both have /etc/debian_version # Ubuntu should always have a working lsb, debian does not by default if lsb[:id] =~ /Ubuntu/i platform "ubuntu" platform_version lsb[:release] else if File.exists?("/usr/bin/raspi-©\config") platform "raspbian" else platform "debian" end platform_version File.read("/etc/debian_version").chomp end elsif File.exists?("/etc/redhat-©\release") contents = File.read("/etc/redhat-©\release").chomp platform get_redhatish_platform(contents) platform_version get_redhatish_version(contents) elsif File.exists?("/etc/system-©\release") contents = File.read("/etc/system-©\release").chomp platform get_redhatish_platform(contents) platform_version get_redhatish_version(contents) elsif File.exists?('/etc/gentoo-©\release') platform "gentoo" ??? ??? ?? ???? ?? 14
  • 15. AWS(EC2) ?? ???? ????! def has_ec2_mac? network[:interfaces].values.each do |iface| unless iface[:arp].nil? if iface[:arp].value?("fe:ff:ff:ff:ff:ff") Ohai::Log.debug("has_ec2_mac? == true") return true end end end Ohai::Log.debug("has_ec2_mac? == false") false end def looks_like_ec2? # Try non-©\blocking connect so we don't "block" if # the Xen environment is *not* EC2 hint?('ec2') || has_ec2_mac? && can_metadata_connect? (EC2_METADATA_ADDR,80) end ?? ???? ?? if looks_like_ec2? Ohai::Log.debug("looks_like_ec2? == true") 15
  • 16. ???? ???? ? ??? ?? ???? ? ? ??. ? ??? ?? ??? ? ? ??. ? ?? ??? ?? ??? ??? ? ??. ? Ex) ec2?? IP? ?? public hostname? ?? ??? ???? ?¡­ 16
  • 17. Cookbook DSL ?? package ¡®nginx¡¯ do action :install end ?? ??, ?????? ? Redhat ????? yum/rpm? ?? ? Debian ????? apt/deb? ?? ? Solaris ????? pkgin/pkg? ?? Chef::Runner? ?? ??? ????? nginx? ??? ??? ??? ????. 17
  • 18. Inventory ?? ? Chef-Clinet/Chef-solo? ??? ?? ? Chef Server? ??? Inventory? SearchAPI? ?? ?? ?? ??? ? ? ?? 18
  • 20. ? Build / Setup ? Convergence 20
  • 21. Convergence ? ? Chef??? ?? ?? ??? Convergence(??)??? ??? ??. ? (????) ????? ???? ??? ???? ?? ??, Client? ??? ? ? ??? ??? ???? ??? ?? ?? ??? ???? ?? ???? ? ? ????. 21
  • 22. ?? ???? ? ?? ??? ??? ???? ??? ?? ? ?? ? ???? ???? ¡¸???¡¹, ? ??? ? ??? ??? ¡°??¡±??. (¡ùCookbook? ????? ????.) ? ??? Resouce Corection??? ????. 22
  • 25. ?? ???? ?? RESOURCE? ?? ? ??? ?? = ??? ? ? : ??? ? ?? ???? / ???? ? ? : ??? ? ???? / ?? ??? ? ?? ? ???? / ????? / ???? 25
  • 26. Curennt Resouce? New Resouce 1. Client/Solo? ??? ? ??? ??=New Resorce 2. ?? ???? ??? =Current Resorce 3. Current Resorce? ?? ? ?? ¡ù ???? ?? ??? ? ? [New Resorce] File ( :path => ¡°/etc/hoge¡±, :owner => ¡°root¡±, :mode => 0644, :content => ¡°piyo¡±) [Current Resorce] File ( :path => ¡°/etc/hoge¡±, :owner => ¡°root¡±, :mode => 0600, :content => ¡°hoge¡±) 26 Converge!
  • 27. Current Resouce ???? ?? ??? ???=PackMan? ?? ??? ??? ????. Chef::Log.debug("#{@new_resource} checking pacman for #{@new_resource.package_name}") status = popen4("pacman -©\Qi #{@new_resource.package_name}") do |pid, stdin, stdout, stderr| stdout.each do |line| line.force_encoding(Encoding::UTF_8) if line.respond_to?(:force_encoding) case line when /^Version(s?)*: (.+)$/ Chef::Log.debug("#{@new_resource} current version is #{$2}") @current_resource.version($2) end ???? ???? ??¡­ 27
  • 28. New Resource ?? ?? ???? ?? ??? ?? def install_package(name, version) run_command_with_systems_locale( :command => "pacman --sync --noconfirm --noprogressbar#{expand_options(@new_resource.options)} #{name}" ) end Cron ?? ??? ?? ?? Source if @cron_exists unless cron_different? Chef::Log.debug("Skipping existing cron entry '#{@new_resource.name}'") return end read_crontab.each_line do |line| case line.chomp when "# Chef Name: #{@new_resource.name}" cron_found = true 28
  • 29. RESOURCE? ??? ? ??? Resouce Correction ? CookBook ???= New Resource ? Current Resouce? New Resource? ?? S tatus? ?? ? = > Client/Solo? ? ??? ???? ?? ??, ?? ??? ??? ??, ?? ?? ??? ??? ?? ?? 29
  • 32. ?? ??? ??? Chef-Server Chef-Clinet Node ? Inventory ??/??(Ohai ??) ? ??? ?? ? H/W ?? Node ? N/W ?? Attribute Override Role ???Runlist ?? 32
  • 33. Env / Role? ?? ?? Server? ????? ???? ?? ?? Chef-Server Node Node Recipe[nagios-server] ?Role[Nagis-Client]?? Node? IP? ? ?? ????. ??? ?? Node? Attribute?? ?? ? ?? ?? Recipe[nagios-client] ?Role[Nagis-Server]?? Node? IP?? ??? ?? ??? ?? ???? ????? ?? Role[Nagios-Server] Role[Nagios-Client] 33
  • 34. ??? ?? ??? ?? ?? ??? ???? ?? (Configuration Management First) 34
  • 35. ??? Node? Role? ??=???? ??? ?? Chef-Server Node New Node Role? ??=Server ? ??????. Node . Nagios? ?? ?? ? ????. Recipe[nagios-server] . Role[Nagios-Server]? ?Role[Nagis-Client] ?? Node? IP? ? Recipe[nagios-client] ?Role[Nagis-Server]?? Node? IP??Client? Node ??? ??? ????. ? ???? ?? ??? ??? ?? ??? ?? Node? Attribute?? ?? ? ?? ??? ?????. ??? ?? ???? ????? ?? ?? ?? Role[Nagios-Server] Role[Nagios-Client] 35
  • 36. ?? ??=?? ?? ? Chef ?? ??? ??=?? ?? ? ?? ????? ? Client ?? ??? ??????. ? ?? ???? ?? ?? ????. 36
  • 37. ??? ? Chef? ?? ? ?? ???? ?? ???? ?? ?? ???? ??? ??? ??. ? Solo? ??? ??? ?? ??? ?? ?? ??? ??? ??. ??? Active Directory? ???? ????? ??? ???, ? ? ????. 37