Class: Prepper::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/prepper/runner.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Runner

Returns a new instance of Runner.



14
15
16
17
18
19
20
# File 'lib/prepper/runner.rb', line 14

def initialize(config)
  @packages = []
  @commands = []
  @user = "root"
  @port = 22
  instance_eval config
end

Instance Attribute Details

#commandsObject

Returns the value of attribute commands.



6
7
8
# File 'lib/prepper/runner.rb', line 6

def commands
  @commands
end

#hostObject

Returns the value of attribute host.



6
7
8
# File 'lib/prepper/runner.rb', line 6

def host
  @host
end

#packagesObject

Returns the value of attribute packages.



6
7
8
# File 'lib/prepper/runner.rb', line 6

def packages
  @packages
end

#portObject

Returns the value of attribute port.



6
7
8
# File 'lib/prepper/runner.rb', line 6

def port
  @port
end

#userObject

Returns the value of attribute user.



6
7
8
# File 'lib/prepper/runner.rb', line 6

def user
  @user
end

Class Method Details

.run(config) ⇒ Object



8
9
10
11
12
# File 'lib/prepper/runner.rb', line 8

def self.run(config)
  runner = new(config)
  runner.run
  runner
end

Instance Method Details

#add_command(command, opts = {}) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/prepper/runner.rb', line 46

def add_command(command, opts = {})
  package = Package.new("base", opts)
  package.runner = self
  opts[:user] ||= "root"
  opts[:within] ||= "/"
  package.commands << Command.new(command, opts)
  @packages << package
end

#package(name, opts = {}, &block) ⇒ Object



55
56
57
# File 'lib/prepper/runner.rb', line 55

def package(name, opts = {}, &block)
  @packages << Package.new(name, opts.merge(runner: self), &block)
end

#runObject



22
23
24
# File 'lib/prepper/runner.rb', line 22

def run
  @packages.each(&:process)
end

#server_hashObject



42
43
44
# File 'lib/prepper/runner.rb', line 42

def server_hash
  {hostname: host, user: user, port: port, ssh_options: @ssh_options}
end

#server_host(host) ⇒ Object



26
27
28
# File 'lib/prepper/runner.rb', line 26

def server_host(host)
  @host = host
end

#server_port(port) ⇒ Object



34
35
36
# File 'lib/prepper/runner.rb', line 34

def server_port(port)
  @port = port
end

#server_user(user) ⇒ Object



30
31
32
# File 'lib/prepper/runner.rb', line 30

def server_user(user)
  @user = user
end

#ssh_options(ssh_options) ⇒ Object



38
39
40
# File 'lib/prepper/runner.rb', line 38

def ssh_options(ssh_options)
  @ssh_options = ssh_options
end