Welkin Fan bio photo

Welkin Fan

A software engineer from Taiwan.

Email Github

認識Puppet

在動手之前先看看下面文章

嘗試單機(Apply)模式

有了大致的概念後不囉嗦直接動手玩玩看, 參考官方文件直上Puppet 4.0在RHEL 6.x環境 首先安裝repo

1
rpm -ivh http://yum.puppetlabs.com/puppetlabs-release-pc1-el-6.noarch.rpm

完成後搜尋看看repository 是不是找的到puppet

1
yum search puppet

應該會看到以下的package

1
2
3
4
5
puppet-agent.x86_64 : The Puppet Agent package contains all of the elements needed to run puppet, including ruby, facter, hiera and mcollective.
puppetdb.noarch : Puppet Centralized Storage Daemon
puppetdb-terminus.noarch : Puppet terminus files to connect to PuppetDB
puppetlabs-release-pc1.noarch : Release packages for the Puppet Labs PC1 repository
puppetserver.noarch : Puppet Labs - puppetserver

接著安裝puppet agent

1
yum -y install puppet-agent

裝完後檢查看看版本是否為4.0

1
/opt/puppetlabs/bin/puppet --version

接下來就可以建立第一個設定檔

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cat >/etc/puppetlabs/code/environments/production/manifests/hellopuppet.pp

node "foo.bar" {

file { '/root/hellopuppet.txt':
ensure => "file",
owner => "root",
group => "root",
mode => "600",
content => "Congratulations!
Puppet has created this file.
",}

}
^D

用apply命令套用設定檔

1
/opt/puppetlabs/bin/puppet apply /etc/puppetlabs/code/environments/production/manifests/hellopuppet.pp

這時候puppet應該會在家目錄下產生hellopuppet.txt

1
cat /root/hellopuppet.txt

接下來可以任意改改看那個檔案的內容或是權限然後再執行apply的指令,檢查puppet是否正確地把檔案修復

References