Puppent 基本使用方法

时间:2021-04-07 09:29:40

简单的文件配置

master端

vim /etc/puppet/manifests/site.pp
###########################内容如下
node default{
file {"/tmp/test.txt":
content=>"I am test puppet\n"; }
}

第一次需要重启Master

service puppetmaster restart

客户端请求

[root@client01 puppet]# puppet agent --test
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for client01.test.com
Info: Applying configuration version ''
Notice: /Stage[main]/Main/Node[default]/File[/tmp/test.txt]/ensure: defined content as '{md5}a54460ca5545fddd6250f9aab22fc857'
Notice: Finished catalog run in 0.06 seconds
[root@client01 puppet]# ll /tmp/
total
-rw-r--r-- root root Oct : test.txt
-rw-------. root root Mar yum.log
[root@client01 puppet]# cat /tmp/test.txt
I am test puppet

查看到文件以及同步过来了

创建文件并改变用户和授权

node default{
file {"/tmp/test.txt":
content=>"I am test puppet\n";
owner => "root"
group => "puppet"
mode => ""
}
}

管理组和用户:

group {"test":
gid =>,
ensure => present,
} user {"hmy":
name => "yf",
uid => ,
gid => test,
managehome => true
} 默认是false
ensure => present
groups => ['puppet','xfs']
shell => "/bin/bash"

实例

user {"test1":
name => "test",
uid => ,
gid => test,
managehome => true,
ensure => present,
groups => ['puppet'],
shell => "/bin/bash";
}

定时任务cron

cron { "ntp time":
command => "/usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1",
minute => '*/10',
hour => ['2-4'],
monthday => [,],
ensure => present, }

文件同步案例

同步master端/etc/puppet/system_conf/下的文件到agent

a修改master配置文件

[root@master01 puppet]# vim fileserver.conf
[system_conf]
path /etc/puppet/system_conf
allow *

重启

[root@master01 puppet]# /etc/init.d/puppetmaster restart
Stopping puppetmaster: [ OK ]
Starting puppetmaster: [ OK ]

b 把需要同步的文件放到master的/etc/puppet/system_conf下

 cp /etc/resolv.conf /etc/puppet/system_conf/

c 修改master端 site.pp

file {"/etc/resolv.conf":
mode => ,
source => "puppet://master01.test.com/system_conf/resolv.conf"; }

d 客户端同步

# puppet agent --test

这个实例可以配置:
系统文件 hosts,resolv.conf,i18n,yum配置文件
脚本文件 /script/service_all_clear.sh