在 Puppet 中使用多个虚拟主机模板

Using multiple vhost templates in puppet

我想在我的节点清单中使用我的 apache 模块中的多个 vhost 模板,但到目前为止还没有成功。

我的 apache 模块中有一个 vhost 模板,如下所示。这是我的 apache::vhost 模板:

cat modules/apache/templates/vhost.conf.erb
<VirtualHost *:<%= port %>>
   ServerName <%= name %>
<%if serveraliases.is_a? Array -%>
<% serveraliases.each do |name| -%>
<%= " ServerAlias #{name}\n" %><% end -%>
<% elsif serveraliases != '' -%>
<%= "   ServerAlias #{serveraliases}" -%>
<% end -%>

   php_value newrelic.appname <%= name  %>

    KeepAlive   On
    KeepAliveTimeout 5
    MaxKeepAliveRequests 100
    LogFormat "{ \
      \"host\":\"<%= name %>.<%= domain %>\", \
      \"path\":\"/var/log/httpd/jf_<%= name %>_access_log\", \
      \"tags\":[\"Jokefire <%= name %>\"], \
      \"message\": \"%h %l %u %t \\"%r\\" %>s %b\", \
      \"timestamp\": \"%{%Y-%m-%dT%H:%M:%S%z}t\", \
      \"clientip\": \"%a\", \
      \"duration\": %D, \
      \"status\": %>s, \
      \"request\": \"%U%q\", \
      \"urlpath\": \"%U\", \
      \"urlquery\": \"%q\", \
      \"method\": \"%m\", \
      \"bytes\": %B, \
      \"vhost\": \"%v\" \
    }" <%= name %>_access_json
    CustomLog /var/log/httpd/jf_<%= name %>_access_log <%= name %>_access_json
    LogLevel  debug
    ErrorLog  /var/log/httpd/jf_<%= name %>_error_log
    DirectoryIndex index.html index.php
    DocumentRoot <%= docroot %>
    <Directory <%= docroot %>>
      Options  Indexes  FollowSymLinks
      AllowOverride All
      Order allow,deny
      allow from all
    </Directory>
     ServerSignature  On
</VirtualHost>

当我在我的 nodes.pp 清单中定义该模板时,它工作得很好:

   apache::vhost { 'dev.example.com':
      port => 80,
      docroot => '/var/www/jf-wp',
      ssl => false,
      priority => 002,
      }

但是当我尝试在我的 nodes.pp 清单中使用另一个具有不同设置的 vhost 模板时,我收到了一个错误。这是我无法在我的 nodes.pp 清单中工作的 apache::vhost_admin 模板:

 #cat modules/apache/templates/vhost_admin.conf.erb
<VirtualHost *:<%= port %>>
   ServerName <%= name %>
<%if serveraliases.is_a? Array -%>
<% serveraliases.each do |name| -%>
<%= " ServerAlias #{name}\n" %><% end -%>
<% elsif serveraliases != '' -%>
<%= "   ServerAlias #{serveraliases}" -%>
<% end -%>

   php_value newrelic.enabled false

    KeepAlive   On
    KeepAliveTimeout 5
    MaxKeepAliveRequests 100
    LogFormat "{ \
      \"host\":\"<%= name %>.<%= domain %>\", \
      \"path\":\"/var/log/httpd/jf_<%= name %>_access_log\", \
      \"tags\":[\"Jokefire <%= name %>\"], \
      \"message\": \"%h %l %u %t \\"%r\\" %>s %b\", \
      \"timestamp\": \"%{%Y-%m-%dT%H:%M:%S%z}t\", \
      \"clientip\": \"%a\", \
      \"duration\": %D, \
      \"status\": %>s, \
      \"request\": \"%U%q\", \
      \"urlpath\": \"%U\", \
      \"urlquery\": \"%q\", \
      \"method\": \"%m\", \
      \"bytes\": %B, \
      \"vhost\": \"%v\" \
    }" <%= name %>_access_json
    CustomLog /var/log/httpd/jf_<%= name %>_access_log <%= name %>_access_json
    LogLevel  debug
    ErrorLog  /var/log/httpd/jf_<%= name %>_error_log
    DirectoryIndex index.html index.php
    DocumentRoot <%= docroot %>
    <Directory <%= docroot %>>
      Options  Indexes  FollowSymLinks
      AllowOverride All
      Order allow,deny
      allow from all
    </Directory>
     ServerSignature  On
</VirtualHost>

当我尝试在我的 nodes.pp 文件中定义 apache::vhost_admin 时:

apache::vhost_admin { 'admin.example.com':
  port => 80,
  docroot => '/var/www/admin',
  ssl => false,
  priority => 004,
  serveraliases => 'www.admin.example.com',
  }

当我在 nodes.pp 清单中定义 apache::vhost_admin 模板时,出现以下错误:

 Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Puppet::Parser::AST::Resource failed with e
rror ArgumentError: Invalid resource type apache::vhost_admin at /etc/puppet/environments/production/manifests/nodes.p
p:139 on node web1.jokefire.com
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
enter code here

我做错了什么?如何在 puppet 中定义多个 vhost 定义,每个定义都有不同的设置?

在与@bluethundr 讨论后,似乎缺少 "apache::vhost_admin" 定义。