© Reductive Labs 2009Microsoft's Internet Explorer browser has no built-in vector graphics machinery required for "loss-free" gradient background themes.
Please upgrade to a better browser such as Firefox, Opera, Chrome, Safari or others with built-in vector graphics machinery and much more. (Learn more or post questions or comments at the Slide Show (S9) project site. Thanks!)
by Luke Kanies
Reductive Labs, Inc.
Japanese Translated by Naoya Nakazawa
Original Presentation available at git://github.com/reductivelabs/velocity_puppet_workshop_2009.git
#puppet on irc.freenode.net1 ralsh <パッケージ名> 2 ralsh user luke 3 ralsh user naoya 4 ralsh user naoya ensure=present shell=/opt/local/bin/zsh home=/Users/naoya 5 ralsh user naoya shell=/opt/local/bin/zsh 6 ralsh user naoya ensure=absent
ralsh package を試してみよう
1 file { "/tmp/example_file": 2 ensure => present, 3 content => "This is a test\n", 4 mode => 640, 5 }
puppetralshpuppetdpuppetmasterdpuppetca他の実行プログラムもあるが、今回はすべてを対象にしていない
1 puppet -e 'file { "/tmp/eh": ensure => present }'
実演:
1 notice: //File[/tmp/eh]/ensure: created
2回試してみよう。--noop オプションをつけて試してみよう。
1 puppet -e 'file { "/tmp/eh": ensure => absent }'
実演:
1 notice: //File[/tmp/eh]: Filebucketed to with sum d41d8cd98f00b204e9800998ecf8427e 2 notice: //File[/tmp/eh]/ensure: removed
1 class foo { 2 file { "/tmp/foo": ensure => present } 3 }
実演:
1
1 class foo { 2 file { "/tmp/foo": ensure => present } 3 } 4 include foo
実演:
1 notice: //foo/File[/tmp/foo]/ensure: created
基本のリポジトリ構造:
1 manifests/site.pp 2 modules/ 3 modules/mymod/manifests/init.pp 4 modules/mymod/templates/mytemplate.erb 5 modules/mymod/plugins/puppet/parser/functions/myfunction.rb
1 mkdir repo 2 mkdir -p repo/manifests repo/modules/foo/manifests 3 cp examples/class_but_no_include.pp repo/modules/foo/manifests/init.pp
使ってみよう:
1 puppet --modulepath repo/modules -e 'include foo'
1 node default { 2 include foo 3 }
1 puppet --modulepath repo/modules repo/manifests/site.pp
これで「完全な」 Puppet リポジトリになり、拡張していく準備が整いました。
1 puppetmasterd --verbose --no-daemonize --modulepath $PWD/repo/modules \ 2 --confdir /tmp/server --vardir /tmp/server \ 3 --manifest $PWD/repo/manifests/site.pp --certdnsnames localhost
実演:
1 info: Starting server for Puppet version 0.24.8 2 info: Creating a new certificate request for phage.local 3 info: Creating a new SSL key at /tmp/server/ssl/private_keys/phage.local.pem 4 info: Autosign is enabled but /tmp/server/autosign.conf is missing 5 info: Signing certificate for CA server 6 info: Signing certificate for phage.local 7 info: Listening on port 8140 8 notice: Starting Puppet server version 0.24.8
通常は 'puppet' ユーザで実行しますが、'puppet' ユーザは必須ではありません。
--verbose: 特別なロギングを提供する--no-daemonize: バックグランドで動作させない--modulepath $PWD/repo/modules: モジュールの場所を指定する--confdir /tmp/server: 非標準的な設定ファイルがあるディレクトリを使う--vardir /tmp/server: 非標準的な状態/データがあるディレクトリを使う--manifest $PWD/repo/manifests/site.pp: 特別なマニフェストを使って開始する--certdnsnames localhost: SSL 証明書のエイリアスとして localhost を指定する1 puppetmasterd --configprint modulepath 2 puppetmasterd --configprint confdir 3 puppetmasterd --configprint vardir
実演:
1 /opt/rl/dist/apps/puppet/modules:/usr/share/puppet/modules 2 /etc/puppet 3 /var/puppet
1 sudo puppetd --test --confdir /tmp/server --vardir /tmp/server --server localhost
実演:
1 info: Caching catalog at /tmp/server/state/localconfig.yaml 2 notice: Starting catalog run 3 notice: //Node[default]/foo/File[/tmp/foo]/ensure: created 4 notice: Finished catalog run in 0.01 seconds
root ユーザが実行することに注意しよう
--test: とても助けになる引数をまとめて指定する--confdir /tmp/server: 非標準的な設定ファイルのディレクトリを使う--vardir /tmp/server: 非標準敵な状態/データファイルのディレクトリを使う--server localhost: 接続先のサーバを指定する標準の SSL(tm) になっている。
1 puppetca --confdir /tmp/server/ --vardir /tmp/server --list
実演:
1 No certificates to sign
puppetca --print <hostname> を試してみよう/tmp/client ディレクトリに移動する:
1 sudo puppetd --test --confdir /tmp/client --vardir /tmp/client \ 2 --server localhost --certname other.madstop.com
サーバ上の表示:
1 notice: Host other.madstop.com has a waiting certificate request
1 puppetca --confdir /tmp/server/ --vardir /tmp/server --list 2 puppetca --confdir /tmp/server/ --vardir /tmp/server --sign other.madstop.com
もう一度クライアント上で実行してみよう
私は、いつも、sudo から始める。
repo/modules/sudo/manifests/init.pp の中身:
1 2 class sudo { 3 file { "/usr/bin/sudo": 4 owner => root, 5 group => wheel, 6 mode => 4111 7 } 8 }
site.pp のデフォルトノードに sudo を追加する。
repo/modules/sudo/files/sudoers に自分の sudoers を作成したら、init.pp に追加してみよう:
1 file { "/etc/sudoers": 2 owner => root, 3 group => wheel, 4 mode => 440, 5 source => "puppet:///sudo/sudoers" 6 }
1 file { sudo: 2 path => $operatingsystem ? { 3 darwin => "/usr/bin/sudo", 4 default => "/usr/sbin/sudo", 5 }, 6 owner => root, 7 group => 0, 8 mode => 4111 9 }
1 $ facter | wc -l 2 55 3 $ facter | grep name 4 hostname => phage 5 macosx_productname => Mac OS X 6 sp_local_host_name => phage 7 sp_machine_name => MacBook 8 sp_user_name => Luke Kanies (luke) 9 $
1 class rels { 2 file { "/tmp/reltest": ensure => present } 3 exec { "/bin/echo got notified": 4 subscribe => File["/tmp/reltest"], 5 refreshonly => true 6 } 7 }
実演:
1 notice: //rels/File[/tmp/reltest]/ensure: created 2 notice: //rels/Exec[/bin/echo got notified]: Triggering 'refresh' from 1 dependencies
1 define apache::vhost($docroot, $ensure = present) { 2 file { "/tmp/apache/sites/$name": 3 content => template("apache/vhost.erb"), 4 ensure => $ensure 5 } 6 }
条件付き定義名に注意しよう。この名前は正しく自動ロードするときに必要なものです。
1 class apache { 2 apache::vhost { 'reductivelabs.com': 3 docroot => "/var/www/reductivelabs.com" 4 } 5 apache::vhost { 'foo.com': 6 docroot => "/var/www/foo.com", 7 ensure => absent 8 } 9 }
1 define apache::vhost2($docroot, $ensure = present) { 2 $available => $ensure ? { enabled => present, default => $ensure } 3 $enabled => $ensure ? { enabled => symlink, default => absent } 4 file { "/tmp/apache/sites-available/$name": 5 content => template("apache/vhost.erb"), 6 ensure => $available 7 } 8 file { "/tmp/apache/sites-enabled/$name": 9 target => "/tmp/apache/sites-available/$name", 10 ensure => $enabled 11 } 12 }
Reductive Labs はサポート契約を提供、トレーニング、カスタム開発を提供しています。そして、これらを Puppet の開発、講演、食べることための資金としています。もちろんほとんどすべてです。