Sha256: 14cdef451aa6f91c813f9f46436a9ef5db27e0827398964f59d53641cbdc157c

Contents?: true

Size: 1.32 KB

Versions: 27

Compression:

Stored size: 1.32 KB

Contents

require 'pe_build/release'

require 'erb'

class PEBuild::Provisioner::PEBootstrap::AnswersFile

  # @param machine [Vagrant::Machine]
  # @param config [Object < Vagrant.plugin('2', :config)]
  # @param work_dir [String]
  def initialize(machine, config, work_dir)
    @machine, @config = machine, config
    @work_dir = Pathname.new(work_dir)

    @logger = Log4r::Logger.new('vagrant::provisioner::pe_bootstrap::answers_file')

    @answer_dir  = @work_dir.join('answers')
    @output_file = @answer_dir.join "#{@machine.name}.txt"

    set_template_path
  end

  def generate
    @logger.info "Writing answers file for #{@machine.inspect} to #{@output_file}"
    @answer_dir.mkpath unless @answer_dir.exist?

    @output_file.open('w') { |fh| fh.write(render_answers) }
  end

  private

  def set_template_path
    if @config.answer_file
      @template = @config.answer_file
      mode = 'explicit'
    else
      release_info = PEBuild::Release[@config.version]

      @template = release_info.answer_file(@config.role)
      mode = 'default'
    end

    @logger.info "Using #{mode} answers file template #{@template} for #{@machine.inspect}"
  end

  def render_answers
    template_data = File.read(@template)
    ERB.new(template_data).result(binding)
  end

  def machine_hostname
    @machine.config.vm.hostname || @machine.name
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
vagrant-pe_build-0.10.4 lib/pe_build/provisioner/pe_bootstrap/answers_file.rb
vagrant-pe_build-0.10.3 lib/pe_build/provisioner/pe_bootstrap/answers_file.rb
vagrant-pe_build-0.10.2 lib/pe_build/provisioner/pe_bootstrap/answers_file.rb
vagrant-pe_build-0.10.1 lib/pe_build/provisioner/pe_bootstrap/answers_file.rb
vagrant-pe_build-0.10.0 lib/pe_build/provisioner/pe_bootstrap/answers_file.rb
vagrant-pe_build-0.9.7 lib/pe_build/provisioner/pe_bootstrap/answers_file.rb
vagrant-pe_build-0.9.6 lib/pe_build/provisioner/pe_bootstrap/answers_file.rb
vagrant-pe_build-0.9.5 lib/pe_build/provisioner/pe_bootstrap/answers_file.rb
vagrant-pe_build-0.9.4 lib/pe_build/provisioner/pe_bootstrap/answers_file.rb
vagrant-pe_build-0.9.3 lib/pe_build/provisioner/pe_bootstrap/answers_file.rb
vagrant-pe_build-0.9.2 lib/pe_build/provisioner/pe_bootstrap/answers_file.rb
vagrant-pe_build-0.9.1 lib/pe_build/provisioner/pe_bootstrap/answers_file.rb
vagrant-pe_build-0.9.0 lib/pe_build/provisioner/pe_bootstrap/answers_file.rb
vagrant-pe_build-0.8.8 lib/pe_build/provisioner/pe_bootstrap/answers_file.rb
vagrant-pe_build-0.8.7 lib/pe_build/provisioner/pe_bootstrap/answers_file.rb
vagrant-pe_build-0.8.6 lib/pe_build/provisioner/pe_bootstrap/answers_file.rb
vagrant-pe_build-0.8.5 lib/pe_build/provisioner/pe_bootstrap/answers_file.rb
vagrant-pe_build-0.8.4 lib/pe_build/provisioner/pe_bootstrap/answers_file.rb
vagrant-pe_build-0.8.3 lib/pe_build/provisioner/pe_bootstrap/answers_file.rb
vagrant-pe_build-0.8.2 lib/pe_build/provisioner/pe_bootstrap/answers_file.rb