我使用Chef recipe來管理在Amazon EC2實例上運行的一些Tomcat服務器。在我需要使用大量相同Tomcat的情況下,它對我來說非常適合,它們都具有相同的.jars/Java選項/等等。使用廚師來管理具有實例特定內容的文件?
但是,我碰到一個用例,我不知道如何處理。基本上,每個Tomcat都有一個context.xml文件(位於/ etc/tomcat7),我希望配置這個文件,使其具有需要指向特定端點的Manager元素(Amazon中與其名稱對應的Elasticache,所以TomcatA有ElasticacheA等)。最初,我曾在我的食譜如下代碼以及相關的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
模板的context.xml:
<?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名稱值,但是如何確保Chef每次都不會使用該值覆蓋現有設置?理想情況下,配方的每次運行都會爲此模板產生新的結果,而不會影響已經使用的任何設置。