【发布时间】:2019-05-05 13:33:57
【问题描述】:
这是我的目标文件:
Sonatype Nexus
# ==============
# This is the most basic configuration of Nexus.
# Jetty section
application-port=8081
application-host=0.0.0.0
nexus-webapp=${bundleBasedir}/nexus
nexus-webapp-context-path=/nexus
# Nexus section
nexus-work=/opt/nexuswork
runtime=${bundleBasedir}/nexus/WEB-INF
我知道使用 regex 或简单的 sed 脚本可以轻松做到这一点:
sed -i 's/${bundleBasedir}\/..\/my\/second\/path\/002\/\/nexus/\/myfirstdir001\/g'
但是,理想情况下,我更喜欢 saltstack 方式。
我希望它看起来像这样:
Sonatype Nexus
# ==============
# This is the most basic configuration of Nexus.
# Jetty section
application-port=8081
application-host=0.0.0.0
nexus-webapp=/my/second/path/002/nexus # changed
nexus-webapp-context-path=/nexus
# Nexus section
nexus-work=/opt/nexuswork
runtime=/myfirstdir001/nexus/WEB-INF # changed
我还没有理解关于此的 saltstack 文档。
Saltstack 的 salt.states.file.replace 文档看起来相当简单:
http://docs.saltstack.com/en/latest/ref/states/all/salt.states.file.html#salt.states.file.replace
这是我尝试过的:
/opt/nexus-2.8.0/conf/nexus.properties
file: # state
- replace
- pattern: '\$\{bundleBasedir\}' # without escapes: '${bundleBasedir}/nexus'
- repl: '/my/second/path/002/nexus'
# - name: /opt/nexus-2.8.0/conf/nexus.properties
# - count=0
# - append_if_not_found=False
# - prepend_if_not_found=False
# - not_found_content=None
# - backup='.bak'
# - show_changes=True
- pattern: '\$\{bundleBasedir\}\/WEB-INF' # without escapes: ${bundleBasedir}/WEB-INF
- repl: '/myfirstdir001/'
我也许可以尝试多个状态 ID,但这似乎不优雅。
如果还有什么我生气的,请指教!
我很乐意找到解决此问题的方法。
另外,如果有人需要改进 salt 文档,我认为我的团队可能会被说服提供一些帮助。
这是我发现的最接近别人问这个问题的东西:
http://comments.gmane.org/gmane.comp.sysutils.salt.user/15138
【问题讨论】:
标签: replace nexus configuration-management salt-stack