Sha256: e9d52f8e14d3d02a9a0fc6e95b1551b79d2dabc6823e00ab5786877fe4a40c56

Contents?: true

Size: 1.39 KB

Versions: 3

Compression:

Stored size: 1.39 KB

Contents

require 'itamae'

module Itamae
  class Runner
    class << self
      def run(recipe_files, backend_type, options)
        set_backend_from_options(backend_type, options)

        runner = self.new(node_from_options(options))

        recipe_files.each do |path|
          recipe = Recipe.new(runner, File.expand_path(path))
          recipe.run(dry_run: options[:dry_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 set_backend_from_options(type, options)
        opts = {}

        case type
        when :local
          # do nothing
        when :ssh
          opts[:host] = options[:host]
          opts[:user] = options[:user] || Etc.getlogin
          opts[:keys] = [options[:key]] if options[:key]
          opts[:port] = options[:port] if options[:port]
        end

        Backend.instance.set_type(type, opts)
      end
    end

    attr_accessor :node
    attr_accessor :tmpdir

    def initialize(node)
      @node = node
      @tmpdir = "/tmp/itamae_tmp"

      Backend.instance.run_command(["mkdir", "-p", @tmpdir])
      Backend.instance.run_command(["chmod", "777", @tmpdir])
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
itamae-1.0.0.beta6 lib/itamae/runner.rb
itamae-1.0.0.beta5 lib/itamae/runner.rb
itamae-1.0.0.beta4 lib/itamae/runner.rb