kitchen-puppet 3.2.1 → 3.3.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
  SHA1:
3
- metadata.gz: '042347429c02f1702cd07b8d5f0e7b8b615a3e7e'
4
- data.tar.gz: 91d9a4094ad08cd687390ea65caabd8be65af9e1
3
+ metadata.gz: 5fd3f0255598eccfa42487ea777dcc84ea1b1115
4
+ data.tar.gz: a880703ff969cafa64c25a1e8d60f7b61b3fd5d5
5
5
  SHA512:
6
- metadata.gz: 140cd72e439d2bcf86d4ba93afe607b400464b1fb492245037af98b284bff39b26a5cf2b790a424b857c18adf809310e8857c841ce96839483ba72d5a4021787
7
- data.tar.gz: 789d4e8e0b610fd903882287ff7b658a326af371945e3d47b450616c71da60688483746b7449a869f394b25f42363e5dd0126e948144c4beb8429358404d9395
6
+ metadata.gz: a7d4e20212b16e6dc6491eabddc791d1c56a13448f8d767d94e912d1deb3533d9c454c41e616c17aeed1004e98e80b23038530465abe3264cbfd7fb6181ccc85
7
+ data.tar.gz: 9ed8a833172fea17feb6f210fa9eedf4e2b7e539363b361801f5aaff110c8bf06ff601a7186a041287d25cc36c28d4499b33fb2834396cd6745632b1f80f6fb3
data/README.md CHANGED
@@ -7,14 +7,17 @@
7
7
  # kitchen-puppet
8
8
  A Test Kitchen Provisioner for Puppet
9
9
 
10
- The providers supports both puppet apply and puppet agent clients
10
+ The providers supports both puppet apply and puppet agent clients and puppet bolt.
11
11
 
12
12
  The PuppetApply provider works by passing the puppet repository based on attributes in .kitchen.yml & calling puppet apply.
13
13
 
14
14
  The PuppetAgent provider works by passing the puppetmaster and other attributes in .kitchen.yml & calling puppet agent.
15
15
 
16
+ The PuppetBolt provider works by passing the puppet bolt commands based on attributes in .kitchen.yml & calling puppet bolt.
16
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
+
19
+
20
+ This provider has been tested against the Ubuntu 1604 and Centos 7 boxes running in docker and vagrant/virtualbox.
18
21
 
19
22
  ## Resources
20
23
  * http://ehaselwanter.com/en/blog/2014/05/08/using-test-kitchen-with-puppet
