generate-puppetfile 1.0.0 → 1.1.0

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: 20ff01c403b03aacd1a849c841fef1723543d739
4
- data.tar.gz: 2571ee7127adad7638a9e0cf2f1f773cc7d1bf96
3
+ metadata.gz: 614002454318ec3de6dc470fad81e00e57c2b750
4
+ data.tar.gz: 39bb78f3cd1d05d32e3c298e0d8b0eacf66b5a6e
5
5
  SHA512:
6
- metadata.gz: a3d7878cea4c6ccb4ede987cd424cdeddae79c8f79f80ca835af479a0d28fbc944406b8e7d327bf24b42c1ad419f57f81e9eb0f3f55c7706b30cf56c6ff14e5c
7
- data.tar.gz: 14eff83bc5121fefe0736e19e28fe6a5c7bd4edc8a0b85c66366ec5781e806c5ea186663267aeb2a7c914713f672aafeef537238849c9330e10a9ffc5d7366c4
6
+ metadata.gz: 73859a79af4d3b17769eaa18499f684b29ec91a5850bf5149d5bc7f74ca06515921a1b727bfb918c50c75b6502ec6a90aa442db5b859b67dee971139fe2801df
7
+ data.tar.gz: 8e267c59fc4b76f4276b351b73c2a621d70e3ec586304156692afe007200e8c4ffedc5073b265df82e4caa7e231d209f91d0a451cbe26dbe8191618d54f2def7
data/README.md CHANGED
@@ -100,6 +100,39 @@ mod 'lab_config',
100
100
  :git => 'git@github.com:puppetinabox/lab_config.git'
101
101
  =======================================================================
102
102
  ```
103
+ #### extending puppet modules & bolt projects
104
+
105
+ Due to the nature of the generate-puppetfile gem it makes an excellent tool for developing the Puppetfile for [bolt projects]( https://puppet.com/docs/bolt/latest/bolt_project_directories.html). Seeing the simplest way to create a Bolt project is with the Puppet PDK this approach extends that use case. Add the following to your `.sync.yml` in a pdk managed module and run `pdk update`.zd
106
+
107
+ ```
108
+ Gemfile:
109
+ optional:
110
+ ':development':
111
+ - gem: 'generate-puppetfile'
112
+ version: '~> 1.0
113
+ ```
114
+
115
+ Add the following to `/rakelib/generate_puppetfile.rake` to create a rake target for the experimental `pdk bundle` feature. You can then use `pdk bundle exec rake generate_puppetfile` to generate the puppetfile based on the modules metadata.
116
+
117
+ ```
118
+ require 'json'
119
+
120
+ desc 'generate puppetfile'
121
+ task :generate_puppetfile, [:mod] do |t, args|
122
+ args.with_defaults(:mod => JSON.parse(File.read('metadata.json'))['name'])
123
+ sh "generate-puppetfile -c #{args.mod}"
124
+ end
125
+ ```
126
+ Add the following to `/rakelib/generate_fixturesfile.rake` to create a rake target for the experimental `pdk bundle` feature. You can then use `pdk bundle exec rake generate_fixturesfile` to generate the `.fixtures.yaml` based on the module metadata to aid in testing with the `pdk test` feature.
127
+
128
+ ```
129
+ desc 'generate fixtures'
130
+ task :generate_fixturesfile do |t|
131
+ mod = JSON.parse(File.read('metadata.json'))['name']
132
+ sh "generate-puppetfile -f -p ./Puppetfile #{mod} --fixtures-only -m #{mod}"
133
+ end
134
+ ```
135
+
103
136
 
104
137
  ## Limitations
105
138
 
@@ -11,11 +11,11 @@ require 'uri'
11
11
  module GeneratePuppetfile
12
12
  # Internal: The Bin class contains the logic for calling generate_puppetfile at the command line
13
13
  class Bin
14
- Module_Regex = %r{^\s*mod ['\"]([a-z0-9_]+\/[a-z0-9_]+)['\"](,\s+['\"](\d+\.\d+\.\d+)['\"])?\s*$}
15
- Repository_Regex = %r{^\s*mod\s+['\"](\w+)['\"]\s*,\s*$}
16
- Location_Only_Regex = %r{^\s+:git\s+=>\s+['\"](\S+)['\"]\s*$}
17
- Location_Plus_Regex = %r{^\s+:git\s+=>\s+['\"](\S+)['\"]\s*,\s*$}
18
- Type_ID_Regex = %r{^\s+:(\w+)\s+=>\s+['\"](\S+)['\"]\s*$}
14
+ Module_Regex = %r{^\s*mod ['"]([a-z0-9_]+[/-][a-z0-9_]+)['"](,\s+['"](\d+\.\d+\.\d+)['"])?\s*(?:#.*)?$}i
15
+ Repository_Regex = %r{^\s*mod\s+['"](\w+)['"]\s*,\s*(?:#.*)?$}i
16
+ Location_Only_Regex = %r{^\s+:git\s+=>\s+['"](\S+)['"]\s*(?:#.*)?$}i
17
+ Location_Plus_Regex = %r{^\s+:git\s+=>\s+['"](\S+)['"]\s*,\s*(?:#.*)?$}i
18
+ Type_ID_Regex = %r{^\s+:(\w+)\s+=>\s+['"](\S+)['"]\s*(?:#.*)?$}i
19
19
  Forge_Regex = %r{^forge}
20
20
  Blanks_Regex = %r{^\s*$}
21
21
  Comments_Regex = %r{^\s*#}
@@ -435,6 +435,7 @@ forge 'https://forge.puppet.com'
435
435
  paths = modulepath.split(':').delete_if { |path| path =~ /^\$/ }
436
436
  paths.each do |path|
437
437
  Dir["#{path}/*"].each do |module_location|
438
+ next unless File.directory?(module_location)
438
439
  module_name = File.basename(module_location)
439
440
  module_path = module_location
440
441
  symlinks << {
@@ -456,14 +457,14 @@ forge 'https://forge.puppet.com'
456
457
  fixtures_data = "fixtures:\n"
457
458
  if symlinks
458
459
  fixtures_data += " symlinks:\n"
459
- symlinks.each do |symlink|
460
+ symlinks.sort_by!{|symlink| symlink[:name]}.each do |symlink|
460
461
  fixtures_data += " #{symlink[:name]}: #{symlink[:path]}\n"
461
462
  end
462
463
  end
463
464
 
464
465
  unless @repository_data.empty?
465
466
  fixtures_data += " repositories:\n"
466
- @repository_data.each do |repodata|
467
+ @repository_data.sort_by!{|repo| repo[:name]}.each do |repodata|
467
468
  # Each repository has two or pieces of data
468
469
  # Mandatory: the module name, the URI/location
469
470
  # Optional: the type (ref, branch, commit, etc.) and ID (tag, branch name, commit hash, etc.)
@@ -476,7 +477,7 @@ forge 'https://forge.puppet.com'
476
477
  #{name}:
477
478
  repo: "#{location}"
478
479
  EOF
479
- data += " #{type}: \"#{id}\"\n" if (type && id)
480
+ data += " #{type}: \"#{id}\"\n" unless @options[:latest_versions] || !type || !id
480
481
 
481
482
  fixtures_data += data
482
483
  end
@@ -485,15 +486,14 @@ forge 'https://forge.puppet.com'
485
486
 
486
487
  unless @module_data.empty?
487
488
  fixtures_data += " forge_modules:\n"
488
- @module_data.keys.each do |modulename|
489
- shortname = modulename.split('/')[1]
489
+ @module_data.keys.sort_by!{|mod| mod.split(/[\/-]/)[1]}.each do |modulename|
490
+ shortname = modulename.split(/[\/-]/)[1]
490
491
  version = @module_data[modulename]
491
492
  data = <<-EOF
492
493
  #{shortname}:
493
494
  repo: "#{modulename}"
494
- ref: "#{version}"
495
495
  EOF
496
- data.gsub!(/^ *ref.*$\n/, '') unless version != nil
496
+ data += " ref: \"#{version}\"\n" unless @options[:latest_versions] || version.nil?
497
497
 
498
498
  fixtures_data += data
499
499
  end
@@ -36,6 +36,10 @@ module GeneratePuppetfile
36
36
  options[:modulename] = name
37
37
  end
38
38
 
39
+ opts.on('-l', '--latest-versions', "Use latest version of forge modules and default branch of repository modules in .fixtures.yml") do |name|
40
+ options[:latest_versions] = true
41
+ end
42
+
39
43
  opts.on('-s', '--silent', 'Run in silent mode. Supresses all non-debug output. Adds the -c flag automatically.') do
40
44
  options[:silent] = true
41
45
  options[:create_puppetfile] = true
@@ -1,3 +1,3 @@
1
1
  module GeneratePuppetfile
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: generate-puppetfile
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Nelson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-01-02 00:00:00.000000000 Z
12
+ date: 2019-11-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colorize
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  version: '0'
158
158
  requirements: []
159
159
  rubyforge_project:
160
- rubygems_version: 2.6.10
160
+ rubygems_version: 2.6.14
161
161
  signing_key:
162
162
  specification_version: 4
163
163
  summary: Generate a Puppetfile