0

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

我的 apache 模块中有一个虚拟主机模板,看起来像这样。这是我的 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 清单中使用另一个具有不同设置的虚拟主机模板时,我收到了一个错误。这是我无法在我的 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 中定义多个虚拟主机定义,每个都有不同的设置?

4

1 回答 1

1

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

于 2015-11-12T07:12:42.527 回答