I'm using Capistrano to deploy configuration files for a legacy non-Ruby application, that for arcane legacy reasons need to be parameterized with the fully-qualified name of the target host, e.g.
name: myservice-stg
identifier: myservice-stg-1.example.org:8675
baseURI: http://myservice-stg-1.example.org:8675
Apart from that, for a given environment, there's no difference between the config files, so I'd like to be able to just define a template (example uses Mustache but could be ERB or whatever):
name: myservice-stg
identifier: {{fqhn}}:8675
baseURI: http://{{fqhn}}:8675
My current idea for a hack is just to use gsub
and a StringIO
:
config_tmpl = File.open('/config/src/config.txt')
config_txt = config_tmpl.gsub('{{fqhn}}', host.hostname)
upload!(StringIO.new(config_txt), 'dest/config.txt')
But it seems like there ought to be a more standard, out-of-the box solution.