qb 0.1.55 → 0.1.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82118c8f18b2147d380af7b988da02cf1c81d965
4
- data.tar.gz: ad75036b23b4e2ec7a4d59ecc1fedc46179f2ea5
3
+ metadata.gz: a3ccd247eed4ac55327f18af1328683369b781c8
4
+ data.tar.gz: 036e4e71a58d83a99137b27c61e44a6bbbf99247
5
5
  SHA512:
6
- metadata.gz: 88d65f3c512013f500b1110bde91f993e557da913f476b5242391059b07e5c799750d3715b22a13dc992ac63807f9e18627f249cb13aaaff656eb8dc9fa869db
7
- data.tar.gz: 3443133b5aa046953e3d4a62b3b0dfa7e2d4eff36e02696f159aa1f27495f61f144321189526835f2c396179b0909cd129975478255b4b426e6e2609139eef0c
6
+ metadata.gz: b9034e575a08fd1fffb4973fcc5f7c4e3a7055927c8bf07be2cf01e828a3d314cee408b283223cf4458e14dc4217f603d7ba37aaccc84f912022b2a1ba28b39e
7
+ data.tar.gz: 2593c3192c626701c2017d51c55cdf30df3359c52245acf69a09616f5e47ea635fff64865d14845bd783eade72cff24d1524420c9dc054ddda68747d85e372fc
@@ -2,10 +2,16 @@ require 'json'
2
2
 
3
3
  module QB
4
4
  class AnsibleModule
5
+ @@arg_types = {}
6
+
5
7
  def self.stringify_keys hash
6
8
  hash.map {|k, v| [k.to_s, v]}.to_h
7
9
  end
8
10
 
11
+ def self.arg name, type
12
+ @@arg_types[name.to_sym] = type
13
+ end
14
+
9
15
  def initialize
10
16
  @changed = false
11
17
  @input_file = ARGV[0]
@@ -23,6 +29,20 @@ module QB
23
29
  if ENV['QB_STDIO_ERR']
24
30
  $stderr = UNIXSocket.new ENV['QB_STDIO_ERR']
25
31
  end
32
+
33
+ @@arg_types.each {|key, type|
34
+ var_name = "@#{ key.to_s }"
35
+
36
+ unless instance_variable_get(var_name).nil?
37
+ raise ArgumentError.new NRSER.squish <<-END
38
+ an instance variable named #{ var_name } exists
39
+ with value #{ instance_variable_get(var_name).inspect }
40
+ END
41
+ end
42
+
43
+ instance_variable_set var_name,
44
+ type.check(@args.fetch(key.to_s))
45
+ }
26
46
  end
27
47
 
28
48
  def run
@@ -1,7 +1,7 @@
1
1
  module QB
2
2
  GEM_NAME = 'qb'
3
3
 
4
- VERSION = "0.1.55"
4
+ VERSION = "0.1.56"
5
5
 
6
6
  def self.gemspec
7
7
  Gem.loaded_specs[GEM_NAME]
@@ -2,10 +2,14 @@
2
2
  # WANT_JSON
3
3
  # ^ i think this is something telling ansible to provide JSON args?
4
4
 
5
+ # stdlib
5
6
  require 'json'
6
7
  require 'shellwords'
7
8
  require 'pp'
8
9
 
10
+ # deps
11
+ require 'nrser'
12
+
9
13
  def namespace prefix, hash
10
14
  Hash[
11
15
  hash.map {|key, value|
@@ -33,7 +37,7 @@ def main
33
37
  end
34
38
  end
35
39
 
36
- result = b.eval args['src']
40
+ result = b.eval args.fetch('src')
37
41
 
38
42
  if result.is_a? Hash
39
43
  result = namespace(args['namespace'], result) if args['namespace']
@@ -47,13 +51,30 @@ def main
47
51
  })
48
52
 
49
53
  rescue Exception => e
54
+ path = File.join Dir.pwd, "ansible-error.log"
55
+ msg = NRSER.squish <<-END
56
+ vars.rb failed: #{ e.message } (#{ e.class.name }).
57
+ See #{ path } for details.
58
+ END
59
+
60
+ File.open(path, 'w') {|f|
61
+ f.puts "ERROR:\n\n"
62
+ f.puts NRSER.indent(NRSER.format_exception(e))
63
+
64
+ f.puts "\nINPUT:\n\n"
65
+ f.puts NRSER.indent(input) if defined? input
66
+
67
+ f.puts "\nARGS:\n\n"
68
+ f.puts NRSER.indent(args.pretty_inspect) if defined? args
69
+
70
+ f.puts "\nRUBY:\n"
71
+ f.puts NRSER.indent("VERSION: #{ RUBY_VERSION }")
72
+ f.puts NRSER.indent("PATH: #{ RbConfig.ruby }")
73
+ }
74
+
50
75
  print JSON.dump({
51
76
  'failed' => true,
52
- 'msg' => e.message,
53
- # 'input' => input,
54
- # 'args' => args,
55
- # 'ARGV' => ARGV,
56
- # 'ruby' => RUBY_VERSION,
77
+ 'msg' => msg,
57
78
  })
58
79
  end
59
80
  end
@@ -0,0 +1,8 @@
1
+ ---
2
+ # meta file for qb.git_check_clean
3
+
4
+ allow_duplicates: yes
5
+
6
+ dependencies: []
7
+ # - role: role-name
8
+
@@ -0,0 +1,19 @@
1
+ ---
2
+ # tasks file for qb.git_check_clean
3
+
4
+ - name: >
5
+ get git status for repo {{ git_check_clean_dir }}
6
+ shell: git status --porcelain 2>/dev/null
7
+ args:
8
+ chdir: "{{ git_check_clean_dir }}"
9
+ register: git_check_clean_status
10
+ changed_when: false
11
+
12
+ - name: >
13
+ fail if the repo has any untracked or modified files
14
+ fail:
15
+ msg: >
16
+ repo at {{ git_check_clean_dir }} can not have any untracked or
17
+ modified files, please commit or stash and retry.
18
+ when: (git_check_clean_status.stdout_lines | length) != 0
19
+
@@ -4,5 +4,3 @@
4
4
  # default the encapsulated qb.role's `role-dest` to `qb_dir` so we can be
5
5
  # sure to be able to use it here... not sure if needed.
6
6
  role_dest: "{{ qb_dir }}"
7
-
8
- qb_role_modules: []
@@ -10,19 +10,6 @@ var_prefix: null
10
10
  # how to get a default for `dir` if it's not provided as the
11
11
  default_dir: null
12
12
 
13
- options:
14
- - name: modules
15
- description: >-
16
- create ruby module boilerplate(s) in library using QB::AnsibleModule.
17
- type: array
18
- required: false
19
- # TODO not yet implemented
20
- implies: library
21
- examples:
22
- - |
23
- produces library/some_module execuable with a module named SomeModule
24
-
25
- --modules=some_module
26
-
13
+ options:
27
14
  - include: qb.role
28
15
  as: false
@@ -11,9 +11,4 @@
11
11
  src: qb.yml.j2
12
12
  dest: "{{ role_dest }}/meta/qb.yml"
13
13
  force: false
14
-
15
- - include: module.yml
16
- with_items: "{{ qb_role_modules }}"
17
- loop_control:
18
- loop_var: qb_role_module
19
14
 
@@ -13,6 +13,9 @@ role_vars: false
13
13
  role_readme: false
14
14
  role_library: false
15
15
 
16
+ # modules
17
+ qb_role_modules: []
18
+
16
19
  # galaxy
17
20
  role_galaxy: false
18
21
  role_author: "{{ git_user_name }}"
@@ -76,6 +76,19 @@ vars:
76
76
  type: boolean
77
77
  description: create a project repo for this role
78
78
  short: p
79
+
80
+ - name: modules
81
+ description: >-
82
+ create ruby module boilerplate(s) in library using QB::AnsibleModule.
83
+ type: array
84
+ required: false
85
+ # TODO not yet implemented
86
+ implies: library
87
+ examples:
88
+ - |
89
+ produces library/some_module execuable with a module named SomeModule
90
+
91
+ --modules=some_module
79
92
 
80
93
  - include: qb.project
81
94
 
@@ -141,4 +141,11 @@
141
141
  dest: "{{ role_dest }}/library/.gitkeep"
142
142
  force: "{{ role_force }}"
143
143
  when: role_library
144
-
144
+
145
+ # modules
146
+ # =======
147
+
148
+ - include: module.yml
149
+ with_items: "{{ role_modules }}"
150
+ loop_control:
151
+ loop_var: role_module
@@ -0,0 +1,20 @@
1
+ ---
2
+ - set_fact:
3
+ role_module_class: "{{ role_module | class_case }}"
4
+ role_module_path: "{{ role_dest }}/library/{{ role_module }}"
5
+
6
+ - name: create library directory
7
+ file:
8
+ dest: "{{ role_module_path | dirname }}"
9
+ state: directory
10
+
11
+ - name: "create {{ role_module }} module"
12
+ template:
13
+ src: library/module.rb.j2
14
+ dest: "{{ role_module_path }}"
15
+ force: "{{ role_force }}"
16
+
17
+ - name: "make library/{{ role_module }} executable"
18
+ file:
19
+ path: "{{ role_module_path }}"
20
+ mode: a+x
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+ # WANT_JSON
3
+
4
+ # init bundler in dev env
5
+ if ENV['QB_DEV_ENV']
6
+ ENV.each {|k, v|
7
+ if k.start_with? 'QB_DEV_ENV_'
8
+ ENV[k.sub('QB_DEV_ENV_', '')] = v
9
+ end
10
+ }
11
+ require 'bundler/setup'
12
+ end
13
+
14
+ require 'qb'
15
+ require 'nrser'
16
+
17
+ class {{ role_module_class }} < QB::AnsibleModule
18
+ # define arg names to NRSER::Types::Type instances here and they
19
+ # will be type checked and set as @<name>
20
+ #
21
+ # example:
22
+ #
23
+ # arg :x, NRSER::Types.array(String)
24
+ #
25
+ # will check that the input json has a key named 'x' and that it's value
26
+ # is an Array of String instances, then set it's value as `@x`.
27
+ #
28
+
29
+ # entry point for the module. invoked by {\#run}.
30
+ #
31
+ # @return [nil | {Symbol => #to_json}]
32
+ # when returning:
33
+ #
34
+ # - `nil`: module will successfully exit with no additional changes.
35
+ #
36
+ # - `{Symbol => #to_json}`: Hash will be merged over @facts that
37
+ # are returned by the module to be set in the Ansible runtime and
38
+ # the module will exit successfully.
39
+ #
40
+ def main
41
+ return nil
42
+ end # #main
43
+ end # {{ role_module_class }}
44
+
45
+ {{ role_module_class }}.new.run
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.55
4
+ version: 0.1.56
5
5
  platform: ruby
6
6
  authors:
7
7
  - nrser
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-11 00:00:00.000000000 Z
11
+ date: 2017-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -276,8 +276,8 @@ files:
276
276
  - roles/nrser.blockinfile/tests/test-replace.yml
277
277
  - roles/nrser.blockinfile/tests/test-state.yml
278
278
  - roles/nrser.rb/.gitignore
279
- - roles/nrser.rb/library/sync.rb
280
- - roles/nrser.rb/library/vars.rb
279
+ - roles/nrser.rb/library/sync.rb.rb
280
+ - roles/nrser.rb/library/vars.rb.rb
281
281
  - roles/nrser.rb/meta/main.yml
282
282
  - roles/nrser.rbenv_gem/README.md
283
283
  - roles/nrser.rbenv_gem/VERSION
@@ -328,6 +328,8 @@ files:
328
328
  - roles/qb.gem/templates/spec.rb.j2
329
329
  - roles/qb.gem/templates/spec_helper.rb.j2
330
330
  - roles/qb.gem/templates/version.rb.j2
331
+ - roles/qb.git_check_clean/meta/main.yml
332
+ - roles/qb.git_check_clean/tasks/main.yml
331
333
  - roles/qb.git_repo/defaults/main.yml
332
334
  - roles/qb.git_repo/meta/main.yml
333
335
  - roles/qb.git_repo/meta/qb.yml
@@ -575,9 +577,7 @@ files:
575
577
  - roles/qb.qb_role/meta/main.yml
576
578
  - roles/qb.qb_role/meta/qb.yml
577
579
  - roles/qb.qb_role/tasks/main.yml
578
- - roles/qb.qb_role/tasks/module.yml
579
580
  - roles/qb.qb_role/templates/.gitkeep
580
- - roles/qb.qb_role/templates/module.rb.j2
581
581
  - roles/qb.qb_role/templates/qb.yml.j2
582
582
  - roles/qb.read_json/defaults/main.yml
583
583
  - roles/qb.read_json/meta/main.yml
@@ -596,10 +596,12 @@ files:
596
596
  - roles/qb.role/meta/main.yml
597
597
  - roles/qb.role/meta/qb.yml
598
598
  - roles/qb.role/tasks/main.yml
599
+ - roles/qb.role/tasks/module.yml
599
600
  - roles/qb.role/templates/.gitkeep
600
601
  - roles/qb.role/templates/README.md.j2
601
602
  - roles/qb.role/templates/defaults/main.yml.j2
602
603
  - roles/qb.role/templates/handlers/main.yml.j2
604
+ - roles/qb.role/templates/library/module.rb.j2
603
605
  - roles/qb.role/templates/meta/main.yml.j2
604
606
  - roles/qb.role/templates/tasks/main.yml.j2
605
607
  - roles/qb.role/templates/vars/main.yml.j2
@@ -1,20 +0,0 @@
1
- ---
2
- - set_fact:
3
- qb_role_module_class: "{{ qb_role_module | class_case }}"
4
- qb_role_module_path: "{{ role_dest }}/library/{{ qb_role_module }}"
5
-
6
- - name: create library directory
7
- file:
8
- dest: "{{ qb_role_module_path | dirname }}"
9
- state: directory
10
-
11
- - name: "create {{ qb_role_module }} module"
12
- template:
13
- src: module.rb.j2
14
- dest: "{{ qb_role_module_path }}"
15
- force: "{{ role_force }}"
16
-
17
- - name: "make library/{{ qb_role_module }} executable"
18
- file:
19
- path: "{{ qb_role_module_path }}"
20
- mode: a+x
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # WANT_JSON
3
-
4
- # init bundler in dev env
5
- if ENV['QB_DEV_ENV']
6
- ENV.each {|k, v|
7
- if k.start_with? 'QB_DEV_ENV_'
8
- ENV[k.sub('QB_DEV_ENV_', '')] = v
9
- end
10
- }
11
- require 'bundler/setup'
12
- end
13
-
14
- require 'qb'
15
-
16
- class {{ qb_role_module_class }} < QB::AnsibleModule
17
- def main
18
- nil
19
- end
20
- end
21
-
22
- {{ qb_role_module_class }}.new.run