2016-08-25 3 views
0

シェフのレシピを使用して、Amazon EC2インスタンス上で動作するTomcatサーバーを管理しています。これは、私が同じTomcatをたくさん使う必要があるシナリオでは、私にとってはうまくいきます。すべて同じ.jars/Javaオプション/を持つものです。Chefを使用してインスタンス固有のコンテンツを持つファイルを管理するには?

しかし、私はどのように対処するかわからないユースケースにヒットしました。基本的に、すべてのTomcatには、特定のエンドポイント(その名前に対応するAmazonのElasticache)を指す必要があるManager要素を持つように構成するcontext.xml(/ etc/tomcat7にあります)ファイルがあります。したがって、TomcatA ElasticacheAなどがあります)。最初は、私は、関連のcontext.xmlテンプレートと私のレシピに次のコードを持っていた:のcontext.xmlのため

elasticache="TomcatA" 
elasticache_suffix = ".xxx.cfg.use1.cache.amazonaws.com" 

template 'tomcat context.xml configuration' do 
path ::File.join(tomcat_directory, 'context.xml') 
source 'context.xml.erb' 
variables(
{ 
      :elasticache => elasticache, 
      :elasticache_suffix => elasticache_suffix 
} 
     ) 
owner 'root' 
group node["tomcat"]["group"] 
mode 00644 
notifies :restart, 'service[tomcat7]', :delayed 
end 

テンプレート:

<?xml version='1.0' encoding='utf-8'?> 
<!-- 
Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license agreements. See the NOTICE file distributed with 
this work for additional information regarding copyright ownership. 
The ASF licenses this file to You under the Apache License, Version 2.0 
(the "License"); you may not use this file except in compliance with 
the License. You may obtain a copy of the License at 
    http://www.apache.org/licenses/LICENSE-2.0 
    Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
See the License for the specific language governing permissions and 
limitations under the License. 
--> 
<!-- The contents of this file will be loaded for each web application -> 
<Context> 

<!-- Default set of monitored resources --> 
<WatchedResource>WEB-INF/web.xml</WatchedResource> 

<Manager 
className="de.javakaffee.web.msm.MemcachedBackupSessionManager" 
memcachedNodes="<%[email protected]%><%[email protected]_suffix%>:11211" 
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$" 
sessionBackupAsync="true" 
sticky="true" 
copyCollectionsForSerialization="false" 
/> 

<!-- Uncomment this to enable Comet connection tacking (provides events 
    on session expiration as well as webapp lifecycle) --> 
<!-- 
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" /> 
--> 

</Context> 

しかし、これは明らかにので、私の目的のために動作しませんがシェフは、既存のすべての設定がElasticacheAを使用していることを確認します。

AWS CLIを使用して私が必要とするElasticacheの名前の値を取得できますが、シェフが既存の設定を毎回その値で上書きしないようにするにはどうすればよいですか?理想的には、レシピを実行するたびに、すでに使用されている設定に影響を与えない、このテンプレートの新しい結果が生成されます。

答えて

0

ここにはいくつかのオプションがあります。すべてがノード属性になります。ハードコードされたelasticache変数の代わりに、ノード属性を使用する必要があります(例:node["tomcat"]["elasticache"])。 2つの方法で各展開に調整できます。

  1. それぞれのタイプのTomcatデプロイメントに対してenvironmentを作成し、異なるデプロイメントタイプに異なる環境を割り当て、そこに属性を上書きします。
  2. ノード属性を設定/無効にし、Tomcatの設定を行う基本レシピを含める 'ラッパー'料理本/レシピを作成します。