runsible 0.1.4.5 → 0.1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/runsible.rb +23 -32
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c6e97e7684c0473f0b015ef7458fd181e3758aa
4
- data.tar.gz: 0683c11734db25fb288d7c27ccc0ec15dfb607c1
3
+ metadata.gz: 3555f9e44cc10f2dd93aaa61d532c2094db9c210
4
+ data.tar.gz: aa837e80e9aff3ff4e852dad7ddd1291a6f9c120
5
5
  SHA512:
6
- metadata.gz: ec0617e974d77b203aeb318c14c9ec132e1f3907cde4ef02b4e68185559d018931993eb33b7fb82bf630b0abc509e750ea749a6909d789df136eaa15180e8302
7
- data.tar.gz: efea1d51af58e32a02ff17a49b85ecc8b29da012c47357245d681e78b053ea9c31cfc990355d575a4f3bffecf310d8044baaa772ab236a44316f1fd7c14977f9
6
+ metadata.gz: 1c7d9e19f63ae44c4183170cca0783017fceec93c0f497a6cab2979cabc0ca48c2b33dc96ed63e0d193d1e6bd922350f400913e81fc0fc821dd5a8c9954d938f
7
+ data.tar.gz: 58aecf9c8b625cb252264e6281f46943775a14ebf674938ffd331302777c858dd5a58da371fb3baa8d9b48ba5fb4fc383637728fffc101e41322ecc028418371
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4.5
1
+ 0.1.5.1
@@ -6,13 +6,14 @@ autoload :Slop, 'slop'
6
6
  # - this module is deliberately written without private state
7
7
  # - whenever a remote command sends data to STDOUT or STDERR, Runsible will
8
8
  # immediately send it to the corresponding local IO
9
- # - Runsible itself writes some warnings and timestamped command delimeters to
9
+ # - Runsible itself writes some warnings and timestamped command delimiters to
10
10
  # STDOUT and STDERR
11
11
  #
12
12
  module Runsible
13
13
  class Error < RuntimeError; end
14
14
  class CommandFailure < Runsible::Error; end # nonzero exit
15
15
 
16
+ # defaults
16
17
  SETTINGS = {
17
18
  user: ENV['USER'],
18
19
  host: '127.0.0.1',
@@ -22,20 +23,18 @@ module Runsible
22
23
  }
23
24
  SSH_CNX_TIMEOUT = 10
24
25
 
25
- #
26
- # Utility stuff
27
- #
26
+ ### Utility stuff ###
28
27
 
29
28
  # provide a better string representation for all Exceptions
30
29
  def self.excp(excp)
31
30
  "#{excp.class}: #{excp.message}"
32
31
  end
33
32
 
34
- # return SETTINGS with string keys
35
- def self.default_settings
36
- hsh = {}
33
+ # return SETTINGS with string keys, using values from hsh if passed in
34
+ def self.apply_defaults(hsh = nil)
35
+ hsh ||= Hash.new
37
36
  SETTINGS.each { |sym, v|
38
- hsh[sym.to_s] = v
37
+ hsh[sym.to_s] ||= v
39
38
  }
40
39
  hsh
41
40
  end
@@ -45,7 +44,7 @@ module Runsible
45
44
  File.read(File.join(__dir__, '..', 'VERSION'))
46
45
  end
47
46
 
48
- # send alert depending on settings['alerts']['backend']
47
+ # send alert depending on settings
49
48
  def self.alert(topic, message, settings)
50
49
  backend = settings['alerts'] && settings['alerts']['backend']
51
50
  case backend
@@ -77,19 +76,7 @@ module Runsible
77
76
  exit 1
78
77
  end
79
78
 
80
-
81
- #
82
- # CLI or bin/runsible stuff
83
- #
84
-
85
- # bin/runsible entry point
86
- def self.spoon(ssh_options = Hash.new)
87
- opts = Runsible.slop_parse
88
- yaml = self.extract_yaml(opts)
89
- settings = Runsible.default_settings.merge(yaml['settings'] || Hash.new)
90
- settings = self.merge(opts, settings)
91
- self.ssh_runlist(settings, yaml['runlist'] || Array.new, ssh_options, yaml)
92
- end
79
+ ### CLI or bin/runsible stuff ###
93
80
 
94
81
  # parse CLI arguments
95
82
  def self.slop_parse
@@ -137,15 +124,21 @@ module Runsible
137
124
  exit 1
138
125
  end
139
126
 
140
- #
141
- # Library stuff
142
- #
127
+ # bin/runsible entry point
128
+ def self.spoon(ssh_options = Hash.new)
129
+ opts = Runsible.slop_parse
130
+ yaml = self.extract_yaml(opts)
131
+ settings = self.merge(opts, Runsible.apply_defaults(yaml['settings']))
132
+ self.ssh_runlist(settings, yaml['runlist'], ssh_options, yaml)
133
+ end
134
+
135
+ ### Library stuff ###
143
136
 
144
137
  # run a YAML file without any consideration for command line options
145
138
  def self.run_yaml(yaml_filename, ssh_options = Hash.new)
146
139
  yaml = YAML.load_file(yaml_filename)
147
- self.ssh_runlist(self.default_settings, yaml['runlist'] || Array.new,
148
- ssh_options, yaml)
140
+ settings = self.apply_defaults(yaml['settings'])
141
+ self.ssh_runlist(settings, yaml['runlist'], ssh_options, yaml)
149
142
  end
150
143
 
151
144
  # initiate ssh connection, perform the runlist
@@ -161,8 +154,9 @@ module Runsible
161
154
  end
162
155
 
163
156
  # execute runlist with failure handling, retries, alerting, etc.
157
+ # runlist can be nil
164
158
  def self.exec_runlist(ssh, runlist, settings, yaml = Hash.new)
165
- runlist.each { |run|
159
+ (runlist || Array.new).each { |run|
166
160
  cmd = run.fetch('command')
167
161
  retries = run['retries'] || settings['retries']
168
162
  on_failure = run['on_failure'] || 'exit'
@@ -238,10 +232,7 @@ module Runsible
238
232
  true
239
233
  end
240
234
 
241
-
242
- #
243
- # Necessities
244
- #
235
+ ### Necessities ###
245
236
 
246
237
  # opts has symbol keys, overrides settings (string keys)
247
238
  # return a hash with string keys
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runsible
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4.5
4
+ version: 0.1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rick Hull