puppet 基础-创建第一个配置

一个节点的目录结构可以任意定义,只要在site.pp配置文件中import即可。
建议采用如下目录结构配置:
节点信息:/etc/puppet/manifests/nodes
模块信息:/etc/puppet/modules

现在学习配置简单的File资源,创建文件,并写入’Hello World‘。
1.创建file-helloworld模块
mkdir -p /etc/puppet/modules/ file-helloworld/{manifests,templates,files }
vim   /etc/puppet/modules/ file-helloworld/ manifests/init.pp
class file-helloworld {
  file { "/root/hostname.txt": content => "Hello world!";}
}
2.创建测试节点app-192.168.9.158.centos.test.com
mkdir -p /etc/puppet/manifests/nodes
node 'app-192.168.9.158.centos.test.com' {
  include file-helloworld
}
3.最后将测试节点载入到Puppet,也就是修改site.pp配置文件。
vim /etc/puppet/manifests/site.pp
追加一行
import "nodes/app-192.168.9.158.centos.test.com.pp"

到此一个测试节点配置完毕,接下来需要检查配置文件的语法。

检查配置文件分两步经行
第一步在服务端
puppet parser validate /etc/puppet/modules/file-helloworld/manifests/init.pp
看是否提示错误,无错误提示则经行下一步。

第二步在客户端
通过添加--noop参数来实现,验证配置,模拟执行。
[root@app-192 ~]# puppet agent --test --noop
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for app-192.168.9.158.centos.test.com
Info: Applying configuration version '1464588576'
Notice: /Stage[main]/File-helloworld/File[/root/hostname.txt]/ensure: current_value absent, should be file (noop)
Notice: Class[File-helloworld]: Would have triggered 'refresh' from 1 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.17 seconds

客户端运行配置
[root@app-192 ~]# puppet agent --test 
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for app-192.168.9.158.centos.test.com
Info: Applying configuration version '1464588576'
Notice: /Stage[main]/File-helloworld/File[/root/hostname.txt]/ensure: defined content as '{md5}86fb269d190d2c85f6e0468ceca42a20'
Notice: Finished catalog run in 0.24 seconds
查看运行结果
[root@app-192 ~]# ll hostname.txt 
-rw-r--r-- 1 root root 12 5月  30 14:13 hostname.txt
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值