kitchen-puppet 1.0.33 → 1.0.34

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: f35ff34e5f2d431f879e03f1ef78f663b5cb2035
4
- data.tar.gz: 8ec9e89202b63c503cffe34ccc2b9a9f34a0490a
3
+ metadata.gz: 4ff25034f7a7dfe7a6f9af8c8d5d91d33f9cc6b1
4
+ data.tar.gz: 676912db95788783bf3bfb4ac22eae57baa4a72c
5
5
  SHA512:
6
- metadata.gz: f19631f93680c0152e4f0a570478eaa63cc49fd450e82e5dfb93673e3351bd05a5f1e73982ef13b2db54848c0b78cf104b5a1a36df0bc40751dc4668f8b78281
7
- data.tar.gz: f69ba6210b184cfe83e9d63173e706ee475ec434dabe9509552ce20cc55af86073a9f8f66e3f9356faf90eddd5544600f0bd242a7cf463755d07b0a6470b9a0c
6
+ metadata.gz: 52630ad4ceb29ffae31ce66be9bd2140be2de49d2b10f1b384e72bde9233c998d01d7b59c6a21c6de5ae84efccd7b39d78409f08e6b890d6d4ba25f85f32a2e3
7
+ data.tar.gz: 0a7e9b3ed085fa7048eb35e231629188c5bbf97ef01736dcaf7862ed6fee219c56bd85d4ae2a0daef4e6568edfc8f3e573a83968924e4f50a9fb8b68fba9adcd
data/README.md CHANGED
@@ -17,7 +17,7 @@ The PuppetAgent provider works by passing the puppetmaster and other attributes
17
17
  This provider has been tested against the Ubuntu 1204 and Centos 6.5 boxes running in vagrant/virtualbox as well as various docker .
18
18
 
19
19
  ## Windows Workstation Install
20
- You need to download the puppet msi and install it and run everything inside the puppet window.
20
+ You need to download the puppet msi and install it and run everything inside the puppet window.
21
21
 
22
22
  1. Download and install puppet from the windows msi file from https://downloads.puppetlabs.com/windows
23
23
  * I recommend the using the 32 bit version as not all ruby gems works with the 64 bit version.
@@ -37,7 +37,7 @@ You need to download the puppet msi and install it and run everything inside the
37
37
  * gem install librarian-puppet
38
38
  * gem install test-kitchen
39
39
  * gem install kitchen-puppet
40
-
40
+
41
41
  ## Mac-OSX Workstation Install
42
42
 
43
43
  1. Download and install the mac packages from https://downloads.puppetlabs.com/mac/
@@ -52,21 +52,129 @@ You need to download the puppet msi and install it and run everything inside the
52
52
  * gem install kitchen-puppet
53
53
 
54
54
  ## Requirements
55
+ It is recommended to have a metadata.json file of your puppet module. It is used by kitchen-puppet to configure the module path.
56
+ The puppet docs describe (https://docs.puppetlabs.com/puppet/latest/reference/modules_publishing.html#write-a-metadatajson-file) how to create one.
57
+
55
58
  You'll need a driver box without a chef installation so puppet can be installed. Puppet have one at http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box or http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box.
56
59
 
57
60
  For PuppetAgent a server with a puppet master is required that can resolve the hostname ip address of the server. The server must also be able to resolve the hostname ip address of the puppet master.
58
61
 
59
62
  You can also use the PuppetApply driver with a docker container, provided the necessary box requirements to install puppet are included inside the container. The easiest way to do this is to supply Kitchen-Docker with a custom dockerfile to install the needed dependencies for puppet installation.
60
63
 
64
+ ## Test-Kitchen Serverspec
65
+
66
+ To run the verify step with the test-kitchen serverspec setup your puppet repository as follows:
67
+
68
+ In the root directory for your puppet repository:
69
+
70
+ Create a `.kitchen.yml`, much like one the described above:
71
+
72
+ ```yaml
73
+ ---
74
+ driver:
75
+ name: vagrant
76
+
77
+ provisioner:
78
+ name: puppet_apply
79
+ manifests_path: /repository/puppet_repo/manifests
80
+ modules_path: /repository/puppet_repo/modules-mycompany
81
+ hiera_data_path: /repository/puppet_repo/hieradata
82
+
83
+ platforms:
84
+ - name: nocm_ubuntu-12.04
85
+ driver_plugin: vagrant
86
+ driver_config:
87
+ box: nocm_ubuntu-12.04
88
+ box_url: http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box
89
+
90
+ suites:
91
+ - name: default
92
+ ```
93
+
94
+ Then for serverspec:
95
+
96
+ ```bash
97
+ mkdir -p test/integration/default/serverspec/localhost
98
+ echo "require 'serverspec'" >> test/integration/default/serverspec/spec_helper.rb
99
+ echo "set :backend, :exec" >> test/integration/default/serverspec/spec_helper.rb
100
+ ```
101
+
102
+ Create your serverspec tests in `test/integration/default/serverspec/localhost/xxxxxx_spec.rb`:
103
+
104
+ ```ruby
105
+ require 'spec_helper'
106
+
107
+ if os[:family] == 'ubuntu'
108
+ describe '/etc/lsb-release' do
109
+ it "exists" do
110
+ expect(file('/etc/lsb-release')).to be_file
111
+ end
112
+ end
113
+ end
114
+
115
+ if os[:family] == 'redhat'
116
+ describe '/etc/redhat-release' do
117
+ it "exists" do
118
+ expect(file('/etc/redhat-release')).to be_file
119
+ end
120
+ end
121
+ end
122
+ ```
123
+
124
+ ## Test-Kitchen Beaker
125
+
126
+ test-kitchen normally uses tests setup in `test/integration/....` directory. Beaker format puts the tests with the
127
+ `spec/acceptance` directory in the puppet repository and the `spec_helper_acceptance.rb` under the `spec` directory.
128
+
129
+ For examples see:
130
+ * https://gitlab.com/joshbeard/puppet-module-test
131
+ * https://github.com/puppetlabs/puppetlabs-mysql/tree/master/spec
132
+
133
+ To implement this with test-kitchen setup the puppet repository with:
134
+
135
+ * the spec files with the spec/acceptance directory.
136
+
137
+ * the spec_helper_acceptance in the spec folder.
138
+
139
+ * a dummy `test/integration/<suite>/beaker/localhost/<suite>_spec.rb` containing just a dummy comment.
140
+
141
+ See example [https://github.com/neillturner/puppet_repo](https://github.com/neillturner/puppet_repo)
142
+
143
+ ```
144
+ .
145
+ +-- spec
146
+ ¦   +-- acceptance
147
+ ¦   ¦   +-- mariadb_spec.rb
148
+ ¦   ¦ +-- nginx_spec.rb
149
+ ¦   ¦
150
+ ¦ +-- spec_helper_acceptance.rb
151
+ +-- test
152
+ +-- integration
153
+ +-- default # name of test-kitchen suite
154
+ +-- beaker
155
+ +-- localhost
156
+ +-- default_spec.rb # <suite>_spec.rb
157
+ ```
158
+
159
+ In the root directory for your puppet repository create a `.kitchen.yml`, the same as for test-kitchen serverspec above.
160
+
161
+ When test-kitchen runs the verify step will
162
+ * detect the dummy `/test/integration/<suite>/beaker` directory
163
+ * install the busser-beaker plugin instead of the normal busser-serverspec plugin
164
+ * serverspec will be called using the beaker conventions.
165
+
166
+ See [busser-beaker](https://github.com/neillturner/busser-beaker)
167
+
168
+
61
169
  ## Provisioner Options
62
170
  Please see the Provisioner Options (https://github.com/neillturner/kitchen-puppet/blob/master/provisioner_options.md).
63
171
 
64
172
  ## Contributing
65
- To contriubute to the repository, please follow the Fork / PR model:
173
+ To contribute to the repository, please follow the Fork / PR model:
66
174
 
67
175
  1. Fork The Repository
68
176
  2. Work on epic changes
69
- 3. Write tests for your changes
177
+ 3. Write tests for your changes, see [TESTING](TESTING.md)
70
178
  4. Update Documentation
71
179
  5. Commit
72
180
  6. Push
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kitchen
4
4
  module Puppet
5
- VERSION = '1.0.33'
5
+ VERSION = '1.0.34'
6
6
  end
7
7
  end
@@ -58,7 +58,6 @@ module Kitchen
58
58
  default_config :require_chef_for_busser, true
59
59
  default_config :resolve_with_librarian_puppet, true
60
60
  default_config :puppet_environment, nil
61
- default_config :install_custom_facts, false
62
61
  default_config :puppet_apt_repo, 'http://apt.puppetlabs.com/puppetlabs-release-precise.deb'
63
62
  default_config :puppet_yum_repo, 'https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm'
64
63
  default_config :chef_bootstrap_url, 'https://www.getchef.com/chef/install.sh'
@@ -136,6 +135,7 @@ module Kitchen
136
135
  default_config :platform, &:platform_name
137
136
  default_config :update_package_repos, true
138
137
  default_config :remove_puppet_repo, false
138
+ default_config :install_custom_facts, false
139
139
  default_config :custom_facts, {}
140
140
  default_config :facterlib, nil
141
141
  default_config :puppet_detailed_exitcodes, nil
@@ -382,7 +382,7 @@ module Kitchen
382
382
  end
383
383
 
384
384
  def init_command
385
- dirs = %w(modules manifests files hiera hiera.yaml spec)
385
+ dirs = %w(modules manifests files hiera hiera.yaml facter spec)
386
386
  .map { |dir| File.join(config[:root_path], dir) }.join(' ')
387
387
  cmd = "#{sudo('rm')} -rf #{dirs} #{hiera_data_remote_path} \
388
388
  /etc/hiera.yaml #{puppet_dir}/hiera.yaml \
@@ -401,6 +401,7 @@ module Kitchen
401
401
  prepare_modules
402
402
  prepare_manifests
403
403
  prepare_files
404
+ prepare_facter_file
404
405
  prepare_facts
405
406
  prepare_puppet_config
406
407
  prepare_hiera_config
@@ -519,16 +520,16 @@ module Kitchen
519
520
  if !config[:puppet_apply_command].nil?
520
521
  return config[:puppet_apply_command]
521
522
  else
522
- [
523
+ result = [
523
524
  facterlib,
524
525
  custom_facts,
525
- facter_facts,
526
+ puppet_manifestdir,
526
527
  puppet_cmd,
527
528
  'apply',
528
529
  File.join(config[:root_path], 'manifests', manifest),
529
530
  "--modulepath=#{File.join(config[:root_path], 'modules')}",
530
- puppet_manifestdir,
531
531
  "--fileserverconfig=#{File.join(config[:root_path], 'fileserver.conf')}",
532
+ custom_options,
532
533
  puppet_environment_flag,
533
534
  puppet_noop_flag,
534
535
  puppet_detailed_exitcodes_flag,
@@ -537,6 +538,8 @@ module Kitchen
537
538
  puppet_logdest_flag,
538
539
  remove_repo
539
540
  ].join(' ')
541
+ info("Going to invoke puppet apply with: #{result}")
542
+ result
540
543
  end
541
544
  end
542
545
 
@@ -674,7 +677,15 @@ module Kitchen
674
677
  end
675
678
 
676
679
  def puppet_manifestdir
677
- config[:puppet_environment] ? nil : "--manifestdir=#{File.join(config[:root_path], 'manifests')}"
680
+ return nil if config[:require_puppet_collections]
681
+ return nil if config[:puppet_environment]
682
+ bash_vars = "export MANIFESTDIR='#{File.join(config[:root_path], 'manifests')}';"
683
+ debug(bash_vars)
684
+ bash_vars
685
+ end
686
+
687
+ def custom_options
688
+ config[:custom_options] || ''
678
689
  end
679
690
 
680
691
  def puppet_noop_flag
@@ -702,17 +713,6 @@ module Kitchen
702
713
  config[:platform].gsub(/-.*/, '')
703
714
  end
704
715
 
705
- def facter_facts
706
- return nil unless config[:facter_file]
707
- fact_vars = 'export '
708
- fact_hash = YAML.load_file(config[:facter_file])
709
- fact_hash.each do |key, value|
710
- fact_vars << "FACTER_#{key}=#{value} "
711
- end
712
- fact_vars << ';'
713
- fact_vars
714
- end
715
-
716
716
  def update_packages_debian_cmd
717
717
  config[:update_package_repos] ? "#{sudo_env('apt-get')} update" : nil
718
718
  end
@@ -740,15 +740,22 @@ module Kitchen
740
740
  config[:spec_files_remote_path]
741
741
  end
742
742
 
743
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
743
744
  def facterlib
744
- return nil if config[:facterlib].nil?
745
- bash_vars = "export FACTERLIB='#{config[:facterlib]}';"
745
+ factpath = nil
746
+ factpath = "#{File.join(config[:root_path], 'facter')}" if config[:install_custom_facts] && !config[:custom_facts].none?
747
+ factpath = "#{File.join(config[:root_path], 'facter')}" if config[:facter_file]
748
+ factpath = "#{factpath}:" if config[:facterlib] && !factpath.nil?
749
+ factpath = "#{factpath}#{config[:facterlib]}" if config[:facterlib]
750
+ return nil if factpath.nil?
751
+ bash_vars = "export FACTERLIB='#{factpath}';"
746
752
  debug(bash_vars)
747
753
  bash_vars
748
754
  end
749
755
 
750
756
  def custom_facts
751
757
  return nil if config[:custom_facts].none?
758
+ return nil if config[:install_custom_facts]
752
759
  bash_vars = config[:custom_facts].map { |k, v| "FACTER_#{k}=#{v}" }.join(' ')
753
760
  bash_vars = "export #{bash_vars};"
754
761
  debug(bash_vars)
@@ -763,7 +770,6 @@ module Kitchen
763
770
  remove_puppet_repo ? "; #{sudo('rm')} -rf /tmp/kitchen #{hiera_data_remote_path} #{hiera_eyaml_key_remote_path} #{puppet_dir}/* " : nil
764
771
  end
765
772
 
766
- # rubocop:disable Metrics/CyclomaticComplexity
767
773
  def puppet_apt_repo
768
774
  platform_version = config[:platform].partition('-')[2]
769
775
  case puppet_platform
@@ -863,16 +869,30 @@ module Kitchen
863
869
  FileUtils.cp_r(Dir.glob("#{files}/*"), tmp_files_dir)
864
870
  end
865
871
 
872
+ def prepare_facter_file
873
+ return unless config[:facter_file]
874
+ info 'Copying facter file'
875
+ facter_dir = File.join(sandbox_path, 'facter')
876
+ FileUtils.mkdir_p(facter_dir)
877
+ FileUtils.cp_r(config[:facter_file], facter_dir)
878
+ end
879
+
866
880
  def prepare_facts
867
881
  return unless config[:install_custom_facts]
868
882
  return unless config[:custom_facts]
869
883
  info 'Installing custom facts'
870
884
  facter_dir = File.join(sandbox_path, 'facter')
871
885
  FileUtils.mkdir_p(facter_dir)
872
- tmp_facter_file = File.join(facter_dir, 'kitchen.yaml')
886
+ tmp_facter_file = File.join(facter_dir, 'kitchen.rb')
873
887
  facter_facts = Hash[config[:custom_facts].map { |k, v| [k.to_s, v.to_s] }]
874
- File.open(tmp_facter_file, 'w') do |out|
875
- YAML.dump(facter_facts, out)
888
+ File.open(tmp_facter_file, 'a') do |out|
889
+ facter_facts.each do |k, v|
890
+ out.write "\nFacter.add(:#{k}) do\n"
891
+ out.write " setcode do\n"
892
+ out.write " \"#{v}\"\n"
893
+ out.write " end\n"
894
+ out.write "end\n"
895
+ end
876
896
  end
877
897
  end
878
898
 
@@ -11,14 +11,14 @@ install_hiera | false | Installs `hiera-puppet` package. Not needed for puppet >
11
11
  hiera_package | 'hiera-puppet' | Only used if `install_hiera` is set
12
12
  require_puppet_repo | true | Set if using a puppet install from yum or apt repo
13
13
  puppet_apt_repo | "http://apt.puppetlabs.com/puppetlabs-release-precise.deb"| apt repo Ubuntu12
14
- _for Ubuntu15 change to_ | "http://apt.puppetlabs.com/puppetlabs-release-jessie.deb" |
14
+ _for Ubuntu15 change to_ | "http://apt.puppetlabs.com/puppetlabs-release-jessie.deb" |
15
15
  puppet_yum_repo | "https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm"| yum repo RH/Centos6
16
- _for RH/Centos7 change to_ | "https://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm" |
16
+ _for RH/Centos7 change to_ | "https://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm" |
17
17
  require_puppet_collections | false | Set if using puppet collections install (Puppet v4)
18
18
  puppet_yum_collections_repo | "http://yum.puppetlabs.com/puppetlabs-release-pc1-el-6.noarch.rpm" | yum collections repo RH/Centos6
19
- _for RH/Centos7 change to_ | "https://yum.puppetlabs.com/puppetlabs-release-pc1-el-7.noarch.rpm" |
19
+ _for RH/Centos7 change to_ | "https://yum.puppetlabs.com/puppetlabs-release-pc1-el-7.noarch.rpm" |
20
20
  puppet_apt_collections_repo | "http://apt.puppetlabs.com/puppetlabs-release-pc1-wheezy.deb" | apt collections repo
21
- _for Ubuntu15 change to_ | "http://apt.puppetlabs.com/puppetlabs-release-pc1-jessie.deb" |
21
+ _for Ubuntu15 change to_ | "http://apt.puppetlabs.com/puppetlabs-release-pc1-jessie.deb" |
22
22
  puppet_coll_remote_path | "/opt/puppetlabs" | Server Installation location of a puppet collections install.
23
23
  puppet_detailed_exitcodes | nil | Provide transaction information via exit codes.
24
24
  manifests_path | | puppet repo manifests directory
@@ -36,7 +36,8 @@ puppet_git_init | nil | initialize puppet from GIT repository, e.g. "git@github.
36
36
  puppet_git_pr | nil | checkout specific Pull Request from repository specified in puppet_git_init, e.g. "324"
37
37
  update_package_repos| true| update OS repository metadata
38
38
  custom_facts| Hash.new | Hash to set the puppet facts before running puppet apply
39
- install_custom_facts| false | Install custom facts to yaml file at "/tmp/kitchen/facter/kitchen.yaml"
39
+ install_custom_facts| false | Install custom facts to yaml file at "/tmp/kitchen/facter/kitchen.rb"
40
+ facter_file | nil | yaml file of custom facter_files to be provided to the puppet-apply command
40
41
  chef_bootstrap_url |"https://www.getchef.com/chef/install.sh"| the chef (needed for busser to run tests) NOTE: kitchen 1.4 only requires ruby to run busser so this is not required.
41
42
  puppetfile_path | | Path to Puppetfile
42
43
  puppet_apply_command | nil | Overwrite the puppet apply command. Needs "sudo -E puppet apply" as a prefix.
@@ -50,10 +51,10 @@ hiera_eyaml | false | use hiera-eyaml to encrypt hiera data
50
51
  hiera_eyaml_key_remote_path | "/etc/puppet/secure/keys" | directory of hiera-eyaml keys on server
51
52
  hiera_eyaml_key_path | "hiera_keys" | directory of hiera-eyaml keys on workstation
52
53
  hiera_deep_merge | false | install the deep_merge gem to support hiera deep merge mode
53
- facter_file | nil | yaml file of custom facter_files to be provided to the puppet-apply command
54
54
  http_proxy | nil | use http proxy when installing puppet, packages and running puppet
55
55
  https_proxy | nil | use https proxy when installing puppet, packages and running puppet
56
56
  puppet_logdest | nil | _Array_ of log destinations. Include 'console' if wanted
57
+ custom_options | | custom options to add to puppet apply command.
57
58
  custom_install_command | nil | Custom shell command to be used at install stage. Can be multiline. See examples below.
58
59
 
59
60
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-puppet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.33
4
+ version: 1.0.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neill Turner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-26 00:00:00.000000000 Z
11
+ date: 2015-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen