linux拷贝模板配置文件,linux – 如何在Puppet中使用配置文件的模板

在2007年的PuppetLabs文档中有一个Trac站点的Apache配置示例.这应该足以让你开始.

根据OP的要求,这里有一个简单的例子.我使用NTP而不是Apache的默认配置,因为这是一个相当大和复杂的文件. NTP简单得多

目录如下所示:

/etc/puppet/modules/ntp/manifests

/templates

部分内容/etc/puppet/modules/ntp/manifests/init.pp(仅限定义模板的部分):

$ntp_server_suffix = ".ubuntu.pool.ntp.org"

file { '/etc/ntp.conf':

content => template('ntp/ntp.conf.erb'),

owner => root,

group => root,

mode => 644,

}

/etc/puppet/modules/ntp/templates/ntp.conf.erb的内容:

driftfile /var/lib/ntp/drift

server

restrict -4 default kod notrap nomodify nopeer noquery

restrict -6 default kod notrap nomodify nopeer noquery

restrict 127.0.0.1

当使用puppet运行时,这将导致/etc/ntp.conf看起来像:

driftfile /var/lib/ntp/drift

server 1.ubuntu.pool.ntp.org

server 2.ubuntu.pool.ntp.org

restrict -4 default kod notrap nomodify nopeer noquery

restrict -6 default kod notrap nomodify nopeer noquery

restrict 127.0.0.1

这表明了几个不同的概念:

>在木偶清单中定义的变量(如$ntp_server_suffix)可以作为模板中的实例变量(@ntp_server_suffix)访问

>循环和其他ruby代码可以在erb模板中使用

>由ruby执行

>之间的代码由ruby执行并输出

>之间的代码被ruby执行并输出,并且尾随的换行符被抑制.

希望这有助于您了解模板.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值