【问题标题】:SSHKit command or Capistrano task to filter/replace tokens on uploadSSHKit 命令或 Capistrano 任务在上传时过滤/替换令牌
【发布时间】:2018-12-19 20:06:41
【问题描述】:

我正在使用 Capistrano 为遗留的非 Ruby 应用程序部署配置文件,出于神秘的遗留原因,需要使用目标主机的完全限定名称对其进行参数化,例如

name: myservice-stg
identifier: myservice-stg-1.example.org:8675
baseURI: http://myservice-stg-1.example.org:8675

除此之外,对于给定的环境,配置文件之间没有区别,所以我希望能够只定义一个模板(示例使用 Mustache,但可以是 ERB 或其他):

name: myservice-stg
identifier: {{fqhn}}:8675
baseURI: http://{{fqhn}}:8675

我目前对 hack 的想法是使用 gsubStringIO

config_tmpl = File.open('/config/src/config.txt')
config_txt = config_tmpl.gsub('{{fqhn}}', host.hostname)
upload!(StringIO.new(config_txt), 'dest/config.txt')

但似乎应该有一个更标准、开箱即用的解决方案。

【问题讨论】:

    标签: capistrano sshkit


    【解决方案1】:

    像 Ansible 和 Chef 这样的工具非常适合这个,但如果这就是你想要做的所有事情,可能会有点矫枉过正。

    您提出的解决方案看起来相当标准。使用 ERB(或其他模板系统)不会做更多的工作,并提供了灵活性/可重用性:

    template_path = File.open('/config/src/config.txt.erb')
    config_txt = ERB.new(File.new(template_path).read).result(binding)
    upload! StringIO.new(config_txt), 'dest/config.txt', mode: 0644
    

    ERB:

    name: myservice-stg
    identifier: <%= host.hostname %>:8675
    baseURI: http://<%= host.hostname %>:8675
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-16
      • 2019-12-19
      • 1970-01-01
      • 2016-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多