@@ -90,8 +93,10 @@ Create a `.kitchen.yml`, much like one the described above:
90
93
  ```
91
94
 
92
95
  Sample Puppet Repositories
96
+ * A sample hello world example puppet repository with docker : https://github.com/neillturner/puppet_docker_repo
93
97
  * A sample hello world example puppet repository without environents : https://github.com/neillturner/puppet_vagrant_repo
94
98
  * A sample hello world example puppet repository with environents : https://github.com/neillturner/puppet_vagrant_environment_repo
99
+ * A sample puppet bolt example puppet repository with docker : https://github.com/neillturner/bolt_docker_repo
95
100
 
96
101
  ## Test-Kitchen Serverspec
97
102
 
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
 
27
27
  == FEATURES:
28
28
 
29
- Supports puppet apply, puppet agent, hiera, hiera-eyaml, hiera-eyaml-gpg, custom facts, librarian-puppet, puppet collections (v4)
29
+ Supports puppet apply, puppet agent, puppet bolt, hiera, hiera-eyaml, hiera-eyaml-gpg, custom facts, librarian-puppet, puppet collections
30
30
 
31
31
  TEXT
32
32
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kitchen
4
4
  module Puppet
5
- VERSION = '3.2.1'.freeze
5
+ VERSION = '3.3.1'.freeze
6
6
  end
7
7
  end
@@ -76,6 +76,7 @@ module Kitchen
76
76
  default_config :custom_install_command, nil
77
77
  default_config :custom_pre_install_command, nil
78
78
  default_config :custom_pre_apply_command, nil
79
+ default_config :custom_post_apply_command, nil
79
80
  default_config :puppet_whitelist_exit_code, nil
80
81
  default_config :require_puppet_omnibus, false
81
82
  default_config :puppet_omnibus_url, 'https://raw.githubusercontent.com/petems/puppet-install-shell/master/install_puppet_5_agent.sh'
@@ -0,0 +1,304 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ #
4
+ # Author:: Neill Turner (<neillwturner@gmail.com>
5
+ #
6
+ # Copyright (C) 2017 Neill Turner
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ #
21
+
22
+ require 'uri'
23
+ require 'json'
24
+ require 'kitchen'
25
+
26
+ module Kitchen
27
+ module Configurable
28
+ def platform_name
29
+ instance.platform.name
30
+ end
31
+ end
32
+
33
+ module Provisioner
34
+ #
35
+ # Puppet Bolt provisioner.
36
+ #
37
+ class PuppetBolt < Base
38
+ attr_accessor :tmp_dir
39
+
40
+ default_config :bolt_version, nil
41
+ default_config :require_bolt_repo, true
42
+ default_config :remove_bolt_repo, false
43
+ default_config :custom_install_command, nil
44
+ default_config :custom_pre_install_command, nil
45
+ default_config :custom_pre_bolt_command, nil
46
+ default_config :custom_post_bolt_command, nil
47
+ default_config :require_bolt_omnibus, false
48
+ default_config :bolt_commands, []
49
+ default_config :platform, &:platform_name
50
+ default_config :http_proxy, nil
51
+ default_config :https_proxy, nil
52
+ default_config :no_proxy, nil
53
+ # for future use
54
+ default_config :bolt_cmd, nil # bolt command run <COMMAND>, bolt script run, bolt task run, bolt plan run, bolt file upload
55
+ default_config :bolt_nodes, nil # REQUIRED
56
+ default_config :bolt_user, nil # BOLT_USER env variable
57
+ default_config :bolt_password, nil
58
+ default_config :bolt_modulepath, [] # Required for tasks and plans. The path to the module containing the task. Separate multiple paths with a semicolon (;) on Windows or a colon (:) on all other platforms.
59
+ default_config :bolt_params, nil
60
+ default_config :bolt_tty, false
61
+ default_config :bolt_insecure, true
62
+ default_config :bolt_transport, nil
63
+
64
+ # Install the dependencies for your platform.
65
+ # On CentOS 7 or Red Hat Enterprise Linux 7, run yum install -y make gcc ruby-devel
66
+ # On Fedora 25, run dnf install -y make gcc redhat-rpm-config ruby-devel rubygem-rdoc
67
+ # On Debian 9 or Ubuntu 16.04, run apt-get install -y make gcc ruby-dev
68
+ # On Mac OS X, run xcode-select --install
69
+ # Install Bolt as a gem by running gem install bolt
70
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
71
+ def install_command
72
+ return unless config[:require_bolt_repo] || config[:require_bolt_omnibus]
73
+ if config[:require_bolt_omnibus]
74
+ install_omnibus_command
75
+ else
76
+ case bolt_platform
77
+ when 'debian', 'ubuntu'
78
+ info("Installing puppet on #{config[:platform]}")
79
+ # need to add a CR to avoid trouble with proxy settings concatenation
80
+ <<-INSTALL
81
+
82
+ #{custom_pre_install_command}
83
+ if [ ! $(which bolt) ]; then
84
+ #{sudo('apt-get')} install -y make gcc ruby-dev
85
+ #{install_bolt}
86
+ fi
87
+ #{custom_install_command}
88
+ INSTALL
89
+ when 'redhat', 'centos', 'oracle', 'amazon'
90
+ info("Installing puppet from yum on #{bolt_platform}")
91
+ # need to add a CR to avoid trouble with proxy settings concatenation
92
+ <<-INSTALL
93
+
94
+ #{custom_pre_install_command}
95
+ if [ ! $(which bolt) ]; then
96
+ #{sudo('yum')} install -y make gcc ruby-devel
97
+ #{install_bolt}
98
+ fi
99
+ #{custom_install_command}
100
+ INSTALL
101
+ when 'fedora'
102
+ info("Installing bolt from dnf on #{bolt_platform}")
103
+ # need to add a CR to avoid trouble with proxy settings concatenation
104
+ <<-INSTALL
105
+
106
+ #{custom_pre_install_command}
107
+ if [ ! $(which bolt) ]; then
108
+ #{sudo('dnf')} install -y make gcc redhat-rpm-config ruby-devel rubygem-rdoc
109
+ #{install_bolt}
110
+ fi
111
+ #{custom_install_command}
112
+ INSTALL
113
+ when /^windows.*/
114
+ info("Installing puppet on #{bolt_platform}")
115
+ info('Powershell is not recognised by core test-kitchen assuming it is present') unless powershell_shell?
116
+ <<-INSTALL
117
+ if(Get-Command bolt -ErrorAction 0) { return; }
118
+ Write-Host "Disabling UAC..."
119
+ New-ItemProperty -Path HKLM:Software\\Microsoft\Windows\\CurrentVersion\\Policies\\System -Name EnableLUA -PropertyType DWord -Value 0 -Force
120
+ New-ItemProperty -Path HKLM:Software\\Microsoft\\Windows\\CurrentVersion\\Policies\System -Name ConsentPromptBehaviorAdmin -PropertyType DWord -Value 0 -Force
121
+ Write-Host "Install Chocolatey...."
122
+ iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
123
+ Write-Host "Install Ruby...."
124
+ choco install ruby
125
+ refreshenv
126
+ Write-Host "Install Bolt...."
127
+ gem install bolt
128
+ INSTALL
129
+ else
130
+ info('Installing bolt, will try to determine platform os')
131
+ # need to add a CR to avoid trouble with proxy settings concatenation
132
+ <<-INSTALL
133
+
134
+ #{custom_pre_install_command}
135
+ if [ ! $(which bolt) ]; then
136
+ if [ -f /etc/fedora-release ]; then
137
+ #{sudo('dnf')} install -y make gcc redhat-rpm-config ruby-devel rubygem-rdoc
138
+ else
139
+ if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
140
+ #{sudo('yum')} install -y make gcc ruby-devel
141
+ else
142
+ if [ -f /etc/system-release ] || [ grep -q 'Amazon Linux' /etc/system-release ]; then
143
+ #{sudo('yum')} install -y make gcc ruby-devel
144
+ else
145
+ #{sudo('apt-get')} install -y make gcc ruby-dev
146
+ fi
147
+ fi
148
+ fi
149
+ #{install_bolt}
150
+ fi
151
+ #{custom_install_command}
152
+ INSTALL
153
+ end
154
+ end
155
+ end
156
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
157
+
158
+ def install_omnibus_command
159
+ error('Installing bolt using an omnibus install script not currently supported')
160
+ end
161
+
162
+ def custom_pre_install_command
163
+ <<-INSTALL
164
+ #{config[:custom_pre_install_command]}
165
+ INSTALL
166
+ end
167
+
168
+ def custom_install_command
169
+ <<-INSTALL
170
+ #{config[:custom_install_command]}
171
+ INSTALL
172
+ end
173
+
174
+ def install_bolt
175
+ if config[:bolt_version]
176
+ <<-INSTALL
177
+ #{sudo('gem')} install --no-rdoc --no-ri bolt -v #{config[:bolt_version]}
178
+ INSTALL
179
+ else
180
+ <<-INSTALL
181
+ #{sudo('gem')} install --no-rdoc --no-ri bolt
182
+ INSTALL
183
+ end
184
+ end
185
+
186
+ def init_command
187
+ debug('Init Command')
188
+ end
189
+
190
+ def create_sandbox
191
+ super
192
+ debug("Creating local sandbox in #{sandbox_path}")
193
+ end
194
+
195
+ def cleanup_sandbox
196
+ return if sandbox_path.nil?
197
+ debug("Cleaning up local sandbox in #{sandbox_path}")
198
+ FileUtils.rmtree(sandbox_path)
199
+ return if remove_repo.nil?
200
+ debug("Cleaning up remote sandbox: #{remove_repo}")
201
+ instance.remote_exec remove_repo
202
+ end
203
+
204
+ def run_command
205
+ if config[:custom_post_bolt_command]
206
+ custom_post_bolt_trap = <<-TRAP
207
+ function custom_post_bolt_command {
208
+ #{config[:custom_post_bolt_command]}
209
+ }
210
+ trap custom_post_bolt_command EXIT
211
+ TRAP
212
+ end
213
+ result = <<-RUN
214
+ #{config[:custom_pre_bolt_command]}
215
+ #{custom_post_bolt_trap}
216
+ RUN
217
+ bolt_commands_to_run.each do |a|
218
+ result = <<-RUN
219
+ #{result}
220
+ #{a}
221
+ RUN
222
+ end
223
+ info("Going to invoke bolt with: #{result}")
224
+ result
225
+ end
226
+
227
+ protected
228
+
229
+ def bolt_commands_to_run
230
+ if config[:bolt_commands]
231
+ config[:bolt_commands].is_a?(Array) ? config[:bolt_commands] : [config[:bolt_commands]]
232
+ else
233
+ []
234
+ end
235
+ end
236
+
237
+ def bolt_platform
238
+ config[:platform].gsub(/-.*/, '')
239
+ end
240
+
241
+ def remove_repo
242
+ config[:remove_bolt_repo] ? "#{sudo('rm')} -rf /tmp/kitchen " : nil
243
+ end
244
+
245
+ def sudo_env(pm)
246
+ s = https_proxy ? "https_proxy=#{https_proxy}" : nil
247
+ p = http_proxy ? "http_proxy=#{http_proxy}" : nil
248
+ n = no_proxy ? "no_proxy=#{no_proxy}" : nil
249
+ p || s ? "#{sudo('env')} #{p} #{s} #{n} #{pm}" : sudo(pm).to_s
250
+ end
251
+
252
+ def proxy_parm
253
+ http_proxy ? "--httpproxy #{URI.parse(http_proxy).host.downcase} --httpport #{URI.parse(http_proxy).port} " : nil
254
+ end
255
+
256
+ def gem_proxy_parm
257
+ p = http_proxy ? "--http-proxy #{http_proxy}" : nil
258
+ n = no_proxy ? "--no-http-proxy #{no_proxy}" : nil
259
+ p || n ? "#{p} #{n}" : nil
260
+ end
261
+
262
+ def wget_proxy_parm
263
+ p = http_proxy ? "-e http_proxy=#{http_proxy}" : nil
264
+ s = https_proxy ? "-e https_proxy=#{https_proxy}" : nil
265
+ n = no_proxy ? "-e no_proxy=#{no_proxy}" : nil
266
+ p || s ? "-e use_proxy=yes #{p} #{s} #{n}" : nil
267
+ end
268
+
269
+ def posh_proxy_parm
270
+ http_proxy ? "-Proxy #{http_proxy}" : nil
271
+ end
272
+
273
+ def powershell?
274
+ return true if powershell_shell?
275
+ return true if bolt_platform =~ /^windows.*/
276
+ false
277
+ end
278
+
279
+ def export_http_proxy_parm
280
+ http_proxy ? "export http_proxy=#{http_proxy}" : nil
281
+ end
282
+
283
+ def export_https_proxy_parm
284
+ https_proxy ? "export https_proxy=#{https_proxy}" : nil
285
+ end
286
+
287
+ def export_no_proxy_parm
288
+ no_proxy ? "export no_proxy=#{no_proxy}" : nil
289
+ end
290
+
291
+ def http_proxy
292
+ config[:http_proxy]
293
+ end
294
+
295
+ def https_proxy
296
+ config[:https_proxy]
297
+ end
298
+
299
+ def no_proxy
300
+ config[:no_proxy]
301
+ end
302
+ end
303
+ end
304
+ end
@@ -346,3 +346,63 @@ provisioner:
346
346
  - 0
347
347
  - 2
348
348
  ```
349
+
350
+ # Puppet Bolt Provisioner Options
351
+
352
+ key | default value | Notes
353
+ ----|---------------|--------
354
+ bolt_commands | nil | array of bolt commands to run.
355
+ bolt_version | | desired puppet bolt version, defaults to latest.
356
+ custom_pre_install_command | nil | Custom shell command to be used at beginning of install stage. Can be multiline.
357
+ custom_install_command | nil | Custom shell command to be used at end of install stage. Can be multiline. See examples below.
358
+ custom_pre_bolt_command | nil | Custom shell command to be used before the puppet bolt stage. Can be multiline.
359
+ custom_post_bolt_command | nil | Custom shell command to be used after the puppet bolt stage. Can be multiline.
360
+ http_proxy | nil | use http proxy when installing bolt, packages and running bolt
361
+ https_proxy | nil | use https proxy when installing bolt, packages and running bolt
362
+ no_proxy | nil | list of URLs or IPs that should be excluded from proxying
363
+ platform | platform_name kitchen.yml parameter | OS platform of server
364
+ require_bolt_omnibus | false | Set if using omnibus bolt install. (for future use)
365
+ require_bolt_repo | true | Set if using a puppet bolt from yum or apt repo
366
+ remove_bolt_repo | false | remove copy of bolt configuration on server after running bolt
367
+
368
+ ## Puppet Bolt Configuring Provisioner Options
369
+
370
+ The Bolt provisioner can be configured globally or per suite, global settings act as defaults for all suites, you can then customise per suite, for example:
371
+
372
+ ```yaml
373
+ ---
374
+ driver:
375
+ name: docker
376
+ use_sudo: false
377
+ privileged: true
378
+
379
+ provisioner:
380
+ name: puppet_bolt
381
+ bolt_commands:
382
+ - bolt --help
383
+ - bolt --version
384
+
385
+ platforms:
386
+ - name: ubuntu-16.04
387
+ driver_config:
388
+ image: ubuntu:16.04
389
+ platform: ubuntu
390
+ - name: centos-6.6
391
+ driver_config:
392
+ image: centos:6.6
393
+ platform: centos
394
+ - name: centos-7
395
+ driver_config:
396
+ image: centos:latest
397
+ platform: centos
398
+ run_command: /usr/sbin/init
399
+ - name: 'centos'
400
+ driver_plugin: docker
401
+ driver:
402
+ use_sudo: false
403
+ image: centos:7
404
+ run_command: /usr/sbin/init
405
+
406
+ suites:
407
+ - name: base
408
+ ```
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: 3.2.1
4
+ version: 3.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neill Turner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-05 00:00:00.000000000 Z
11
+ date: 2017-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
@@ -45,7 +45,7 @@ description: |2+
45
45
 
46
46
  == FEATURES:
47
47
 
48
- Supports puppet apply, puppet agent, hiera, hiera-eyaml, hiera-eyaml-gpg, custom facts, librarian-puppet, puppet collections (v4)
48
+ Supports puppet apply, puppet agent, puppet bolt, hiera, hiera-eyaml, hiera-eyaml-gpg, custom facts, librarian-puppet, puppet collections
49
49
 
50
50
  email:
51
51
  - neillwturner@gmail.com
@@ -59,6 +59,7 @@ files:
59
59
  - lib/kitchen/provisioner/puppet/librarian.rb
60
60
  - lib/kitchen/provisioner/puppet_agent.rb
61
61
  - lib/kitchen/provisioner/puppet_apply.rb
62
+ - lib/kitchen/provisioner/puppet_bolt.rb
62
63
  - provisioner_options.md
63
64
  homepage: https://github.com/neillturner/kitchen-puppet
64
65
  licenses: