qb 0.1.19 → 0.1.20

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 318feb9ed96e8436116afdc7ca6e9c0c36d3f856
4
- data.tar.gz: 270846ed027667040daf691f77d63e657118b6a2
3
+ metadata.gz: ca9d3309b203357ca3f60f6dadcc234a6deb6b0e
4
+ data.tar.gz: ea834af63ce3b9e275c9f51d80d3400db317ca56
5
5
  SHA512:
6
- metadata.gz: e8cac0e79f2255e01a801111e7bdc94aba54dddd5c553ae3be646e9348aa04df8dc0690a405193db4135c5f191a325ba033c937c45fa6e6ee6ed2dc81d378ba8
7
- data.tar.gz: 5202c0c0154ac74d51d2322c514b9556b5c924370d4405d4db2ec45edbb61d4fd0e79900b9193f74379ee4513e583186806ed7fc24b56b78d89a465f7b3ee212
6
+ metadata.gz: e77e6ddbca93822961261a701b5054ed523978af86d80bcfff0e940f108ff4bfdf189fc17450eefca050c6d5219c514cb9db1e911f10394f5afac3442cce07b4
7
+ data.tar.gz: 2e25ae51fc342efaf90179b2baae6c0289888e100e2dc9042b4ddb0e46bdc3f9ab4dbdb27df928dfd1d599065a8a615fc38155fe90562d675ec1c6207c207eb7
data/bin/qb CHANGED
@@ -2,11 +2,12 @@
2
2
  # stub instead of `bundle exec qb ...`
3
3
 
4
4
  # so you know you're using the local repo version (vs an installed gem)...
5
- puts "*** LOADING REPO VERSION ***\n\n"
5
+ puts "*** LOADING REPO VERSION ***"
6
6
 
7
7
  root = File.dirname(File.realpath(File.join(__FILE__, '..')))
8
8
 
9
9
  puts "source: #{ root }"
10
+ puts
10
11
 
11
12
  Dir.chdir root do
12
13
  require 'bundler/setup'
data/exe/qb CHANGED
@@ -28,7 +28,7 @@ TMP_DIR = ROOT + 'tmp'
28
28
  # format a debug message with optional key / values to print
29
29
  #
30
30
  # @param msg [String] message to print.
31
- # @param dump [Hash] optional hash of keys and vaues to dump.
31
+ # @param dump [Hash] optional hash of keys and values to dump.
32
32
  def format msg, dump = {}
33
33
  unless dump.empty?
34
34
  msg += "\n" + dump.map {|k, v| " #{ k }: #{ v.inspect }" }.join("\n")
@@ -103,9 +103,10 @@ def main args
103
103
  exit 1
104
104
  end
105
105
 
106
- options = QB::Options.parse! role, args
106
+ options, qb_options = QB::Options.parse! role, args
107
107
 
108
108
  debug "options set on cli", options.select {|k, o| !o.value.nil?}
109
+ debug "qb options", qb_options
109
110
 
110
111
  cwd = Dir.getwd
111
112
 
@@ -193,29 +194,35 @@ def main args
193
194
  playbook_role[option.var_name] = option.value
194
195
  end
195
196
 
196
- playbook = [
197
- {
198
- 'hosts' => 'localhost',
199
- 'vars' => playbook_vars,
200
- 'pre_tasks' => [
201
- # need ansible 2.1.2.0 at least to run
202
- {
203
- 'assert' => {
204
- 'that' => "'ansible 2.1.2' in lookup('pipe', 'ansible --version')",
205
- },
197
+ play =
198
+ {
199
+ 'hosts' => qb_options['hosts'],
200
+ 'vars' => playbook_vars,
201
+ 'pre_tasks' => [
202
+ # need ansible 2.1.2.0 at least to run
203
+ {
204
+ 'assert' => {
205
+ 'that' => "'ansible 2.1.2' in lookup('pipe', 'ansible --version')",
206
206
  },
207
- {
208
- 'qb_facts' => {
209
- 'qb_dir' => dir,
210
- }
211
- },
212
- ],
213
- 'roles' => [
214
- 'nrser.blockinfile',
215
- playbook_role
216
- ],
217
- }
218
- ]
207
+ },
208
+ {
209
+ 'qb_facts' => {
210
+ 'qb_dir' => dir,
211
+ }
212
+ },
213
+ ],
214
+ 'roles' => [
215
+ 'nrser.blockinfile',
216
+ playbook_role
217
+ ],
218
+ }
219
+
220
+ if qb_options['user']
221
+ play['become'] = true
222
+ play['become_user'] = qb_options['user']
223
+ end
224
+
225
+ playbook = [play]
219
226
 
220
227
  debug "playbook", playbook
221
228
 
@@ -243,15 +243,40 @@ module QB
243
243
  end # add
244
244
 
245
245
  def self.parse! role, args
246
- options = {}
246
+ role_options = {}
247
+
248
+ qb_options = {
249
+ 'hosts' => ['localhost'],
250
+ }
251
+
252
+ if role.meta['default_user']
253
+ qb_options['user'] = role.meta['default_user']
254
+ end
247
255
 
248
256
  opt_parser = OptionParser.new do |opts|
249
- opts.banner = "qb #{ role.name } [OPTIONS] DIRECTORY"
257
+ opts.banner = role.banner
258
+
259
+ opts.on(
260
+ '-H',
261
+ '---hosts=HOSTS',
262
+ Array,
263
+ "set playbook host",
264
+ "default: localhost"
265
+ ) do |value|
266
+ qb_options['hosts'] = value
267
+ end
268
+
269
+ opts.on(
270
+ '-U',
271
+ '---user=USER',
272
+ String,
273
+ "ansible become user for the playbook"
274
+ ) do |value|
275
+ qb_options['user'] = value
276
+ end
250
277
 
251
- add opts, options, role
278
+ add opts, role_options, role
252
279
 
253
- # No argument, shows at tail. This will print an options summary.
254
- # Try it and see!
255
280
  opts.on_tail("-h", "--help", "Show this message") do
256
281
  puts opts
257
282
  exit
@@ -260,7 +285,7 @@ module QB
260
285
 
261
286
  opt_parser.parse! args
262
287
 
263
- options
288
+ [role_options, qb_options]
264
289
  end # parse!
265
290
  end # Options
266
291
  end # QB
@@ -235,6 +235,26 @@ module QB
235
235
  !!meta_or('mkdir', true)
236
236
  end
237
237
 
238
+ # get the CLI banner for the role
239
+ def banner
240
+ lines = []
241
+
242
+ name_line = "#{ name } role"
243
+ lines << name_line
244
+ lines << "=" * name_line.length
245
+ lines << ''
246
+ if meta['description']
247
+ lines << meta['description']
248
+ lines << ''
249
+ end
250
+ lines << 'usage:'
251
+ lines << " qb #{ name } [OPTIONS] DIRECTORY"
252
+ lines << ''
253
+ lines << 'options:'
254
+
255
+ lines.join("\n")
256
+ end
257
+
238
258
  private
239
259
 
240
260
  # get the value at the first found of the keys or the default.
@@ -1,7 +1,7 @@
1
1
  module QB
2
2
  GEM_NAME = 'qb'
3
3
 
4
- VERSION = "0.1.19"
4
+ VERSION = "0.1.20"
5
5
 
6
6
  def self.gemspec
7
7
  Gem.loaded_specs[GEM_NAME]
@@ -40,6 +40,8 @@ def main():
40
40
  try:
41
41
  value = subprocess.check_output(cmd).rstrip()
42
42
  facts[key] = value
43
+ # depreciated old name
44
+ facts[key[3:]] = value
43
45
  except subprocess.CalledProcessError as e:
44
46
  pass
45
47
 
@@ -59,10 +61,6 @@ def main():
59
61
 
60
62
  facts['qb_gem_info'] = gem_info
61
63
 
62
- # depreciated namespaceless names
63
- facts['git_user_name'] = facts['qb_git_user_name']
64
- facts['git_user_email'] = facts['qb_git_user_email']
65
-
66
64
  changed = False
67
65
 
68
66
  module.exit_json(
@@ -4,10 +4,30 @@
4
4
  # qb settings for this role. see README.md for more info.
5
5
  #
6
6
 
7
+ # description of the role to show in it's help output.
8
+ description: null
9
+
7
10
  # prefix for role variables
8
11
  var_prefix: null
9
12
 
10
- # how to get a default for `dir` if it's not provided as the
13
+ # how to get a default for `dir` if it's not provided as the only
14
+ # positional argument. if a positional argument is provided it will
15
+ # override the method defined here.
16
+ #
17
+ # options:
18
+ #
19
+ # - null
20
+ # - require the value on the command line.
21
+ # - git_root
22
+ # - use the git root fof the directory that the `qb` command is invoked
23
+ # from. useful for 'project-centric' commands so they can be invoked
24
+ # from anywhere in the repo.
25
+ # - cwd
26
+ # - use the directory the `qb` command is invoked form.
27
+ # - {exe: PATH}
28
+ # - invoke an execuable, passing a JSON serialization of the options
29
+ # mapping their CLI names to values. path can be relative to role
30
+ # directory.
11
31
  default_dir: null
12
32
 
13
33
  # set to false to not save options in .qb-options.yml files
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.19
4
+ version: 0.1.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - nrser
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-24 00:00:00.000000000 Z
11
+ date: 2016-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler