Sha256: 0b063e82eafedcbf3c62b6560c8206ee98366b922a7f49880811ff4fa8cdc37f

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

require 'itamae'

module Itamae
  class Runner
    class << self
      def run(recipe_files, backend, options)
        backend = backend_from_options(backend, options)
        runner = self.new
        runner.node = node_from_options(options)

        recipe_files.each do |path|
          recipe = Recipe.new(runner, File.expand_path(path))
          recipe.run
        end
      end

      private
      def node_from_options(options)
        if options[:node_json]
          path = File.expand_path(options[:node_json])
          Logger.debug "Loading node data from #{path} ..."
          hash = JSON.load(open(path))
        else
          hash = {}
        end

        Node.new(hash)
      end

      def backend_from_options(type, options)
        case type
        when :local
          Itamae.create_local_backend
        when :ssh
          ssh_options = {}
          ssh_options[:host] = options[:host]
          ssh_options[:user] = options[:user] || Etc.getlogin
          ssh_options[:keys] = [options[:key]] if options[:key]
          ssh_options[:port] = options[:port] if options[:port]

          Itamae.create_ssh_backend(ssh_options)
        end
      end
    end

    attr_accessor :node
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
itamae-1.0.0.beta3 lib/itamae/runner.rb
itamae-1.0.0.beta2 lib/itamae/runner.rb
itamae-1.0.0.beta1 lib/itamae/runner.rb