chef-flavor-pan 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.rubocop.yml +563 -0
  4. data/CHANGELOG.md +23 -0
  5. data/LICENSE +15 -0
  6. data/README.md +133 -0
  7. data/base/code_generator/files/default/Berksfile +3 -0
  8. data/base/code_generator/files/default/Gemfile +5 -0
  9. data/base/code_generator/files/default/LICENSE +3 -0
  10. data/base/code_generator/files/default/Thorfile +12 -0
  11. data/base/code_generator/files/default/_chef_client.rb +14 -0
  12. data/base/code_generator/files/default/_defaults_linux.rb +16 -0
  13. data/base/code_generator/files/default/_defaults_windows.rb +41 -0
  14. data/base/code_generator/files/default/chefignore +95 -0
  15. data/base/code_generator/files/default/gitignore +16 -0
  16. data/base/code_generator/recipes/cookbook.rb +86 -0
  17. data/base/code_generator/templates/default/.kitchen.yml.erb +19 -0
  18. data/base/code_generator/templates/default/CHANGELOG.md.erb +13 -0
  19. data/base/code_generator/templates/default/LICENSE.all_rights.erb +3 -0
  20. data/base/code_generator/templates/default/LICENSE.apache2.erb +201 -0
  21. data/base/code_generator/templates/default/README.md.erb +29 -0
  22. data/base/code_generator/templates/default/default_attributes.rb.erb +1 -0
  23. data/base/code_generator/templates/default/default_recipe.rb.erb +3 -0
  24. data/base/code_generator/templates/default/metadata.rb.erb +10 -0
  25. data/lib/chef_gen/flavor/base.rb +22 -0
  26. data/lib/chef_gen/flavor/new.rb +22 -0
  27. data/lib/chef_gen/flavor/review.rb +22 -0
  28. data/new/code_generator/files/default/Berksfile +3 -0
  29. data/new/code_generator/files/default/Gemfile +5 -0
  30. data/new/code_generator/files/default/LICENSE +3 -0
  31. data/new/code_generator/files/default/Thorfile +12 -0
  32. data/new/code_generator/files/default/chefignore +95 -0
  33. data/new/code_generator/files/default/gitignore +16 -0
  34. data/new/code_generator/recipes/cookbook.rb +74 -0
  35. data/new/code_generator/templates/default/.kitchen.yml.erb +19 -0
  36. data/new/code_generator/templates/default/CHANGELOG.md.erb +13 -0
  37. data/new/code_generator/templates/default/LICENSE.all_rights.erb +3 -0
  38. data/new/code_generator/templates/default/LICENSE.apache2.erb +201 -0
  39. data/new/code_generator/templates/default/README.md.erb +29 -0
  40. data/new/code_generator/templates/default/default_attributes.rb.erb +1 -0
  41. data/new/code_generator/templates/default/default_recipe.rb.erb +0 -0
  42. data/new/code_generator/templates/default/metadata.rb.erb +6 -0
  43. data/pan.gemspec +19 -0
  44. data/review/code_generator/files/default/Berksfile +3 -0
  45. data/review/code_generator/files/default/Gemfile +5 -0
  46. data/review/code_generator/files/default/LICENSE +3 -0
  47. data/review/code_generator/files/default/Thorfile +12 -0
  48. data/review/code_generator/files/default/chefignore +95 -0
  49. data/review/code_generator/files/default/gitignore +16 -0
  50. data/review/code_generator/recipes/cookbook.rb +29 -0
  51. metadata +100 -0
@@ -0,0 +1,23 @@
1
+ # Pan Example Cookbook Generator
2
+
3
+ ## Release 2.0.0 2015/06/03
4
+
5
+ * Massive overhaul. Now uses [chef-gen-flavors](https://rubygems.org/gems/chef-gen-flavors) and provides several different flavors of cookbook generators for you to consume.
6
+
7
+ ## Release 1.1.1 2015/04/30
8
+
9
+ * Fix readme.
10
+
11
+ ## Release 1.1.0 2015/04/28
12
+
13
+ * Support for ChefDK 0.5.0.
14
+ * Updates to example kitchen.yml to mirror idiomatic Windows configuration.
15
+ * Added default rubocop.yml.
16
+
17
+ ## Release 1.0.1
18
+
19
+ * Small updates to support ChefDK 0.3.6. Will no longer work on ChefDK 0.3.5 and below.
20
+
21
+ ## Release 1.0.0
22
+
23
+ * Provide cookbook example generator
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ # THE APACHE LICENSE, v2
2
+
3
+ Copyright 2015 David Echols
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not
6
+ use this file except in compliance with the License. You may obtain a copy
7
+ of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ License for the specific language governing permissions and limitations
15
+ under the License.
@@ -0,0 +1,133 @@
1
+ # pan cookbook generator
2
+
3
+ Pan is a Chef cookbook generator using [chef-gen-flavors](https://rubygems.org/gems/chef-gen-flavors). You can use it out of the box as an opinionated way of creating new cookbooks, or modify it to meet your organization needs.
4
+
5
+ ## Install
6
+
7
+ - To get started, you'll need to install chef-gen-flavors, a gem that allows you to have multiple types of generators.
8
+
9
+ `chef gem install chef-gen-flavors`
10
+
11
+ - Then you can install the pan flavor:
12
+
13
+ `chef gem install chef-flavor-pan`
14
+
15
+ - Now add this to your knife.rb:
16
+
17
+ ```
18
+ # only load ChefGen::Flavors if we're being called from the ChefDK CLI
19
+ if defined?(ChefDK::CLI)
20
+ require 'chef_gen/flavors'
21
+ chefdk.generator_cookbook = ChefGen::Flavors.path
22
+ end
23
+ ```
24
+
25
+ - You're done! Let's get cooking.
26
+
27
+ ## Usage
28
+
29
+ `chef generate cookbook my_cookbook_name`
30
+
31
+ ```
32
+ echohack:desktop echohack$ chef generate cookbook my_cookbook_name
33
+ Compiling Cookbooks...
34
+ Recipe: new::cookbook
35
+ * directory[/Users/echohack/Desktop/my_cookbook_name/attributes] action create
36
+ - create new directory /Users/echohack/Desktop/my_cookbook_name/attributes
37
+ * directory[/Users/echohack/Desktop/my_cookbook_name/recipes] action create
38
+ - create new directory /Users/echohack/Desktop/my_cookbook_name/recipes
39
+ * directory[/Users/echohack/Desktop/my_cookbook_name/templates/default] action create
40
+ - create new directory /Users/echohack/Desktop/my_cookbook_name/templates/default
41
+ * directory[/Users/echohack/Desktop/my_cookbook_name/files/default] action create
42
+ - create new directory /Users/echohack/Desktop/my_cookbook_name/files/default
43
+ * directory[/Users/echohack/Desktop/my_cookbook_name/test/integration/default] action create
44
+ - create new directory /Users/echohack/Desktop/my_cookbook_name/test/integration/default
45
+ * cookbook_file[/Users/echohack/Desktop/my_cookbook_name/.rubocop.yml] action create_if_missing
46
+ - create new file /Users/echohack/Desktop/my_cookbook_name/.rubocop.yml
47
+ - update content in file /Users/echohack/Desktop/my_cookbook_name/.rubocop.yml from none to fb555e
48
+ (diff output suppressed by config)
49
+ * cookbook_file[/Users/echohack/Desktop/my_cookbook_name/Berksfile] action create_if_missing
50
+ - create new file /Users/echohack/Desktop/my_cookbook_name/Berksfile
51
+ - update content in file /Users/echohack/Desktop/my_cookbook_name/Berksfile from none to 5ec92e
52
+ (diff output suppressed by config)
53
+ * cookbook_file[/Users/echohack/Desktop/my_cookbook_name/chefignore] action create_if_missing
54
+ - create new file /Users/echohack/Desktop/my_cookbook_name/chefignore
55
+ - update content in file /Users/echohack/Desktop/my_cookbook_name/chefignore from none to 9727b1
56
+ (diff output suppressed by config)
57
+ * cookbook_file[/Users/echohack/Desktop/my_cookbook_name/Gemfile] action create_if_missing
58
+ - create new file /Users/echohack/Desktop/my_cookbook_name/Gemfile
59
+ - update content in file /Users/echohack/Desktop/my_cookbook_name/Gemfile from none to a3b439
60
+ (diff output suppressed by config)
61
+ * cookbook_file[/Users/echohack/Desktop/my_cookbook_name/LICENSE] action create_if_missing
62
+ - create new file /Users/echohack/Desktop/my_cookbook_name/LICENSE
63
+ - update content in file /Users/echohack/Desktop/my_cookbook_name/LICENSE from none to 693e85
64
+ (diff output suppressed by config)
65
+ * cookbook_file[/Users/echohack/Desktop/my_cookbook_name/Thorfile] action create_if_missing
66
+ - create new file /Users/echohack/Desktop/my_cookbook_name/Thorfile
67
+ - update content in file /Users/echohack/Desktop/my_cookbook_name/Thorfile from none to bab8d2
68
+ (diff output suppressed by config)
69
+ * template[/Users/echohack/Desktop/my_cookbook_name/metadata.rb] action create_if_missing
70
+ - create new file /Users/echohack/Desktop/my_cookbook_name/metadata.rb
71
+ - update content in file /Users/echohack/Desktop/my_cookbook_name/metadata.rb from none to 95b0c0
72
+ (diff output suppressed by config)
73
+ * template[/Users/echohack/Desktop/my_cookbook_name/README.md] action create_if_missing
74
+ - create new file /Users/echohack/Desktop/my_cookbook_name/README.md
75
+ - update content in file /Users/echohack/Desktop/my_cookbook_name/README.md from none to 5b81bf
76
+ (diff output suppressed by config)
77
+ * template[/Users/echohack/Desktop/my_cookbook_name/CHANGELOG.md] action create_if_missing
78
+ - create new file /Users/echohack/Desktop/my_cookbook_name/CHANGELOG.md
79
+ - update content in file /Users/echohack/Desktop/my_cookbook_name/CHANGELOG.md from none to 0404f5
80
+ (diff output suppressed by config)
81
+ * template[/Users/echohack/Desktop/my_cookbook_name/.kitchen.yml] action create_if_missing
82
+ - create new file /Users/echohack/Desktop/my_cookbook_name/.kitchen.yml
83
+ - update content in file /Users/echohack/Desktop/my_cookbook_name/.kitchen.yml from none to 1338ed
84
+ (diff output suppressed by config)
85
+ * template[/Users/echohack/Desktop/my_cookbook_name/attributes/default.rb] action create_if_missing
86
+ - create new file /Users/echohack/Desktop/my_cookbook_name/attributes/default.rb
87
+ - update content in file /Users/echohack/Desktop/my_cookbook_name/attributes/default.rb from none to cdc111
88
+ (diff output suppressed by config)
89
+ * template[/Users/echohack/Desktop/my_cookbook_name/recipes/default.rb] action create_if_missing
90
+ - create new file /Users/echohack/Desktop/my_cookbook_name/recipes/default.rb
91
+ - update content in file /Users/echohack/Desktop/my_cookbook_name/recipes/default.rb from none to e3b0c4
92
+ (diff output suppressed by config)
93
+ ```
94
+
95
+ ## Examples
96
+
97
+ * Create a cookbook named my_cookbook_name in the same subdirectory where pan resides.
98
+
99
+ (Mac & Windows): `chef generate cookbook my_cookbook_name`
100
+
101
+ * Create a cookbook named my_cookbook_name in the root of your primary drive with pan residing in your home directory
102
+
103
+ (Mac): `chef generate cookbook /mycookbook`
104
+
105
+ (Windows): `chef generate cookbook C:\mycookbook`
106
+
107
+ ## Supported Platforms
108
+
109
+ ### Tested And Validated On
110
+ * Mac OSX 10.10 with ChefDK 0.6.0
111
+ * Windows 7 with ChefDK 0.6.0
112
+
113
+ ChefDK 0.3.6 and higher all likely work, but previous versions were not tested and validated.
114
+
115
+ ## Stuff This Custom Generator Does
116
+
117
+ Take a look at the flavors and generate a few cookbooks to see what they do. But I'll mention some best practices here:
118
+
119
+ ### In default_attributes.rb
120
+
121
+ 1. default['<%= @attribute_context %>']['file_cache_path']
122
+
123
+ * I like to do this so that I can create a "workspace" for the cookbook to drop any files in so I avoid cookbook download collisions. If your cookbook doesn't download anything, than you can trash this.
124
+ * It also provides a good example of how to do an attribute.
125
+
126
+ ### In .kitchen.yml
127
+
128
+ 1. chef_zero provisioner
129
+
130
+ * It's probably stronger to provision with chef_zero than chef_solo since it behaves more like the server does. (That is to say, if you use chef server, then test with chef zero. If you're using solo, then test with solo.)
131
+
132
+ 2. Windows 2012 R2 with automagical WinRM transport
133
+ * Ideally this is how you would set up the transport for WinRM with Kitchen. This is a new feature as of Test Kitchen 1.4.0 / ChefDK 0.5.0.
@@ -0,0 +1,3 @@
1
+ source 'https://supermarket.chef.io'
2
+
3
+ metadata
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'berkshelf'
4
+ gem 'test-kitchen'
5
+ gem 'kitchen-vagrant'
@@ -0,0 +1,3 @@
1
+ Copyright (C) 2014 Your Organization, Inc.
2
+
3
+ All rights reserved - Do Not Redistribute
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ require 'bundler'
4
+ require 'bundler/setup'
5
+ require 'berkshelf/thor'
6
+
7
+ begin
8
+ require 'kitchen/thor_tasks'
9
+ Kitchen::ThorTasks.new
10
+ rescue LoadError
11
+ puts '>>>>> Kitchen gem not loaded, omitting tasks' unless ENV['CI']
12
+ end
@@ -0,0 +1,14 @@
1
+ # Your organization's chef-client settings
2
+ interval = 600
3
+ splay = 300
4
+ node.set['chef_client']['interval'] = interval
5
+ node.set['chef_client']['splay'] = splay
6
+
7
+ # Requires Chef 12 client or a new version of Chef 11 client
8
+ # Always explicitly set security settings: validate SSL
9
+ node.set['chef_client']['config']['verify_api_cert'] = true
10
+ node.set['chef_client']['config']['ssl_verify_mode'] = ':verify_peer'
11
+
12
+ include_recipe 'chef-client::config'
13
+ include_recipe 'chef-client::service'
14
+ include_recipe 'chef-client::delete_validation'
@@ -0,0 +1,16 @@
1
+ if platform_family?('debian', 'rhel')
2
+ node.set['omnibus_updater']['version'] = '12.3.0'
3
+ node.set['omnibus_updater']['restart_chef_service'] = true
4
+ include_recipe 'omnibus_updater'
5
+
6
+ # Install CA certificate
7
+ directory '/etc/chef/trusted_certs' do
8
+ recursive true
9
+ action :create
10
+ end
11
+
12
+ # If you are running your own CA
13
+ # bundle your public certificate with the cookbook
14
+ # and use a cookbook_file resource to drop it on the machine
15
+ # in /etc/chef/trusted_certs
16
+ end
@@ -0,0 +1,41 @@
1
+ if platform_family? 'windows'
2
+ # Install CA certificate
3
+ directory 'C:/chef/trusted_certs' do
4
+ recursive true
5
+ action :create
6
+ end
7
+ # If you are running your own CA
8
+ # bundle your public certificate with the cookbook
9
+ # and use a cookbook_file resource to drop it on the machine
10
+ # in C:/chef/trusted_certs
11
+
12
+ # install chocolatey so we have package management
13
+ include_recipe 'chocolatey'
14
+
15
+ # If you like optimizations like the one below, check out Boxstarter
16
+ # http://www.boxstarter.org/
17
+ # always display all items in the tray
18
+ registry_key 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer' do
19
+ values [{ name: 'EnableAutoTray', type: :dword, data: 00000000 }]
20
+ recursive true
21
+ action :create
22
+ end
23
+
24
+ # Eliminate DSC collisions with Chef by disabling LCM.
25
+ powershell_script 'apply_lcm' do
26
+ code <<-EOH
27
+ configuration LCM
28
+ {
29
+ LocalConfigurationManager
30
+ {
31
+ ConfigurationMode = "ApplyOnly"
32
+ }
33
+ }
34
+ LCM -OutputPath #{Chef::Config[:file_cache_path]}
35
+ Set-DscLocalConfigurationManager -Path #{Chef::Config[:file_cache_path]}
36
+ EOH
37
+ not_if '(Get-DscLocalConfigurationManager).ConfigurationMode -eq "ApplyOnly"'
38
+ end
39
+
40
+ # If you are using DSC you will need to remote_file and install any DSC extensions you are using.
41
+ end
@@ -0,0 +1,95 @@
1
+ # Put files/directories that should be ignored in this file when uploading
2
+ # or sharing to the community site.
3
+ # Lines that start with '# ' are comments.
4
+
5
+ # OS generated files #
6
+ ######################
7
+ .DS_Store
8
+ Icon?
9
+ nohup.out
10
+ ehthumbs.db
11
+ Thumbs.db
12
+
13
+ # SASS #
14
+ ########
15
+ .sass-cache
16
+
17
+ # EDITORS #
18
+ ###########
19
+ \#*
20
+ .#*
21
+ *~
22
+ *.sw[a-z]
23
+ *.bak
24
+ REVISION
25
+ TAGS*
26
+ tmtags
27
+ *_flymake.*
28
+ *_flymake
29
+ *.tmproj
30
+ .project
31
+ .settings
32
+ mkmf.log
33
+
34
+ ## COMPILED ##
35
+ ##############
36
+ a.out
37
+ *.o
38
+ *.pyc
39
+ *.so
40
+ *.com
41
+ *.class
42
+ *.dll
43
+ *.exe
44
+ */rdoc/
45
+
46
+ # Testing #
47
+ ###########
48
+ .watchr
49
+ .rspec
50
+ spec/*
51
+ spec/fixtures/*
52
+ test/*
53
+ features/*
54
+ Guardfile
55
+ Procfile
56
+
57
+ # SCM #
58
+ #######
59
+ .git
60
+ */.git
61
+ .gitignore
62
+ .gitmodules
63
+ .gitconfig
64
+ .gitattributes
65
+ .svn
66
+ */.bzr/*
67
+ */.hg/*
68
+ */.svn/*
69
+
70
+ # Berkshelf #
71
+ #############
72
+ Berksfile
73
+ Berksfile.lock
74
+ cookbooks/*
75
+ tmp
76
+
77
+ # Cookbooks #
78
+ #############
79
+ CONTRIBUTING
80
+
81
+ # Strainer #
82
+ ############
83
+ Colanderfile
84
+ Strainerfile
85
+ .colander
86
+ .strainer
87
+
88
+ # Vagrant #
89
+ ###########
90
+ .vagrant
91
+ Vagrantfile
92
+
93
+ # Travis #
94
+ ##########
95
+ .travis.yml
@@ -0,0 +1,16 @@
1
+ .vagrant
2
+ Berksfile.lock
3
+ *~
4
+ *#
5
+ .#*
6
+ \#*#
7
+ .*.sw[a-z]
8
+ *.un~
9
+
10
+ # Bundler
11
+ Gemfile.lock
12
+ bin/*
13
+ .bundle/*
14
+
15
+ .kitchen/
16
+ .kitchen.local.yml
@@ -0,0 +1,86 @@
1
+ context = ChefDK::Generator.context
2
+ cookbook_dir = File.join(context.cookbook_root, context.cookbook_name)
3
+ attribute_context = context.cookbook_name.gsub(/-/, '_')
4
+
5
+ # Create cookbook directories
6
+ cookbook_directories = [
7
+ 'attributes',
8
+ 'recipes',
9
+ 'templates/default',
10
+ 'files/default',
11
+ 'test/integration/default'
12
+ ]
13
+ cookbook_directories.each do |dir|
14
+ directory File.join(cookbook_dir, dir) do
15
+ recursive true
16
+ end
17
+ end
18
+
19
+ # Create basic files
20
+ files_basic = %w(
21
+ Berksfile
22
+ chefignore
23
+ Gemfile
24
+ LICENSE
25
+ Thorfile
26
+ )
27
+ files_basic.each do |file|
28
+ cookbook_file File.join(cookbook_dir, file) do
29
+ action :create_if_missing
30
+ end
31
+ end
32
+
33
+ # Create basic files from template
34
+ files_template = %w(
35
+ metadata.rb
36
+ README.md
37
+ CHANGELOG.md
38
+ .kitchen.yml
39
+ )
40
+ files_template.each do |file|
41
+ template File.join(cookbook_dir, file) do
42
+ helpers(ChefDK::Generator::TemplateHelper)
43
+ action :create_if_missing
44
+ end
45
+ end
46
+
47
+ # Create recipes
48
+ files_recipes = %w(
49
+ _chef_client.rb
50
+ _defaults_linux.rb
51
+ _defaults_windows.rb
52
+ )
53
+ files_recipes.each do |file|
54
+ cookbook_file File.join(cookbook_dir, 'recipes', file) do
55
+ action :create_if_missing
56
+ end
57
+ end
58
+
59
+ # Create more complex files from templates
60
+ template "#{cookbook_dir}/attributes/default.rb" do
61
+ source 'default_attributes.rb.erb'
62
+ helpers(ChefDK::Generator::TemplateHelper)
63
+ action :create_if_missing
64
+ variables(
65
+ attribute_context: attribute_context)
66
+ end
67
+ template "#{cookbook_dir}/recipes/default.rb" do
68
+ source 'default_recipe.rb.erb'
69
+ helpers(ChefDK::Generator::TemplateHelper)
70
+ action :create_if_missing
71
+ end
72
+
73
+ # git
74
+ if context.have_git
75
+ unless context.skip_git_init
76
+
77
+ execute('initialize-git') do
78
+ command('git init .')
79
+ cwd cookbook_dir
80
+ end
81
+ end
82
+
83
+ cookbook_file "#{cookbook_dir}/.gitignore" do
84
+ source 'gitignore'
85
+ end
86
+ end