generate-puppetfile 0.9.0 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZmU2ODhjY2FlMTczMTAxMzIzY2ZmOWVlZmRkYzBjMTBjNGFiN2JmMA==
4
+ OWExOWZiYjAzNDk1NGFkYTAwMzBkMDAxMWU1NTdkMzQzNDdkNTc2Ng==
5
5
  data.tar.gz: !binary |-
6
- ZjhmMzUwOTM4Yzc1YTFmZjUxMjA2Njg2NGVkZWIwZDRiMjFjNGNlNA==
6
+ N2JlNDViOTUyODBmNDE5OGU2YjU3OTQ3YWJlMjg3Y2ExNDRkMGEyOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDE0Njg0ZmNhY2Q1MzU4MTI1MjUzZTgwM2NiYmQ1MDJiMjQ3YzUwZmJkNWIy
10
- NGMxODA0M2Y3ZDJiNjllNDYxY2VkMzE2ZjQxZDFjZDVlYThjMDc0NmRlZTFi
11
- YTY4ZWM3Y2IyNjkwYmVlZGIyYjM2NmU4YjcwMWJkZjU1NGIwMmQ=
9
+ MjBmNzMwYTBlODI5MTc0ZjQ5NzQwMGVkOGRhYzFmZjYyMTZkYTMyYmMxOTE2
10
+ YTZhMjY4NTNiM2RiZGMyMjlmNzk5MWNkMzczYWMyYTIwODA0MTQyZjIyM2Zh
11
+ MDczY2UzODQ1NmZhNTM0YjIzOTYxYTZiYmU2MThkMGFkZDRhMjY=
12
12
  data.tar.gz: !binary |-
13
- YzM5MTUyZDNiOWQ4MDE3YzcyMjNhNWE0MTA3MmVkYmI4YmQ2NzExYjM2NzIx
14
- NzdlMTU3M2MwOThlZmNiYzFkZmM0ZDAyY2IwNDE2ZDZkOWQzZDliNzM5NDE3
15
- N2ZjOGE3MmE5NGJiYWFjZjBiZjk1NDgwNjdmZmRlOTUwZTUxMzk=
13
+ NDA3MTI0MTg4ZmQxYjUyMjI4ZDM2NTQyYWZmYmE1YzAwYjNmNzc0MDc3NjA4
14
+ ODU5YjZlMzBmZTRhZDQ5YTRmMmRlOTY4NzYwYWNkYjQwNGIzZTBjNmM0OWIz
15
+ MDMzYTgwNzdjZjI0OWE0MWU3MTBkNWZlYjI4YzEyZmI0NTQ2ZWM=
data/README.md CHANGED
@@ -1,22 +1,117 @@
1
- Tired of searching for dependencies on the forge and hoping you got everything? Use generate-puppetfile to generate a list of modules and their dependencies in a Puppetfile format for use with r10k or librarian-puppet.
1
+ [![Gem Version](https://badge.fury.io/rb/generate-puppetfile.svg)](https://badge.fury.io/rb/generate-puppetfile)
2
2
 
3
- To use this, simply clone the repository and run the generate-puppetfile script with a list of valid module names:
3
+ Tired of searching for dependencies on the forge and hoping you got everything? Have an existing Puppetfile that's getting long in the tooth? Use generate-puppetfile to generate a list of modules and their dependencies, at the latest version, in Puppetfile format for use with r10k or librarian-puppet.
4
4
 
5
+ ## Installation
6
+
7
+ gem install generate-puppetfile
8
+
9
+ ## Usage
10
+
11
+ Run `generate-puppetfile` with a list of modules and/or an existing Puppetfile. Each module name will be validated to be of the proper format (author/name). Any existing Puppetfile will be scanned for forge modules. Non-forge module entries will be preserved. All forge modules will be tracked at the latest version, along with their dependencies. The resulting Puppetfile will contain all the forge modules along with any preserved non-forge module statements.
12
+
13
+ ### Forge Modules Only
5
14
  ```
6
- $ ./generate-puppetfile echocat/nfs rnelson0/certs
7
- Download echocat/nfs and its dependencies...
8
- Download rnelson0/certs and its dependencies...
9
- Module download complete. Generating Puppetfile.
15
+ $ generate-puppetfile echocat/nfs rnelson0/certs
10
16
 
11
- Here is your suggested Puppetfile:
12
- ----------------------------------
17
+ Installing modules. This may take a few minutes.
13
18
 
19
+
20
+ Your Puppetfile has been generated. Copy and paste between the markers:
21
+
22
+ =======================================================================
14
23
  forge 'http://forge.puppetlabs.com'
15
24
 
25
+ # Modules discovered by generate-puppetfile
26
+
16
27
  mod 'echocat/nfs', '1.7.1'
17
28
  mod 'herculesteam/augeasproviders_core', '2.1.2'
18
29
  mod 'herculesteam/augeasproviders_shellvar', '2.2.0'
19
30
  mod 'puppetlabs/concat', '1.2.4'
20
31
  mod 'puppetlabs/stdlib', '4.9.0'
21
32
  mod 'rnelson0/certs', '0.6.2'
33
+
34
+ # Discovered elements from existing Puppetfile
35
+
36
+ =======================================================================
37
+
38
+ ```
39
+
40
+ ### Using an existing Puppetfile
41
+ ```
42
+ $ generate-puppetfile -p git/puppetinabox/controlrepo/Puppetfile
43
+
44
+ Installing modules. This may take a few minutes.
45
+
46
+
47
+ Your Puppetfile has been generated. Copy and paste between the markers:
48
+
49
+ =======================================================================
50
+ forge 'http://forge.puppetlabs.com'
51
+
52
+ # Modules discovered by generate-puppetfile
53
+
54
+ mod 'ajjahn/dhcp', '0.2.0'
55
+ mod 'croddy/make', '0.0.5'
56
+ mod 'garethr/erlang', '0.3.0'
57
+ mod 'gentoo/portage', '2.3.0'
58
+ mod 'golja/gnupg', '1.2.1'
59
+ mod 'maestrodev/rvm', '1.12.1'
60
+ mod 'nanliu/staging', '1.0.3'
61
+ mod 'palli/createrepo', '1.1.0'
62
+ mod 'puppetlabs/activemq', '0.4.0'
63
+ mod 'puppetlabs/apache', '1.6.0'
64
+ mod 'puppetlabs/apt', '2.2.0'
65
+ mod 'puppetlabs/concat', '1.2.4'
66
+ mod 'puppetlabs/firewall', '1.7.1'
67
+ mod 'puppetlabs/gcc', '0.3.0'
68
+ mod 'puppetlabs/git', '0.4.0'
69
+ mod 'puppetlabs/inifile', '1.4.2'
70
+ mod 'puppetlabs/java', '1.4.2'
71
+ mod 'puppetlabs/java_ks', '1.3.1'
72
+ mod 'puppetlabs/lvm', '0.5.0'
73
+ mod 'puppetlabs/mcollective', '99.99.99'
74
+ mod 'puppetlabs/mysql', '3.6.1'
75
+ mod 'puppetlabs/ntp', '4.1.0'
76
+ mod 'puppetlabs/pe_gem', '0.1.1'
77
+ mod 'puppetlabs/postgresql', '4.6.0'
78
+ mod 'puppetlabs/puppetdb', '5.0.0'
79
+ mod 'puppetlabs/rabbitmq', '5.3.1'
80
+ mod 'puppetlabs/ruby', '0.4.0'
81
+ mod 'puppetlabs/stdlib', '4.9.0'
82
+ mod 'puppetlabs/tftp', '0.2.3'
83
+ mod 'puppetlabs/vcsrepo', '1.3.1'
84
+ mod 'puppetlabs/xinetd', '1.5.0'
85
+ mod 'richardc/datacat', '0.5.0'
86
+ mod 'rnelson0/certs', '0.6.2'
87
+ mod 'rnelson0/local_user', '1.0.1'
88
+ mod 'saz/ssh', '2.8.1'
89
+ mod 'saz/sudo', '3.1.0'
90
+ mod 'stahnma/epel', '1.1.1'
91
+ mod 'stephenrjohnson/puppet', '1.3.1'
92
+ mod 'thias/bind', '0.5.1'
93
+ mod 'yguenane/augeas', '0.1.1'
94
+ mod 'yguenane/ygrpms', '0.1.0'
95
+ mod 'zack/r10k', '3.1.1'
96
+
97
+ # Discovered elements from existing Puppetfile
98
+ # Modules from the Puppet Forge
99
+ # Modules from Github
100
+ mod 'lab_config',
101
+ :git => 'git@github.com:puppetinabox/lab_config.git'
102
+
103
+ =======================================================================
22
104
  ```
105
+
106
+ ## Limitations
107
+
108
+ * Parsing of an existing Puppetfile is naive. Anything that doesn't look like a forge module is preserved and then added to the end of the new Puppetfile. Verify that no ordering errors are introduced before using the new file.
109
+
110
+ ## Thanks
111
+ Many thanks to the following people for contributing to generate-puppetfile
112
+ * [Tomy Lobo](https://github.com/TomyLobo)
113
+ * [Ben Ford](https://github.com/binford2k)
114
+
115
+ ## Contributing
116
+
117
+ All issues and PRs are welcome!
@@ -4,14 +4,25 @@ require 'generate_puppetfile/optparser'
4
4
  require 'fileutils'
5
5
 
6
6
  module GeneratePuppetfile
7
+ # Internal: The Bin class contains the logic for calling generate_puppetfile at the command line
7
8
  class Bin
8
9
  Module_regex = Regexp.new("mod ['\"]([a-z0-9_]+\/[a-z0-9_]+)['\"](, ['\"](\\d\.\\d\.\\d)['\"])?", Regexp::IGNORECASE)
9
10
  @options = {}
10
11
 
12
+ # Public: Initialize a new GeneratePuppetfile::Bin
13
+ #
14
+ # args - Array of command line arguments as Strings to be passed to GeneratePuppetfile::OptParser.parse
15
+ #
16
+ # Example:
17
+ #
18
+ # GeneratePuppetfile::Bin.new(ARGV).run
11
19
  def initialize(args)
12
20
  @args = args
13
21
  end
14
22
 
23
+ # Public: Run generate-puppetfile at the command line.
24
+ #
25
+ # Returns an Integer exit code for the shell ($?)
15
26
  def run
16
27
  @options = GeneratePuppetfile::OptParser.parse(@args)
17
28
 
@@ -26,92 +37,99 @@ module GeneratePuppetfile
26
37
  forge_module_list = Array.new
27
38
 
28
39
  if @args
29
- puts "\nProcessing modules from the command line...\n\n" if @options[:debug]
40
+ puts "\nProcessing modules from the command line...\n\n" if @options[:debug]
30
41
  cli_modules = Array.new
31
42
  @args.each do |modulename|
32
- validate(modulename) && (cli_modules.push(modulename))
43
+ validate(modulename) && (cli_modules.push(modulename))
33
44
  end
34
45
  end
35
46
 
36
47
  puppetfile_contents = Hash.new
37
48
  extras = Array.new
38
49
  if @options[:puppetfile]
39
- puts "\nProcessing the puppetfile '#{@options[:puppetfile]}'...\n\n" if @options[:debug]
40
- puppetfile_contents = read_puppetfile(@options[:puppetfile])
41
- extras = puppetfile_contents[:extras]
50
+ puts "\nProcessing the puppetfile '#{@options[:puppetfile]}'...\n\n" if @options[:debug]
51
+ puppetfile_contents = read_puppetfile(@options[:puppetfile])
52
+ extras = puppetfile_contents[:extras]
42
53
  end
43
54
 
44
55
  forge_module_list.push(*cli_modules) if @args
45
56
  forge_module_list.push(*puppetfile_contents[:modules]) if puppetfile_contents[:modules]
46
57
 
47
- list_modules(forge_module_list) if puppetfile_contents && @options[:debug]
58
+ list_forge_modules(forge_module_list) if puppetfile_contents && @options[:debug]
48
59
  list_extras(puppetfile_contents[:extras]) if puppetfile_contents[:extras] && @options[:debug]
49
60
 
50
61
  generate_puppetfile_contents(forge_module_list, puppetfile_contents[:extras])
62
+
63
+ return 0
51
64
  end
52
65
 
66
+ # Public: Validates that a provided module name is valid.
53
67
  def validate (modulename)
54
68
  success = (modulename =~ /[a-z0-9_]\/[a-z0-9_]/i)
55
69
  puts " '#{modulename}' is not a valid module name. Skipping." unless success
56
70
  success
57
71
  end
58
72
 
59
- def list_modules (module_list)
73
+ # Public: Display the list of Forge modules collected.
74
+ def list_forge_modules (module_list)
60
75
  puts "\nListing discovered modules from CLI and/or Puppetfile:\n\n"
61
76
  module_list.each do |name|
62
- puts " #{name}"
77
+ puts " #{name}"
63
78
  end
64
79
  puts ""
65
80
  end
66
81
 
82
+ # Public: Display the list of extra statements found in the Puppetfile.
67
83
  def list_extras (extras)
68
84
  puts "\nExtras found in the existing Puppetfile:\n\n"
69
85
  extras.each do |line|
70
- puts " #{line}"
86
+ puts " #{line}"
71
87
  end
72
88
  puts ""
73
89
  end
74
90
 
91
+ # Public: Read and parse the contents of an existing Puppetfile
75
92
  def read_puppetfile (puppetfile)
76
93
  puppetfile_contents = {
77
- :modules => Array.new,
78
- :extras => Array.new,
94
+ :modules => Array.new,
95
+ :extras => Array.new,
79
96
  }
80
97
 
81
98
  File.foreach(puppetfile) do |line|
82
- if Module_regex.match(line)
83
- name = $1
84
- print " #{name} looks like a forge module.\n" if @options[:debug]
85
- puppetfile_contents[:modules].push(name)
86
- else
87
- next if line =~ /^forge/
88
- next if line =~ /^\s+$/
89
- next if line =~ /# Discovered elements from existing Puppetfile/
90
-
91
- puppetfile_contents[:extras].push(line)
92
- end
99
+ if Module_regex.match(line)
100
+ name = $1
101
+ print " #{name} looks like a forge module.\n" if @options[:debug]
102
+ puppetfile_contents[:modules].push(name)
103
+ else
104
+ next if line =~ /^forge/
105
+ next if line =~ /^\s+$/
106
+ next if line =~ /# Discovered elements from existing Puppetfile/
107
+
108
+ puppetfile_contents[:extras].push(line)
109
+ end
93
110
  end
94
111
 
95
112
  puppetfile_contents
96
113
  end
97
114
 
115
+ # Public: Generate a new Puppetfile's contents based on a list of modules
116
+ # and any extras found in an existing Puppetfile.
117
+ #
118
+ # module_list is an array of forge module names to be downloaded
119
+ # extras is an array of strings
98
120
  def generate_puppetfile_contents (module_list, extras = [])
99
- # cli_modules is a hash of module name => version
100
- # puppetfile_contents is a hash with two keys:
101
- # module_list is an array of forge module names to be downloaded
102
- # extras is an array of strings
103
121
  workspace = `mktemp -d`
104
122
 
105
123
  modulepath = "--modulepath #{workspace.chomp} "
106
124
  silence = '>/dev/null 2>&1 '
107
125
  strip_colors = 'sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"'
108
126
 
109
- puts "\nInstalling modules. This may take a few minutes.\n\n"
127
+ puts "\nInstalling modules. This may take a few minutes.\n"
110
128
  module_list.each do |name|
111
- command = "puppet module install #{name} "
112
- command += modulepath + silence
113
-
114
- system(command)
129
+ command = "puppet module install #{name} "
130
+ command += modulepath + silence
131
+
132
+ system(command)
115
133
  end
116
134
 
117
135
  puppetfile_header = <<-EOF
@@ -121,6 +139,7 @@ forge 'http://forge.puppetlabs.com'
121
139
  EOF
122
140
 
123
141
  puppetfile_body = `puppet module list #{modulepath} 2>/dev/null | #{strip_colors}`
142
+ puts puppetfile_body
124
143
 
125
144
  puppetfile_body.gsub!(/^\/.*$/, '')
126
145
  puppetfile_body.gsub!(/-/, '/')
@@ -132,12 +151,11 @@ forge 'http://forge.puppetlabs.com'
132
151
 
133
152
  puppetfile_footer = "# Discovered elements from existing Puppetfile\n"
134
153
  extras.each do |line|
135
- puppetfile_footer += "#{line}"
136
- end
154
+ puppetfile_footer += "#{line}"
155
+ end if extras
137
156
 
138
157
  puts <<-EOF
139
158
 
140
-
141
159
  Your Puppetfile has been generated. Copy and paste between the markers:
142
160
 
143
161
  =======================================================================
@@ -2,7 +2,11 @@ require 'generate_puppetfile'
2
2
  require 'optparse'
3
3
 
4
4
  module GeneratePuppetfile
5
+ # Internal: Parse the options provided to generate-puppetfile
5
6
  class OptParser
7
+ # Internal: Initialize the OptionParser
8
+ #
9
+ # Returns an OptionParser object.
6
10
  def self.parse(args)
7
11
  options = {}
8
12
  opts = OptionParser.new do |opts|
@@ -1,3 +1,3 @@
1
1
  module GeneratePuppetfile
2
- VERSION = '0.9.0'
2
+ VERSION = '0.9.2'
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: 0.9.0
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Nelson
@@ -9,7 +9,49 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2015-10-26 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-its
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1'
13
55
  description: Generate a Puppetfile for use with r10k based on an existing file or
14
56
  a list of modules.
15
57
  email: rnelson0@gmail.com