Class: Amigrind::Blueprints::Provisioners::RemoteShell

Inherits:
Amigrind::Blueprints::Provisioner show all
Defined in:
lib/amigrind/blueprints/provisioners/remote_shell.rb

Instance Method Summary collapse

Methods inherited from Amigrind::Blueprints::Provisioner

#racker_name

Instance Method Details

#command=(cmd) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/amigrind/blueprints/provisioners/remote_shell.rb', line 19

def command=(cmd)
  raise "'command' must be a String or an array of String." \
    unless cmd.is_a?(String) ||
           (cmd.respond_to?(:all?) && cmd.all? { |l| l.is_a?(String) })

  @inline = cmd.is_a?(String) ? cmd.split("\n") : cmd
end

#environment_vars=(vars) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/amigrind/blueprints/provisioners/remote_shell.rb', line 27

def environment_vars=(vars)
  raise "'vars' must be a Hash with Symbol or String keys and stringable values." \
    unless vars.all? { |k, v| (k.is_a?(Symbol) || k.is_a?(String)) && v.respond_to?(:to_s)}

  @env_vars =
    (@env_vars || {}).merge(vars.map { |k, v| [ k.to_s, v.to_s ] }.to_h)
end

#run_as_root!Object



15
16
17
# File 'lib/amigrind/blueprints/provisioners/remote_shell.rb', line 15

def run_as_root!
  @execute_command = "{{ .Vars }} sudo -E -S sh '{{ .Path }}'"
end

#to_racker_hashObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/amigrind/blueprints/provisioners/remote_shell.rb', line 35

def to_racker_hash
  # This trims leading whitespace off of heredoc commands, but leaves
  # them as inlines. They're easier to read when you have to look at the Packer
  # output when you do this.
  trim_count = @inline.map { |line| line[/\A */].size }.min
  lines = @inline.map { |line| line[trim_count..-1] }

  {
    type: 'shell',
    binary: @binary,
    inline: lines,
    scripts: @scripts,
    environment_vars: (@env_vars || {}).map { |k, v| "#{k}=#{v}" },
    execute_command: @execute_command,
    inline_shebang: @inline_shebang,
    start_retry_timeout:
      @start_retry_timeout.nil? ? nil : "#{@start_retry_timeout}s"
  }
end