ansible_make_role 0.7.0 → 0.7.1

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
  SHA256:
3
- metadata.gz: 323dcdb66550dda4f21397b66c21524a16da617d120d05cd9382607cbe20e5d1
4
- data.tar.gz: d9332ca69d757e758f4ec996c2eb86a4676586bf24e457b47d6a6edbcaa0d8c3
3
+ metadata.gz: 29ff2c2883c8a8b4d51a218cd24759b9c30800cf3026da0baf6810ff7b277e46
4
+ data.tar.gz: af5a5ff7ba52f8738d90ae5933c98e31d315596eced5ad283611444867bc2708
5
5
  SHA512:
6
- metadata.gz: b461800f749cee4148bc39ee1221403830d31e4b0894d8b27c9dbd89b9297c9fc4bdaf0ad16e4ad998a3e7d231299b9fba42fb52dc3a14bdd58dedf9dab29abd
7
- data.tar.gz: 480a4a450cb337cb7272a300fb37eb69784e454b54600cef8a618da8e9f58251f2e57e5d88fa19db241f1158a549476141d123b69a6c3e703714f68a709431b6
6
+ metadata.gz: ef8c02faa05b9151e13d431a9d85ab96460a19cb2b898bc46f022a860cf57a7d82e83b7dc7974118cbb9364d7d5ecad09ffb2a142abdc6c998373435f72e0bac
7
+ data.tar.gz: 167cf5397c44fb3d961fb6a63ea0242956dcd7542d92af86f1d6c97449a8a0454c4fe62fc3a087a88bec529f2fedf02d2eec8bc6cd950d028aafcf7b9911fc2d
data/README.md CHANGED
@@ -5,7 +5,7 @@ Pre-compiler that turns `make.yml` files into Ansible roles
5
5
  ## Usage
6
6
 
7
7
  ```shell
8
- ansible-make-role -f|--force -t|--target-dir=DIR -v|--verbose DIR...
8
+ ansible-make-role -f|--force -v|--verbose --version DIR...
9
9
  ```
10
10
 
11
11
  `ansible-make-role` expects a `make.yml` file in each of the given directories
@@ -51,9 +51,23 @@ handlers: # Goes to handlers/main.yml"
51
51
  ...
52
52
  ```
53
53
 
54
+ ## Options
55
+
56
+
57
+ `-f, --force`
58
+ Re-generate all files even if not needed
59
+
60
+ `-v, --verbose`
61
+ Report progress
62
+
63
+ `--version`
64
+ Print version
65
+
66
+
54
67
  ## Installation
55
68
 
56
69
  Install it for the current ruby using:
57
70
 
58
71
  $ gem install ansible_make_role
59
72
 
73
+ Please note that the gem name uses underscores but the command uses dashes ('ansible-make-role')
@@ -3,26 +3,21 @@
3
3
  require 'ansible_make_role.rb'
4
4
  require "shellopts"
5
5
 
6
- USAGE = "f,force t,target-dir=DIR v,verbose -- DIRECTORY..."
6
+ USAGE = "f,force v,verbose version -- DIRECTORY..."
7
7
 
8
8
  force = false
9
- target_dir = nil
10
9
  verbose = false
11
10
 
12
11
  args = ShellOpts.process(USAGE, ARGV) { |opt, arg|
13
12
  case opt
14
13
  when '-f', '--force'; force = true
15
- when '-t', '--target-dir'; target_dir = arg
16
14
  when '-v', '--verbose'; verbose = true
15
+ when '--version'; puts "ansible-make-role #{AnsibleMakeRole::VERSION}"; exit
17
16
  end
18
17
  }
19
18
  args.size > 0 or args << "."
20
19
 
21
- include AnsibleMakeRole
22
20
  for source in args
23
21
  File.directory?(source) or ShellOpts.error "Not a directory: #{source.inspect}"
24
- target = target_dir || File.dirname(source)
25
- puts "Source: #{source}"
26
- puts "Target: #{target}"
27
- make_role(source, target, verbose: verbose, force: force)
22
+ AnsibleMakeRole.make(source, verbose: verbose, force: force)
28
23
  end
@@ -1,22 +1,37 @@
1
1
  require "ansible_make_role/version"
2
2
 
3
+ require "shellopts"
4
+
3
5
  require "fileutils"
4
6
 
5
7
  module AnsibleMakeRole
6
- class Error < StandardError; end
7
- # Your code goes here...
8
+ def self.make(source_dir, verbose: false, force: false)
9
+ source = "#{source_dir}/make.yml"
10
+ target_dir = source_dir
11
+ # TODO: Doesn't belong at this level - catch exceptions in exe instead
12
+ File.file?(source) or ShellOpts::error "Can't read file #{source.inspect}"
13
+ File.directory?(target_dir) or ShellOpts::error "Can't find directory #{target_dir}"
8
14
 
15
+ meta_yml = "#{target_dir}/meta/main.yml"
16
+ if force || !File.exist?(meta_yml) || File.mtime(source) > File.mtime(meta_yml)
17
+ compile_role(source, target_dir, verbose: verbose)
18
+ else
19
+ puts "#{target_dir} is up to date" if verbose
20
+ end
21
+ end
22
+
23
+ private
9
24
  # source is a file, target is a directory. Target can be nil and defaults to
10
25
  # dirname of source
11
- def compile_role(source, target = File.dirname(source), verbose: false)
26
+ def self.compile_role(source, target, verbose: false)
27
+ meta = []
12
28
  sections = {
13
- "meta" => [],
14
29
  "defaults" => [],
15
30
  "vars" => [],
16
31
  "tasks" => [],
17
32
  "handlers" => []
18
33
  }
19
- lines = sections["meta"]
34
+ current_section = meta
20
35
 
21
36
  puts "Parsing #{source}" if verbose
22
37
  File.readlines(source).each { |line|
@@ -25,17 +40,17 @@ module AnsibleMakeRole
25
40
  if line =~ /^(\w+)\s*:/
26
41
  section = $1
27
42
  if sections.key?(section) # Built-in section?
28
- lines = sections[section]
43
+ current_section = sections[section]
29
44
  else # Everything else goes to the meta file incl. section header
30
- lines = sections["meta"]
31
- lines << line
45
+ current_section = meta
46
+ current_section << line
32
47
  end
33
48
  else
34
- lines << line
49
+ current_section << line
35
50
  end
36
51
  }
37
52
 
38
- sections.each { |section, lines|
53
+ (sections.to_a + [["meta", meta]]).each { |section, lines|
39
54
  next if lines.empty? && section != "meta"
40
55
  dir = "#{target}/#{section}"
41
56
  file = "#{dir}/main.yml"
@@ -49,29 +64,13 @@ module AnsibleMakeRole
49
64
  }
50
65
  end
51
66
 
52
- def make_role(source_dir, target_dir = source_dir, verbose: false, force: false)
53
- source = "#{source_dir}/make.yml"
54
- target = "#{target_dir}/#{File.basename(source_dir)}"
55
- File.file?(source) or ShellOpts::error "Can't read file #{source.inspect}"
56
- File.directory?(target_dir) or ShellOpts::error "Can't find directory #{target_dir}"
57
-
58
- meta_yml = "#{target}/meta/main.yml"
59
- if force || !File.exist?(meta_yml) || File.mtime(source) > File.mtime(meta_yml)
60
- compile_role(source, target, verbose: verbose)
61
- else
62
- puts "#{target} is up to date" if verbose
63
- end
64
- end
65
-
66
- private
67
67
  # Unindent lines by the indentation of the first non-comment and non-blank
68
68
  # line
69
- def unindent(lines)
69
+ def self.unindent(lines)
70
70
  line = lines.find { |l| l !~ /^\s*#/ && l !~ /^\s*$/ }
71
71
  return lines if line.nil?
72
72
  line =~ /^(\s*)/
73
73
  prefix = $1.dup
74
74
  lines.map { |l| l.sub(/^#{prefix}/, "") }
75
75
  end
76
-
77
76
  end
@@ -1,3 +1,3 @@
1
1
  module AnsibleMakeRole
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ansible_make_role
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-13 00:00:00.000000000 Z
11
+ date: 2020-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler