use erb to parse the config file, useful for putting dynamic values
also mkdir -p the directory the ssh class cd's to, to avoid errors if the dir is not there.
This commit is contained in:
parent
969f834440
commit
89c16e11c4
|
@ -1,6 +1,7 @@
|
|||
require 'hydra/hash'
|
||||
require 'open3'
|
||||
require 'tmpdir'
|
||||
require 'erb'
|
||||
require 'yaml'
|
||||
module Hydra #:nodoc:
|
||||
# Hydra class responsible for delegate work down to workers.
|
||||
|
@ -31,7 +32,20 @@ module Hydra #:nodoc:
|
|||
opts.stringify_keys!
|
||||
config_file = opts.delete('config') { nil }
|
||||
if config_file
|
||||
opts.merge!(YAML.load_file(config_file).stringify_keys!)
|
||||
|
||||
begin
|
||||
config_erb = ERB.new(IO.read(config_file)).result(binding)
|
||||
rescue Exception => e
|
||||
raise(YmlLoadError,"config file was found, but could not be parsed with ERB.\n#{$!.inspect}")
|
||||
end
|
||||
|
||||
begin
|
||||
config_yml = YAML::load(config_erb)
|
||||
rescue StandardError => e
|
||||
raise(YmlLoadError,"config file was found, but could not be parsed.\n#{$!.inspect}")
|
||||
end
|
||||
|
||||
opts.merge!(config_yml.stringify_keys!)
|
||||
end
|
||||
@files = Array(opts.fetch('files') { nil })
|
||||
raise "No files, nothing to do" if @files.empty?
|
||||
|
|
|
@ -27,6 +27,7 @@ module Hydra #:nodoc:
|
|||
# list all the files.
|
||||
def initialize(connection_options, directory, command)
|
||||
@writer, @reader, @error = popen3("ssh -tt #{connection_options}")
|
||||
@writer.write("mkdir -p #{directory}\n")
|
||||
@writer.write("cd #{directory}\n")
|
||||
@writer.write(command+"\n")
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue