๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
DevOps/IaC ์ž๋™ํ™”

[Puppet] ํผํŽซ ์‹คํ–‰ Resource, Class, Manifest, Node ์‚ฌ์šฉ๋ฒ•

by ๐ŸŒปโ™š 2021. 1. 11.

Puppet ์‹คํ–‰

Puppet์€ ์ž์ฒด์ ์œผ๋กœ ์ œ๊ณต๋˜๋Š” ์–ธ์–ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•œ๋‹ค. ์ž‘์„ฑํ•œ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๊ด€๋ฆฌ๋˜๊ณ  ์žˆ๋Š” Host์— ๋ช…๋ น์„ ๋‚ด๋ฆฌ๊ณ  ์ธํ”„๋ผ๋ฅผ ์ฝ”๋“œํ™”ํ•˜์—ฌ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค. Puppet ์Šคํฌ๋ฆฝํŠธ๋Š” .pp ํ™•์žฅ์ž๋ฅผ ๊ฐ–๊ณ  Manifest ํŒŒ์ผ์ด๋ผ๊ณ ๋„ ํ•œ๋‹ค.

 

์ด๋ฒˆ ๊ธ€์—์„œ๋Š” Puppet Script์—์„œ ์‚ฌ์šฉ๋˜๋Š” Resource, Class, Manifest ๊ทธ๋ฆฌ๊ณ  Node์— ๋Œ€ํ•œ ๊ฐœ๋…์„ ์•Œ์•„๋ณด๊ณ  Nginx๋ฅผ ์„ค์น˜ํ•˜๊ณ  Nginx ํ™ˆํŽ˜์ด์ง€์˜ htmlํŒŒ์ผ์„ ๋ฐ›์•„์™€์„œ index๋กœ ์ •์˜ํ•˜๋Š” ์˜ˆ์ œ๋ฅผ ์ง„ํ–‰ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

Puppet์— ๋Œ€ํ•œ ๊ธฐ๋ณธ ๊ฐœ๋…์ด ํ•„์š”ํ•˜๊ฑฐ๋‚˜ Puppet์„ค์น˜๊ฐ€ ์•ˆ๋˜์–ด์žˆ์œผ๋ฉด ์‹ค์Šตํ™˜๊ฒฝ์„ ์œ„ํ•ด ์•„๋ž˜ ๊ธ€์„ ํ†ตํ•ด ์„ค์น˜๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

 

 

[Puppet] ํผํŽซ ์†Œ๊ฐœ ๋ฐ ์„ค์น˜

Puppet์ด๋ž€?  Puppet์€ ruby๋กœ ๋งŒ๋“ค์–ด์ง„ ์‹œ์Šคํ…œ ๊ด€๋ฆฌ ์ž๋™ํ™” ํˆด์ด๋‹ค. ์ฃผ๋กœ ์„ค์ •, ๊ด€๋ฆฌ, ๋ฐฐํฌ, orchestrate์™€ ๊ฐ™์€ ์ผ์„ ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋œ๋‹ค. puppet์„ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ๋Š” ๋ฐ˜๋ณต๋˜๋Š” ์—…๋ฌด๋ฅผ ์ž๋™ํ™”ํ•˜๊ธฐ ์œ„ํ•จ์ด

myjamong.tistory.com

 

์‹ค์Šตํ™˜๊ฒฝ

os : CentOS 7.8
hostnames:
  master.puppet.test
  node01.puppet.test
  node02.puppet.test
puppet version : 5.5.22

puppet master์™€ 2๊ฐœ์˜ agent๋กœ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค.

 

 

Puppet Script ์‹คํ–‰ ํ”„๋กœ์„ธ์Šค

Puppet script๋ฅผ ์‹คํ–‰ํ•˜๋Š” ํ”„๋กœ์„ธ์Šค๋Š”

  1. puppet script ์ž‘์„ฑํ•œ๋‹ค.(create nginx.pp)
  2. puppet script๊ฐ€ ๋ฌธ๋ฒ•์ƒ ๋ฌธ์ œ๊ฐ€ ์—†๋Š”์ง€ ๊ฒ€์‚ฌํ•œ๋‹ค. (puppet parser validate nginx.pp)
  3. Dry run์„ ํ†ตํ•ด์„œ ๋ชจ์˜ ์‹คํ–‰ํ•œ๋‹ค. (puppet apply nginx.pp --noop)
  4. Puppet script๋ฅผ ์‹คํ–‰ํ•œ๋‹ค. (puppet apply nginx.pp)

๋ฌด์กฐ๊ฑด ์ง€์ผœ์•ผํ•˜๋Š” ๋ถ€๋ถ„์€ ์•„๋‹ˆ์ง€๋งŒ, ์œ„์˜ 4 ๋‹จ๊ณ„์— ๊ฑธ์ณ ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ์ด ์•ˆ์ „ํ•˜๊ณ  ์˜ค๋ฅ˜์—†์ด puppet script๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. ์•„๋ž˜ ์˜ˆ์‹œ์—์„œ ์‹คํ–‰ํ•˜๋Š” ๋ชจ๋“  ์ ˆ์ฐจ๋Š” ์œ„์˜ ํ”„๋กœ์„ธ์Šค๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

 

Resource

Resource๋Š” puppet ์•„ํ‚คํ…์ฒ˜์˜ ๊ธฐ๋ณธ ๊ตฌ์„ฑ์š”์†Œ์ด๊ณ  puppet agent์—์„œ ์ž‘๋™๋˜๋Š” ๋ชจ๋“  ์ž‘์—…์€ puppet resource๋ฅผ ํ†ตํ•ด์„œ ์ง„ํ–‰๋ฉ๋‹ˆ๋‹ค. ์„œ๋ฒ„๋ฅผ ์ œ์–ดํ•˜๊ธฐ ์œ„ํ•œ ์ผ์ข…์˜ function๊ณผ ๋น„์Šทํ•ฉ๋‹ˆ๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ puppet์ด ์ œ๊ณตํ•ด์ฃผ๋Š” Resource๋„ ์กด์žฌํ•˜๊ณ  ์ง์ ‘ Resource๋ฅผ ์ •์˜ํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ๋„ ์žˆ์Šต๋‹ˆ๋‹ค. Resource๋Š” ๊ฐœ๋ณ„์ ์œผ๋กœ ์‚ฌ์šฉ์ด๊ฐ€๋Šฅํ•˜๊ณ  ์กฐํ•ฉ์„ ํ†ตํ•ด ๋ณต์žกํ•œ ์ˆ˜ํ–‰ ๊ณผ์ •์„ ์‹คํ–‰ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

 

๋Œ€ํ‘œ์ ์œผ๋กœ file, package, service์™€ ๊ฐ™์€ Resource๊ฐ€ ์กด์žฌํ•˜๊ณ  ์ด๋ฆ„์ฒ˜๋ฆผ file, package, service๋ฅผ ์ œ์–ดํ•  ์ˆ˜ ์žˆ๋Š” Resource์ž…๋‹ˆ๋‹ค. 

 

puppet resource --type

์œ„์˜ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด์„œ puppet์—์„œ ๊ธฐ๋ณธ์ ์œผ๋กœ ์ •์˜ํ•ด ๋†“์€ Resource๋“ค์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•ด๋‹น Resource๋“ค์— ๋Œ€ํ•ด์„œ ์ž์„ธํ•œ ์‚ฌ์šฉ๋ฒ•์„ ์•Œ์•„๋ณด๊ธฐ ์œ„ํ•ด์„œ๋Š” 2๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๋‹ค.

 

puppet describe ๋ช…๋ น

puppet describe file

describe ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด Command line ์ƒ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์˜ต์…˜๊ณผ ์šฉ๋„๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

puppet documentation

 

Resource Type: file | Puppet

Puppet automates away the challenges, complexity, and risk of securing and running global hybrid and cloud-native infrastructure, so you can focus on delivering the next great thing.

puppet.com

๋‘๋ฒˆ ์งธ ๋ฐฉ๋ฒ•์€ puppet documentation์„ ํ†ตํ•ด ์‚ฌ์šฉ๋ฐฉ๋ฒ•์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

nginx ์„ค์น˜ ์‹ค์Šต

์‹ค์Šต์€ master node์—์„œ ์ง„ํ–‰ํ•œ๋‹ค.

Puppet script ์ƒ์„ฑ

nginx.pp

package { 'nginx':
  ensure => 'present'
} ->

package { 'wget':
  ensure => 'present'
} ->

exec { 'download nginx index':
  cwd => '/usr/share/nginx/html/',
  command => '/bin/wget https://www.nginx.com -O /usr/share/nginx/html/index.html',
} ->

service { 'nginx':
  ensure => 'running'
}

nginx๋ฅผ ์„ค์น˜ํ•˜๊ณ  nginx ํ™ˆํŽ˜์ด์ง€ index.html์„ ๋ฐ›์•„์„œ web server์— ์œ„์น˜์‹œํ‚ค๊ณ  nginx ์„œ๋ฒ„๋ฅผ ์‹คํ–‰ํ•˜๋Š” puppet ํŒŒ์ผ์ž…๋‹ˆ๋‹ค.

๋ฌธ๋ฒ•์˜ ๊ตฌ์กฐ๋ฅผ ๋ณด๋ฉด '{}'๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์•ž์— Resource๋ฅผ ์ •์˜ํ•ด์„œ ์–ด๋–ค ์ž‘์—…์„ ํ•˜๋Š”์ง€ ์•Œ์•„๋ณด๊ธฐ ์‰ฝ๊ฒŒ ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฐ Resource์— ๋Œ€ํ•œ ํŒŒ๋ผ๋ฏธํ„ฐ๋Š” describe ๋ช…๋ น์–ด๋‚˜ documentation์„ ํ™•์ธํ•˜์—ฌ ํ™œ์šฉ๋ฒ•์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

nginx.pp ํŒŒ์ผ์—์„œ ์‚ฌ์šฉ๋˜๋Š” ํŒŒ๋ฆฌ๋ฏธํ„ฐ๋Š”...

package ensure present : ์—†์œผ๋ฉด ์„ค์น˜ํ•˜๊ณ , ์žˆ์œผ๋ฉด ์„ค์น˜ํ•˜์ง€ ์•Š๋Š”๋‹ค.

exe cwd: command๊ฐ€ ์‹คํ–‰๋˜๋Š” ์œ„์น˜

exe command: ์‹คํ–‰ํ•  command

service ensure running : ์„œ๋น„์Šค๊ฐ€ ์‹คํ–‰๋˜์–ด ์žˆ๋Š” ์ƒํƒœ

 

์—ฌ๊ธฐ์„œ ์ค‘์š”ํ•˜๊ฒŒ ๋ด์•ผํ•  ๋ถ€๋ถ„์€ Resource ์‚ฌ์ด์‚ฌ์ด์— '->' ์ž…๋‹ˆ๋‹ค. '->'์—†์ด๋„ ๋ฌธ์ œ์—†์ด ์ž˜ ๋Œ์•„๊ฐ‘๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ˆœ์„œ๋Š” ๋ชจ๋‘ ๋™์‹œ์— ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. '->' ๋ฌธ์ž๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์‹คํ–‰๋˜๋Š” ์ˆœ์„œ๋ฅผ ์ •ํ•ด์ค๋‹ˆ๋‹ค. ํ•„์š”์—๋”ฐ๋ผ ๊ผญ ์„ ํ–‰๋˜์–ด์•ผํ•˜๋Š” ์ž‘์—…์ด ์žˆ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. nginx ์„ค์น˜ ๋ถ€๋ถ„์—์„œ๋„ package๊ฐ€ ์„ค์น˜ ๋œ ํ›„์—, ํŒŒ์ผ์„ ๋ฐ›์•„์•ผํ•ฉ๋‹ˆ๋‹ค. ์—ฌ๋Ÿฌ ์ƒํ™ฉ์„ ๊ณ ๋ คํ•˜์—ฌ '->'๋ฌธ์ž๋ฅผ ์œ ์šฉํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Puppet script ๊ฒ€์‚ฌ

puppet parser validate nginx.pp

์—๋Ÿฌ๋กœ๊ทธ๊ฐ€ ๋ฐœ์ƒํ•˜์ง€์•Š์œผ๋ฉด ๋ฌธ๋ฒ•์ƒ ๋ฌธ์ œ๊ฐ€ ์—†๋Š” ์Šคํฌ๋ฆฝํŠธ์ž…๋‹ˆ๋‹ค.

 

Puppet script Dry run

puppet apply nginx.pp --noop

apply๋ช…๋ น์œผ๋กœ ์ง์—… ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๊ณ  --noop ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜์—ฌ ์‹ค์ œ๋กœ ์‹คํ–‰๋˜์ง€ ์•Š๋Š” dry run์„ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋กœ๊ทธ์˜ ๋‚ด์šฉ์„ ๋ณด๋ฉด ํ˜„์žฌ ๊ฐ’๊ณผ ๋ณ€๊ฒฝ๋˜์–ด์•ผํ•  ๊ฐ’์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์‹ค์ œ๋กœ ์‹คํ–‰ํ•˜๊ธฐ ์ด์ „์— ์ด์ƒ์—†์ด ์‹คํ–‰๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด Dry run์„ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

 

Puppet script ์‹คํ–‰

puppet apply nginx.pp

 

์‹คํ–‰์ด ์™„๋ฃŒ๋˜์—ˆ๊ณ  ์ด์ œ ๋ธŒ๋ผ์šฐ์ €์—์„œ master node์— ๋ถ™์–ด์„œ nginx์„œ๋ฒ„๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์‹คํ–‰๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.

๋ฌธ์ œ๊ฐ€ ์—†๋‹ค๋ฉด ์œ„์™€ ๊ฐ™์ด nginx ํ™ˆํŽ˜์ด์ง€์™€ ๋™์ผํ•œ html์„ ๊ฐ–๊ณ  ์„œ๋ฒ„๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์‹คํ–‰๋˜์—ˆ์„ ๊ฒƒ์ด๋‹ค.

 

๋งŒ์•ฝ ํ•œ๋ฒˆ ๋” ์‹คํ–‰ํ•˜๋ฉด ์–ด๋–ป๊ฒŒ ๋ ๊นŒ?

ํ•œ๋ฒˆ ๋” ์‹คํ–‰๋˜์—ˆ์„ ๋•Œ๋Š” exec Resource์— ๋Œ€ํ•œ ๋ถ€๋ถ„๋งŒ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. Puppet์€ ๋ฉฑ๋“ฑ์„ฑ์ด๋ผ๋Š” ํŠน์ง•๋•Œ๋ฌธ์— ํ•ญ์ƒ ๊ฐ™์€ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•ด์ฃผ๋Š” ์„ฑ์งˆ์„ ๊ฐ–๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. exec์˜ ๊ฒฝ์šฐ command๋ฅผ ์‹คํ–‰ํ•˜๋Š” ์ž‘์—…์ด๊ธฐ ๋•Œ๋ฌธ์— ์‹คํ–‰๋˜์—ˆ์ง€๋งŒ,... ๋‚˜๋จธ์ง€ package๋‚˜ service์— ๋Œ€ํ•œ Resource๋Š” ์‹คํ–‰๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. ์ด๋ฏธ ์‹คํ–‰๋œ ๋ถ€๋ถ„์ด๊ธฐ ๋•Œ๋ฌธ์— ๋„˜์–ด๊ฐ‘๋‹ˆ๋‹ค.

 

 

Class

์ง€๊ธˆ๊นŒ์ง€๋Š” puppet์˜ Resource๋“ค์„ ์กฐํ•ฉํ•ด์„œ puppet script๋ฅผ ์ž‘์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค. ๋งŒ์•ฝ puppet ์ฝ”๋“œ๊ฐ€ ๋ณต์žกํ•ด์ง€๊ณ  ๊ณ„์†ํ•ด์„œ Resource๋“ค๋งŒ ๋‚˜์—ดํ•ด์„œ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•˜๋ฉด, ์•Œ์•„๋ณด๊ธฐ๋„ ์–ด๋ ต๊ณ  ์ฝ”๋“œ์˜ ์žฌ์‚ฌ์šฉ๋„ ๋ถˆ๊ฐ€๋Šฅํ•˜๊ณ  ๊ด€๋ฆฌ์ ์ธ ์ธก๋ฉด์— ์žˆ์–ด์„œ ๋น„ํšจ์œจ์ ์ž…๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด Resource๋“ค์„ ํ•˜๋‚˜์˜ ๋ชฉ์ ์„ ๊ฐ–๋Š” ์ž‘์—…์œผ๋กœ ๋ฌถ๊ณ  ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด Class๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

 

Nginx ์‚ญ์ œ

yum remove nginx -y

 

nginx ์„ค์น˜ ์‹ค์Šต

์‹ค์Šต์€ master node์—์„œ ์ง„ํ–‰ํ•œ๋‹ค.

 

Puppet script ์ƒ์„ฑ

nginx.pp

class nginx_install {
  package { 'nginx':
    ensure => 'present'
  } ->
  
  package { 'wget':
    ensure => 'present'
  } ->

  exec { 'download nginx index':
    cwd => '/usr/share/nginx/html/',
    command => '/bin/wget https://www.nginx.com -O /usr/share/nginx/html/index.html',
  } ->

  service { 'nginx':
    ensure => 'running'
  }
}
include nginx_install

nginx ์„ค์น˜ํ•˜๋Š” class๋ฅผ ์ƒ์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค. ๋ณด์‹œ๋Š” ์ฝ”๋“œ์™€ ๊ฐ™์ด ์œ„์—์„œ Resource ์‹ค์Šตํ•œ ๋ถ€๋ถ„์—์„œ class๋กœ๋งŒ ๋ฌถ์–ด์ฃผ๊ณ  ํ•˜๋‹จ์— include ๋ช…๋ น์„ ์‚ฌ์šฉ class์— ์ •์˜๋˜์–ด ์žˆ๋Š” ๋‚ด์šฉ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. puppet script์— class๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ๊ฐ์ฒด์ง€ํ–ฅํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ์˜ ๊ฐœ๋…์ด ๋„์ž…๋˜๊ณ  ์ฝ”๋“œ์˜ ์žฌ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

 

๋งˆ์ฐฌ๊ฐ€์ง€๋กœ Puppet script ๊ฒ€์‚ฌ, Dry run, ์‹คํ–‰ ์ˆœ์„œ๋Œ€๋กœ ์‹คํ–‰ํ•ด์ฃผ๊ณ  ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

Puppet script ๊ฒ€์‚ฌ

puppet parser validate nginx.pp

 

Puppet script Dry run

puppet apply nginx.pp --noop

 

Puppet script ์‹คํ–‰

puppet apply nginx.pp

 

Manifest

์ง€๊ธˆ๊นŒ์ง€๋Š” puppet script๋ฅผ ์•„๋ฌด ์œ„์น˜์—์„œ ์‹คํ–‰ํ•˜๊ณ  ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. puppet์—์„œ๋Š” ์ง€์ •๋œ ๊ณณ์— puppet script๋ฅผ ์ƒ์„ฑํ•˜๋„๋ก ์ •์˜๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. manifest๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋‹จ๊ณ„์—์„œ puppet์˜ master์™€ agent์— ๋Œ€ํ•œ ๊ฐœ๋…์„ ์ž˜ ์ดํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค. puppet์€ pull based ์ž๋™ํ™” ๊ด€๋ฆฌ ํˆด์ž…๋‹ˆ๋‹ค. Ansible์ฒ˜๋Ÿผ Ansible์ด ์„ค์น˜๋˜์–ด ์žˆ๋Š” Host์—์„œ ๊ด€๋ฆฌ๋˜๋Š” host์— ๋ช…๋ น์„ ํ•˜๋Š” ๊ฒƒ์ด์•„๋‹ˆ๋ผ, agent๊ฐ€ ์ˆ˜์‹œ๋กœ master์—๊ฒŒ ํ•ด์•ผํ•  ์ผ์„ ๋ฌผ์–ด๋ณด๊ณ  ์ ์šฉํ•˜๋Š” ๊ด€๊ณ„๋ฅผ ๊ฐ–์Šต๋‹ˆ๋‹ค. ์ฆ‰, agent๊ฐ€ ๋ฌด์—‡์„ ํ•ด์•ผํ•˜๋Š”์ง€ master์—๊ฒŒ ๋ฌผ์–ด๋ณผ๋•Œ, ๋ฐ”๋ผ์˜ค๋Š” ๊ณณ์ด ๋ฐ”๋กœ manifest directory ์ž…๋‹ˆ๋‹ค.

 

agent์— ์‹คํ–‰ํ•˜๋ ค๋Š” puppet manifest๋ฅผ master์˜ manifest directory์— ์œ„์น˜์‹œ์ผœ์ฃผ๋ฉด ์‹คํ–‰ํ•˜๊ฒŒ๋ฉ๋‹ˆ๋‹ค.

 

puppet config print

ํ•ด๋‹น ๋ช…๋ น์„ ํ†ตํ•ด์„œ puppetserver์˜ ๋ชจ๋“  ํ™˜๊ฒฝ์„ค์ •์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

puppet config print | grep manifest

config์˜ ์ •๋ณด์—์„œ manifest๋ฅผ ์ฐพ์•„๋ณด๋ฉด manifest์˜ ๊ฒฝ๋กœ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

'/etc/puppetlabs/code/environmets/' ํ•ด๋‹น ๊ฒฝ๋กœ์•„๋ž˜ Host๊ฐ€ ์†ํ•ด์žˆ๋Š” environment ํด๋”๋ฅผ ์ƒ์„ฑํ•ด์ฃผ๊ณ  manifests ํด๋”๋ฅผ ์•ˆ์— ์ƒ์„ฑํ•ด์„œ puppet manifest์„ ์ž‘์„ฑํ•ด์„œ ๋„ฃ์–ด์ฃผ๋ฉด runinterval ์ฃผ๊ธฐ๋งˆ๋‹ค ํ˜น์€ puppet agent -t ๋ช…๋ น์ด ์‹คํ–‰๋  ๋•Œ agent๊ฐ€ master์—๊ฒŒ ์ž‘์—…์„ ์š”์ฒญํ•˜์—ฌ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

 

runinterval๋„ config์ค‘ ํ•˜๋‚˜์ด๊ณ , ํ•ด๋‹น ์„ค์ •์€ /etc/puppetlabs/puppet/puppet.conf ํŒŒ์ผ์— ์ •์˜ํ•˜๊ฑฐ๋‚˜ ์ˆ˜์ •ํ•˜์—ฌ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ณ€๊ฒฝ ํ›„์—๋Š” puppetserver๋ฅผ ์žฌ์‹œ์ž‘ํ•ด์ค๋‹ˆ๋‹ค.

 

 

site.pp

์‹ค์Šต์„ ์ง„ํ–‰ํ•˜๊ธฐ ์ด์ „์— site manifest์— ๋Œ€ํ•ด์„œ ์กฐ๊ธˆ ์•Œ์•„๋ณด์ž.

manifest ๊ฒฝ๋กœ์•ˆ์— ์—ฌ๋Ÿฌ๊ฐœ์˜ ํŒŒ์ผ์ด ์žˆ๋Š” ๊ฒฝ์šฐ ์–ด๋–ป๊ฒŒ ๋ ๊นŒ? puppet์—์„œ๋Š” site.pp๋ผ๋Š” ํŒŒ์ผ์„ agent๊ฐ€ master์˜ manifest๋ฅผ ํ™•์ธํ•  ๋•Œ ๊ฐ€์žฅ ์ฒ˜์Œ ํ™•์ธํ•˜๋Š” ํŒŒ์ผ์ด๋‹ค. community ๋ฒ„์ „์—์„œ๋Š” ํŒŒ์ผ์„ ์ƒ์„ฑํ•ด์ค˜์•ผํ•œ๋‹ค. ๊ฐ€์žฅ ๋„๋ฆฌ ์‚ฌ์šฉ๋˜๋Š” ๋ฐฉ์‹์ด๋ผ๊ณ  ํ•œ๋‹ค๋ฉด ์—ฌ๋Ÿฌ ํŒŒ์ผ์— ๊ฐ๊ฐ class์™€ Resource์„ ์‚ฌ์šฉํ•ด์„œ manifest๋ฅผ ์ƒ์„ฑํ•ด์ฃผ๊ณ  site.pp์— include ๋ช…๋ น์„ ํ†ตํ•ด์„œ ์‹คํ–‰ํ•˜๋Š” main manifest ์ •๋„๋กœ ์ƒ๊ฐํ•˜๋ฉด ๋œ๋‹ค.

 

Nginx ์‚ญ์ œ

yum remove nginx -y

 

nginx ์„ค์น˜ ์‹ค์Šต

agent puppet.conf

[main]
certname = node01.puppet.test
environment = node
server = master.puppet.test
runinterval = 600

agent์— /etc/puppetlabs/puppet/puppet.conf ์„ค์ •ํŒŒ์ผ์˜ ๋‚ด์šฉ์ด๋‹ค.

๋ณด๋ฉด environment = node๋กœ ์ง€์ •ํ•ด์คฌ๋Š”๋ฐ ์ด๋Š” master์— ์š”์ฒญํ•  ๋•Œ /etc/puppetlabs/code/environments/node/manifest์•„๋ž˜ ์žˆ๋Š” puppet manifest๋ฅผ ์‹คํ–‰ํ•˜๊ฒ ๋‹ค๋Š” ์˜๋ฏธ์ด๋‹ค.

 

master /etc/puppetlabs/code/environments/node/manifest puppet script ์ƒ์„ฑ

nginx.pp

class nginx_install {
  package { 'nginx':
    ensure => 'present'
  } ->

  package { 'wget':
    ensure => 'present'
  } ->

  exec { 'download nginx index':
    cwd => '/usr/share/nginx/html/',
    command => '/bin/wget https://www.nginx.com -O /usr/share/nginx/html/index.html',
  } ->

  service { 'nginx':
    ensure => 'running'
  }
}

 

site.pp

include nginx_install

 

Puppet script ๊ฒ€์‚ฌ

master์—์„œ ์ง„ํ–‰ํ•œ๋‹ค.

puppet parser validate nginx.pp
puppet parser validate site.pp

 

Puppet script Dry run

agent์—์„œ ์ง„ํ–‰ํ•œ๋‹ค.

puppet agent -t --noop

์ผ๋ฐ˜ puppet script๋ฅผ ์ƒ์„ฑํ•ด์„œ ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ๊ณผ ๋‹ค๋ฅด๊ฒŒ master๊ฐ€ ์•„๋‹Œ ์‹ค์ œ ๋ฐ˜์˜ํ•˜๋Š” host์— ์ ‘์†ํ•ด์„œ puppet agent -t ๋ช…๋ น์„ ์‹คํ–‰ํ•ด์„œ apply๋ฅผ ์ง„ํ–‰ํ•œ๋‹ค. 

 

 

Puppet script ์‹คํ–‰

puppet agent -t

์‹คํ–‰ ํ›„ ๋ฐ˜์˜ ํ™•์ธํ•œ๋‹ค.

 

 

Node

Node๋Š” ์–ด๋–ค Host์— ์ž‘์—…์„ ๋ฐ˜์˜ํ• ์ง€ ์ •์˜ํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด์„œ ํ˜„์žฌ node๋กœ ์ด๋ฆ„์ด ๋˜์–ด์žˆ๋Š” environment์— node01.puppet.test, node02.puppet.test ๋‘๊ฐœ์˜ host๊ฐ€ ์žˆ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ node01์—๋งŒ ์ ์šฉํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. agent์—์„œ master์—๊ฒŒ ์ž‘์—…์„ ์š”์ฒญํ• ๋•Œ manifest์— ์ž์‹ ์˜ host๋ฅผ ์ฐพ์•„๊ฐ€๋Š” ๋Š๋‚Œ์œผ๋กœ ์ดํ•ดํ•˜๋ฉด ๋ ๊ฒƒ์ด๋‹ค.

 

Nginx ์‚ญ์ œ

yum remove nginx -y

 

nginx ์„ค์น˜ ์‹ค์Šต

Puppet script ์ƒ์„ฑ

nginx.pp

 

class nginx_install {
  package { 'nginx':
    ensure => 'present'
  } ->
  
  package { 'wget':
    ensure => 'present'
  } ->

  exec { 'download nginx index':
    cwd => '/usr/share/nginx/html/',
    command => '/bin/wget https://www.nginx.com -O /usr/share/nginx/html/index.html',
  } ->

  service { 'nginx':
    ensure => 'running'
  }
}
include nginx_install

 

site.pp

node "node01.puppet.test" {
  include nginx_install
}

node 'default' {

}

 

Puppet script ๊ฒ€์‚ฌ

master์—์„œ ์ง„ํ–‰ํ•œ๋‹ค.

puppet parser validate nginx.pp
puppet parser validate site.pp

 

Puppet script ์‹คํ–‰

ํŽธ์˜ ์ƒ dry run์€ ์ƒ๋žตํ•œ๋‹ค.

puppet agent -t

puppet์„ node01๊ณผ node02, ๋ชจ๋“  agent์—์„œ ์‹คํ–‰ํ•ด๋ณธ๋‹ค.

๊ฒฐ๋ก ์ ์œผ๋กœ node01 agent์—์„œ๋งŒ nginx๊ฐ€ ์„ค์น˜๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

๋Œ“๊ธ€