linux – 如何在Puppet中使用配置文件的模板
我是Puppet的新手,我正在编写一个模块来设置配置文件.问题是当多个客户端将使用我们的模块时,他们将根据自己的系统进行编辑.我听说模板是解决这个问题的方法.但是我无法得到如何使用模板来设置配置文件.
如果任何人可以给我一个简单的例子,使用模板配置文件将是非常有帮助的.例如我如何设置Apache网站 – 使用模板的可用的默认配置文件,或者给出任何其他的例子,你会帮助一个新的木偶用户. BTW我在Ubuntu机器上. 解决方法
在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 <% [1,2].each do |n| -%> server <%=n-%><%=@ntp_server_suffix%> <% end -%> 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)访问 希望这有助于您了解模板. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |