Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何在Puppet中使用配置文件模板_Linux_Templates_Configuration_Puppet - Fatal编程技术网

Linux 如何在Puppet中使用配置文件模板

Linux 如何在Puppet中使用配置文件模板,linux,templates,configuration,puppet,Linux,Templates,Configuration,Puppet,我是Puppet的新手,我正在编写一个模块来设置配置文件。问题是,当多个客户端将使用我的模块时,他们必须根据自己的系统对其进行编辑。我听说模板是解决这个问题的方法。但我无法了解如何使用模板设置配置文件 如果你们中有人能给我一个简单的例子,使用模板来配置文件将非常有用。例如,我如何使用模板设置Apache站点可用的默认配置文件,或者给出您认为有助于新puppet用户的任何其他示例。顺便说一句,我在Ubuntu机器上。上的PuppetLabs文档有一个用于Trac站点的Apache配置示例。这应该足

我是Puppet的新手,我正在编写一个模块来设置配置文件。问题是,当多个客户端将使用我的模块时,他们必须根据自己的系统对其进行编辑。我听说模板是解决这个问题的方法。但我无法了解如何使用模板设置配置文件

如果你们中有人能给我一个简单的例子,使用模板来配置文件将非常有用。例如,我如何使用模板设置Apache站点可用的默认配置文件,或者给出您认为有助于新puppet用户的任何其他示例。顺便说一句,我在Ubuntu机器上。

上的PuppetLabs文档有一个用于Trac站点的Apache配置示例。这应该足以让你开始

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

目录如下所示:

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

/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
这说明了几个不同的概念:

  • 木偶清单中定义的变量(如
    $ntp\u server\u suffix
    )可以作为模板中的实例变量(
    @ntp\u server\u suffix
    )进行访问
  • 循环和其他ruby代码可以在erb模板中使用
  • 之间的代码由ruby执行
  • 之间的代码由ruby执行和输出
  • ruby执行并输出之间的代码,并抑制尾随的换行符

  • 希望这能帮助您理解模板。

    谢谢ben.:)。。。我查看了文档,它有点复杂。你能举个小例子吗?谢谢你,本。。非常感谢。。这让我很好地理解了模板的工作原理。我必须安装ntp,然后将它与您在puppet代码中修改它的方式进行比较:)…再次感谢..内容行应该是Content=>template('ntp/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
    
    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