kitchen-puppet 3.4.1 → 3.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +283 -283
- data/kitchen-puppet.gemspec +32 -32
- data/lib/kitchen-puppet/version.rb +7 -7
- data/lib/kitchen/provisioner/puppet/librarian.rb +111 -111
- data/lib/kitchen/provisioner/puppet/r10k.rb +73 -73
- data/lib/kitchen/provisioner/puppet_agent.rb +430 -430
- data/lib/kitchen/provisioner/puppet_apply.rb +1465 -1464
- data/lib/kitchen/provisioner/puppet_bolt.rb +307 -307
- data/provisioner_options.md +411 -411
- metadata +3 -3
data/kitchen-puppet.gemspec
CHANGED
@@ -1,32 +1,32 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
4
|
-
require 'kitchen-puppet/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = 'kitchen-puppet'
|
8
|
-
s.license = 'Apache-2.0'
|
9
|
-
s.version = Kitchen::Puppet::VERSION
|
10
|
-
s.authors = ['Neill Turner']
|
11
|
-
s.email = ['neillwturner@gmail.com']
|
12
|
-
s.homepage = 'https://github.com/neillturner/kitchen-puppet'
|
13
|
-
s.summary = 'puppet provisioner for test-kitchen'
|
14
|
-
candidates = Dir.glob('{lib}/**/*') + ['README.md', 'provisioner_options.md', 'kitchen-puppet.gemspec']
|
15
|
-
s.files = candidates.sort
|
16
|
-
s.platform = Gem::Platform::RUBY
|
17
|
-
s.require_paths = ['lib']
|
18
|
-
s.rubyforge_project = '[none]'
|
19
|
-
s.required_ruby_version = '>= 2.1'
|
20
|
-
s.add_dependency 'net-ssh', '>= 3'
|
21
|
-
s.add_dependency 'test-kitchen', '~> 1.4'
|
22
|
-
s.description = <<-TEXT
|
23
|
-
== DESCRIPTION:
|
24
|
-
|
25
|
-
Puppet Provisioner for Test Kitchen
|
26
|
-
|
27
|
-
== FEATURES:
|
28
|
-
|
29
|
-
Supports puppet apply, puppet agent, puppet bolt, hiera, hiera-eyaml, hiera-eyaml-gpg, custom facts, librarian-puppet, puppet collections
|
30
|
-
|
31
|
-
TEXT
|
32
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
4
|
+
require 'kitchen-puppet/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'kitchen-puppet'
|
8
|
+
s.license = 'Apache-2.0'
|
9
|
+
s.version = Kitchen::Puppet::VERSION
|
10
|
+
s.authors = ['Neill Turner']
|
11
|
+
s.email = ['neillwturner@gmail.com']
|
12
|
+
s.homepage = 'https://github.com/neillturner/kitchen-puppet'
|
13
|
+
s.summary = 'puppet provisioner for test-kitchen'
|
14
|
+
candidates = Dir.glob('{lib}/**/*') + ['README.md', 'provisioner_options.md', 'kitchen-puppet.gemspec']
|
15
|
+
s.files = candidates.sort
|
16
|
+
s.platform = Gem::Platform::RUBY
|
17
|
+
s.require_paths = ['lib']
|
18
|
+
s.rubyforge_project = '[none]'
|
19
|
+
s.required_ruby_version = '>= 2.1'
|
20
|
+
s.add_dependency 'net-ssh', '>= 3'
|
21
|
+
s.add_dependency 'test-kitchen', '~> 1.4'
|
22
|
+
s.description = <<-TEXT
|
23
|
+
== DESCRIPTION:
|
24
|
+
|
25
|
+
Puppet Provisioner for Test Kitchen
|
26
|
+
|
27
|
+
== FEATURES:
|
28
|
+
|
29
|
+
Supports puppet apply, puppet agent, puppet bolt, hiera, hiera-eyaml, hiera-eyaml-gpg, custom facts, librarian-puppet, puppet collections
|
30
|
+
|
31
|
+
TEXT
|
32
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
module Kitchen
|
4
|
-
module Puppet
|
5
|
-
VERSION = '3.4.
|
6
|
-
end
|
7
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Kitchen
|
4
|
+
module Puppet
|
5
|
+
VERSION = '3.4.2'.freeze
|
6
|
+
end
|
7
|
+
end
|
@@ -1,111 +1,111 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
#
|
4
|
-
# Author:: Fletcher Nichol (<fnichol@nichol.ca>) Neill Turner (<neillwturner@gmail.com>)
|
5
|
-
#
|
6
|
-
# Copyright (C) 2013, Fletcher Nichol, 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
|
-
require 'kitchen/errors'
|
21
|
-
require 'kitchen/logging'
|
22
|
-
require 'librarian/ui'
|
23
|
-
|
24
|
-
module Kitchen
|
25
|
-
module Provisioner
|
26
|
-
module Puppet
|
27
|
-
# Puppet module resolver that uses Librarian-Puppet and a Puppetfile to
|
28
|
-
# calculate # dependencies.
|
29
|
-
#
|
30
|
-
class Librarian
|
31
|
-
include Logging
|
32
|
-
|
33
|
-
class LoggerUI < ::Librarian::UI
|
34
|
-
attr_writer :logger
|
35
|
-
|
36
|
-
def initialize(logger)
|
37
|
-
@logger = logger
|
38
|
-
end
|
39
|
-
|
40
|
-
def warn(message = nil)
|
41
|
-
@logger.warn(message || yield)
|
42
|
-
end
|
43
|
-
|
44
|
-
def debug(message = nil)
|
45
|
-
@logger.debug(message || yield)
|
46
|
-
end
|
47
|
-
|
48
|
-
def error(message = nil)
|
49
|
-
@logger.error(message || yield)
|
50
|
-
end
|
51
|
-
|
52
|
-
def info(message = nil)
|
53
|
-
@logger.info(message || yield)
|
54
|
-
end
|
55
|
-
|
56
|
-
def confirm(message = nil)
|
57
|
-
@logger.info(message || yield)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def initialize(puppetfile, path, logger = Kitchen.logger)
|
62
|
-
@puppetfile = puppetfile
|
63
|
-
@path = path
|
64
|
-
@logger = logger
|
65
|
-
end
|
66
|
-
|
67
|
-
def self.load!(logger = Kitchen.logger)
|
68
|
-
load_librarian!(logger)
|
69
|
-
end
|
70
|
-
|
71
|
-
def resolve
|
72
|
-
version = ::Librarian::Puppet::VERSION
|
73
|
-
info("Resolving module dependencies with Librarian-Puppet #{version}...")
|
74
|
-
debug("Using Puppetfile from #{puppetfile}")
|
75
|
-
|
76
|
-
env = ::Librarian::Puppet::Environment.new(
|
77
|
-
project_path: File.expand_path(File.dirname(puppetfile))
|
78
|
-
)
|
79
|
-
env.ui = LoggerUI.new(@logger)
|
80
|
-
|
81
|
-
env.config_db.local['path'] = path
|
82
|
-
::Librarian::Action::Resolve.new(env).run
|
83
|
-
::Librarian::Action::Install.new(env).run
|
84
|
-
end
|
85
|
-
|
86
|
-
attr_reader :puppetfile, :path, :logger
|
87
|
-
|
88
|
-
def self.load_librarian!(logger)
|
89
|
-
first_load = require 'librarian/puppet'
|
90
|
-
require 'librarian/puppet/environment'
|
91
|
-
require 'librarian/action/resolve'
|
92
|
-
require 'librarian/action/install'
|
93
|
-
|
94
|
-
version = ::Librarian::Puppet::VERSION
|
95
|
-
if first_load
|
96
|
-
logger.debug("Librarian-Puppet #{version} library loaded")
|
97
|
-
else
|
98
|
-
logger.debug("Librarian-Puppet #{version} previously loaded")
|
99
|
-
end
|
100
|
-
rescue LoadError => e
|
101
|
-
logger.fatal("The `librarian-puppet' gem is missing and must be installed" \
|
102
|
-
' or cannot be properly activated. Run' \
|
103
|
-
' `gem install librarian-puppet` or add the following to your' \
|
104
|
-
" Gemfile if you are using Bundler: `gem 'librarian-puppet'`.")
|
105
|
-
raise UserError,
|
106
|
-
"Could not load or activate Librarian-Puppet (#{e.message})"
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
#
|
4
|
+
# Author:: Fletcher Nichol (<fnichol@nichol.ca>) Neill Turner (<neillwturner@gmail.com>)
|
5
|
+
#
|
6
|
+
# Copyright (C) 2013, Fletcher Nichol, 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
|
+
require 'kitchen/errors'
|
21
|
+
require 'kitchen/logging'
|
22
|
+
require 'librarian/ui'
|
23
|
+
|
24
|
+
module Kitchen
|
25
|
+
module Provisioner
|
26
|
+
module Puppet
|
27
|
+
# Puppet module resolver that uses Librarian-Puppet and a Puppetfile to
|
28
|
+
# calculate # dependencies.
|
29
|
+
#
|
30
|
+
class Librarian
|
31
|
+
include Logging
|
32
|
+
|
33
|
+
class LoggerUI < ::Librarian::UI
|
34
|
+
attr_writer :logger
|
35
|
+
|
36
|
+
def initialize(logger)
|
37
|
+
@logger = logger
|
38
|
+
end
|
39
|
+
|
40
|
+
def warn(message = nil)
|
41
|
+
@logger.warn(message || yield)
|
42
|
+
end
|
43
|
+
|
44
|
+
def debug(message = nil)
|
45
|
+
@logger.debug(message || yield)
|
46
|
+
end
|
47
|
+
|
48
|
+
def error(message = nil)
|
49
|
+
@logger.error(message || yield)
|
50
|
+
end
|
51
|
+
|
52
|
+
def info(message = nil)
|
53
|
+
@logger.info(message || yield)
|
54
|
+
end
|
55
|
+
|
56
|
+
def confirm(message = nil)
|
57
|
+
@logger.info(message || yield)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def initialize(puppetfile, path, logger = Kitchen.logger)
|
62
|
+
@puppetfile = puppetfile
|
63
|
+
@path = path
|
64
|
+
@logger = logger
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.load!(logger = Kitchen.logger)
|
68
|
+
load_librarian!(logger)
|
69
|
+
end
|
70
|
+
|
71
|
+
def resolve
|
72
|
+
version = ::Librarian::Puppet::VERSION
|
73
|
+
info("Resolving module dependencies with Librarian-Puppet #{version}...")
|
74
|
+
debug("Using Puppetfile from #{puppetfile}")
|
75
|
+
|
76
|
+
env = ::Librarian::Puppet::Environment.new(
|
77
|
+
project_path: File.expand_path(File.dirname(puppetfile))
|
78
|
+
)
|
79
|
+
env.ui = LoggerUI.new(@logger)
|
80
|
+
|
81
|
+
env.config_db.local['path'] = path
|
82
|
+
::Librarian::Action::Resolve.new(env).run
|
83
|
+
::Librarian::Action::Install.new(env).run
|
84
|
+
end
|
85
|
+
|
86
|
+
attr_reader :puppetfile, :path, :logger
|
87
|
+
|
88
|
+
def self.load_librarian!(logger)
|
89
|
+
first_load = require 'librarian/puppet'
|
90
|
+
require 'librarian/puppet/environment'
|
91
|
+
require 'librarian/action/resolve'
|
92
|
+
require 'librarian/action/install'
|
93
|
+
|
94
|
+
version = ::Librarian::Puppet::VERSION
|
95
|
+
if first_load
|
96
|
+
logger.debug("Librarian-Puppet #{version} library loaded")
|
97
|
+
else
|
98
|
+
logger.debug("Librarian-Puppet #{version} previously loaded")
|
99
|
+
end
|
100
|
+
rescue LoadError => e
|
101
|
+
logger.fatal("The `librarian-puppet' gem is missing and must be installed" \
|
102
|
+
' or cannot be properly activated. Run' \
|
103
|
+
' `gem install librarian-puppet` or add the following to your' \
|
104
|
+
" Gemfile if you are using Bundler: `gem 'librarian-puppet'`.")
|
105
|
+
raise UserError,
|
106
|
+
"Could not load or activate Librarian-Puppet (#{e.message})"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -1,73 +1,73 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
#
|
4
|
-
# Author:: Fletcher Nichol (<fnichol@nichol.ca>) Neill Turner (<neillwturner@gmail.com>) Dennis Lerch (<dennis.lerch@transporeon.com>)
|
5
|
-
#
|
6
|
-
# Copyright (C) 2018, Fletcher Nichol, Neill Turner, Dennis Lerch
|
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
|
-
require 'kitchen/errors'
|
21
|
-
require 'kitchen/logging'
|
22
|
-
|
23
|
-
module Kitchen
|
24
|
-
module Provisioner
|
25
|
-
module Puppet
|
26
|
-
# Puppet module resolver that uses R10K and a Puppetfile to
|
27
|
-
# calculate # dependencies.
|
28
|
-
#
|
29
|
-
class R10K
|
30
|
-
include Logging
|
31
|
-
|
32
|
-
def initialize(puppetfile, path, logger = Kitchen.logger)
|
33
|
-
@puppetfile = puppetfile
|
34
|
-
@path = path
|
35
|
-
@logger = logger
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.load!(logger = Kitchen.logger)
|
39
|
-
load_r10k!(logger)
|
40
|
-
end
|
41
|
-
|
42
|
-
def resolve
|
43
|
-
version = ::R10K::VERSION
|
44
|
-
info("Resolving module dependencies with R10K-Puppet #{version}...")
|
45
|
-
debug("Using Puppetfile from #{puppetfile}")
|
46
|
-
|
47
|
-
::R10K::Git::Cache.settings[:cache_root] = '.r10k/git'
|
48
|
-
::R10K::Forge::ModuleRelease.settings[:cache_root] = '.r10k/cache'
|
49
|
-
|
50
|
-
pf = ::R10K::Puppetfile.new(nil, path, puppetfile)
|
51
|
-
pf.load
|
52
|
-
pf.modules.map(&:sync)
|
53
|
-
end
|
54
|
-
|
55
|
-
attr_reader :puppetfile, :path, :logger
|
56
|
-
|
57
|
-
def self.load_r10k!(logger)
|
58
|
-
require 'r10k/puppetfile'
|
59
|
-
|
60
|
-
version = ::R10K::VERSION
|
61
|
-
logger.debug("R10K #{version} library loaded")
|
62
|
-
rescue LoadError => e
|
63
|
-
logger.fatal("The `r10k' gem is missing and must be installed" \
|
64
|
-
' or cannot be properly activated. Run' \
|
65
|
-
' `gem install r10k` or add the following to your' \
|
66
|
-
" Gemfile if you are using Bundler: `gem 'r10k'`.")
|
67
|
-
raise UserError,
|
68
|
-
"Could not load or activate R10K (#{e.message})"
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
#
|
4
|
+
# Author:: Fletcher Nichol (<fnichol@nichol.ca>) Neill Turner (<neillwturner@gmail.com>) Dennis Lerch (<dennis.lerch@transporeon.com>)
|
5
|
+
#
|
6
|
+
# Copyright (C) 2018, Fletcher Nichol, Neill Turner, Dennis Lerch
|
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
|
+
require 'kitchen/errors'
|
21
|
+
require 'kitchen/logging'
|
22
|
+
|
23
|
+
module Kitchen
|
24
|
+
module Provisioner
|
25
|
+
module Puppet
|
26
|
+
# Puppet module resolver that uses R10K and a Puppetfile to
|
27
|
+
# calculate # dependencies.
|
28
|
+
#
|
29
|
+
class R10K
|
30
|
+
include Logging
|
31
|
+
|
32
|
+
def initialize(puppetfile, path, logger = Kitchen.logger)
|
33
|
+
@puppetfile = puppetfile
|
34
|
+
@path = path
|
35
|
+
@logger = logger
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.load!(logger = Kitchen.logger)
|
39
|
+
load_r10k!(logger)
|
40
|
+
end
|
41
|
+
|
42
|
+
def resolve
|
43
|
+
version = ::R10K::VERSION
|
44
|
+
info("Resolving module dependencies with R10K-Puppet #{version}...")
|
45
|
+
debug("Using Puppetfile from #{puppetfile}")
|
46
|
+
|
47
|
+
::R10K::Git::Cache.settings[:cache_root] = '.r10k/git'
|
48
|
+
::R10K::Forge::ModuleRelease.settings[:cache_root] = '.r10k/cache'
|
49
|
+
|
50
|
+
pf = ::R10K::Puppetfile.new(nil, path, puppetfile)
|
51
|
+
pf.load
|
52
|
+
pf.modules.map(&:sync)
|
53
|
+
end
|
54
|
+
|
55
|
+
attr_reader :puppetfile, :path, :logger
|
56
|
+
|
57
|
+
def self.load_r10k!(logger)
|
58
|
+
require 'r10k/puppetfile'
|
59
|
+
|
60
|
+
version = ::R10K::VERSION
|
61
|
+
logger.debug("R10K #{version} library loaded")
|
62
|
+
rescue LoadError => e
|
63
|
+
logger.fatal("The `r10k' gem is missing and must be installed" \
|
64
|
+
' or cannot be properly activated. Run' \
|
65
|
+
' `gem install r10k` or add the following to your' \
|
66
|
+
" Gemfile if you are using Bundler: `gem 'r10k'`.")
|
67
|
+
raise UserError,
|
68
|
+
"Could not load or activate R10K (#{e.message})"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -1,430 +1,430 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
#
|
4
|
-
# Author:: Chris Lundquist (<chris.lundquist@github.com>) Neill Turner (<neillwturner@gmail.com>)
|
5
|
-
#
|
6
|
-
# Copyright (C) 2013,2014 Chris Lundquist, 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
|
-
# See https://github.com/neillturner/kitchen-puppet/blob/master/provisioner_options.md
|
21
|
-
# for documentation configuration parameters with puppet_agent provisioner.
|
22
|
-
#
|
23
|
-
|
24
|
-
require 'json'
|
25
|
-
require 'kitchen'
|
26
|
-
require 'kitchen/provisioner/base'
|
27
|
-
require 'kitchen/provisioner/puppet/librarian'
|
28
|
-
|
29
|
-
module Kitchen
|
30
|
-
class Busser
|
31
|
-
def non_suite_dirs
|
32
|
-
%w[data data_bags environments nodes roles puppet]
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
module Provisioner
|
37
|
-
#
|
38
|
-
# Puppet Agent provisioner.
|
39
|
-
#
|
40
|
-
class PuppetAgent < Base
|
41
|
-
attr_accessor :tmp_dir
|
42
|
-
|
43
|
-
default_config :require_puppet_omnibus, false
|
44
|
-
# TODO: use something like https://github.com/fnichol/omnibus-puppet
|
45
|
-
default_config :puppet_omnibus_url, nil
|
46
|
-
default_config :puppet_environment, nil
|
47
|
-
default_config :puppet_omnibus_remote_path, '/opt/puppet'
|
48
|
-
default_config :puppet_version, nil
|
49
|
-
default_config :facter_version, nil
|
50
|
-
default_config :require_puppet_repo, true
|
51
|
-
default_config :require_chef_for_busser, true
|
52
|
-
|
53
|
-
default_config :puppet_apt_repo, 'http://apt.puppetlabs.com/puppetlabs-release-precise.deb'
|
54
|
-
default_config :puppet_yum_repo, 'https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm'
|
55
|
-
default_config :chef_bootstrap_url, 'https://www.chef.io/chef/install.sh'
|
56
|
-
|
57
|
-
default_config :puppet_agent_command, nil
|
58
|
-
|
59
|
-
default_config :http_proxy, nil
|
60
|
-
default_config :https_proxy, nil
|
61
|
-
default_config :no_proxy, nil
|
62
|
-
default_config :puppet_whitelist_exit_code, nil
|
63
|
-
|
64
|
-
default_config :puppet_config_path do |provisioner|
|
65
|
-
provisioner.calculate_path('puppet.conf', :file)
|
66
|
-
end
|
67
|
-
|
68
|
-
default_config :puppet_debug, false
|
69
|
-
default_config :puppet_verbose, false
|
70
|
-
default_config :puppet_noop, false
|
71
|
-
default_config :puppet_platform, ''
|
72
|
-
default_config :update_package_repos, true
|
73
|
-
|
74
|
-
default_config :custom_facts, {}
|
75
|
-
|
76
|
-
default_config :puppet_detailed_exitcodes, nil
|
77
|
-
default_config :puppet_logdest, nil
|
78
|
-
default_config :puppet_masterport, nil
|
79
|
-
default_config :puppet_test, false
|
80
|
-
default_config :puppet_onetime, true
|
81
|
-
default_config :puppet_no_daemonize, true
|
82
|
-
# will default to 'puppet'
|
83
|
-
default_config :puppet_server, nil
|
84
|
-
default_config :puppet_waitforcert, '0'
|
85
|
-
default_config :puppet_certname, nil
|
86
|
-
default_config :puppet_digest, nil
|
87
|
-
|
88
|
-
def calculate_path(path, type = :directory)
|
89
|
-
base = config[:test_base_path]
|
90
|
-
candidates = []
|
91
|
-
candidates << File.join(base, instance.suite.name, 'puppet', path)
|
92
|
-
candidates << File.join(base, instance.suite.name, path)
|
93
|
-
candidates << File.join(base, path)
|
94
|
-
candidates << File.join(Dir.pwd, path)
|
95
|
-
|
96
|
-
candidates.find do |c|
|
97
|
-
type == :directory ? File.directory?(c) : File.file?(c)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
102
|
-
def install_command
|
103
|
-
return unless config[:require_puppet_omnibus] || config[:require_puppet_repo]
|
104
|
-
if config[:require_puppet_omnibus]
|
105
|
-
info('Installing puppet using puppet omnibus')
|
106
|
-
version = ''
|
107
|
-
version = "-v #{config[:puppet_version]}" if config[:puppet_version]
|
108
|
-
<<-INSTALL
|
109
|
-
#{Util.shell_helpers}
|
110
|
-
|
111
|
-
if [ ! -d "#{config[:puppet_omnibus_remote_path]}" ]; then
|
112
|
-
echo "-----> Installing Puppet Omnibus"
|
113
|
-
do_download #{config[:puppet_omnibus_url]} /tmp/puppet_install.sh
|
114
|
-
#{sudo('sh')} /tmp/puppet_install.sh #{version}
|
115
|
-
fi
|
116
|
-
#{install_busser}
|
117
|
-
INSTALL
|
118
|
-
else
|
119
|
-
case puppet_platform
|
120
|
-
when 'debian', 'ubuntu'
|
121
|
-
info("Installing puppet on #{puppet_platform}")
|
122
|
-
<<-INSTALL
|
123
|
-
if [ ! $(which puppet) ]; then
|
124
|
-
#{sudo('apt-get')} -y install wget
|
125
|
-
#{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
|
126
|
-
#{sudo('dpkg')} -i #{puppet_apt_repo_file}
|
127
|
-
#{update_packages_debian_cmd}
|
128
|
-
#{sudo_env('apt-get')} -y install facter#{facter_debian_version}
|
129
|
-
#{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
|
130
|
-
#{sudo('apt-get')} -y install puppet#{puppet_debian_version}
|
131
|
-
fi
|
132
|
-
#{install_busser}
|
133
|
-
INSTALL
|
134
|
-
when 'redhat', 'centos', 'fedora', 'oracle', 'amazon'
|
135
|
-
info("Installing puppet on #{puppet_platform}")
|
136
|
-
<<-INSTALL
|
137
|
-
if [ ! $(which puppet) ]; then
|
138
|
-
#{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
|
139
|
-
#{update_packages_redhat_cmd}
|
140
|
-
#{sudo('yum')} -y install puppet#{puppet_redhat_version}
|
141
|
-
fi
|
142
|
-
#{install_busser}
|
143
|
-
INSTALL
|
144
|
-
else
|
145
|
-
info('Installing puppet, will try to determine platform os')
|
146
|
-
<<-INSTALL
|
147
|
-
if [ ! $(which puppet) ]; then
|
148
|
-
if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
|
149
|
-
#{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
|
150
|
-
#{update_packages_redhat_cmd}
|
151
|
-
#{sudo('yum')} -y install puppet#{puppet_redhat_version}
|
152
|
-
else
|
153
|
-
if [ -f /etc/system-release ] || grep -q 'Amazon Linux' /etc/system-release; then
|
154
|
-
#{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
|
155
|
-
#{update_packages_redhat_cmd}
|
156
|
-
#{sudo('yum')} -y install puppet#{puppet_redhat_version}
|
157
|
-
else
|
158
|
-
#{sudo('apt-get')} -y install wget
|
159
|
-
#{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
|
160
|
-
#{sudo('dpkg')} -i #{puppet_apt_repo_file}
|
161
|
-
#{update_packages_debian_cmd}
|
162
|
-
#{sudo('apt-get')} -y install facter#{facter_debian_version}
|
163
|
-
#{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
|
164
|
-
#{sudo('apt-get')} -y install puppet#{puppet_debian_version}
|
165
|
-
fi
|
166
|
-
fi
|
167
|
-
fi
|
168
|
-
#{install_busser}
|
169
|
-
INSTALL
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
173
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
174
|
-
|
175
|
-
def install_busser
|
176
|
-
return unless config[:require_chef_for_busser]
|
177
|
-
<<-INSTALL
|
178
|
-
#{Util.shell_helpers}
|
179
|
-
# install chef omnibus so that busser works as this is needed to run tests :(
|
180
|
-
# TODO: work out how to install enough ruby
|
181
|
-
# and set busser: { :ruby_bindir => '/usr/bin/ruby' } so that we dont need the
|
182
|
-
# whole chef client
|
183
|
-
if [ ! -d "/opt/chef" ]
|
184
|
-
then
|
185
|
-
echo "-----> Installing Chef Omnibus to install busser to run tests"
|
186
|
-
do_download #{chef_url} /tmp/install.sh
|
187
|
-
#{sudo('sh')} /tmp/install.sh
|
188
|
-
fi
|
189
|
-
INSTALL
|
190
|
-
end
|
191
|
-
|
192
|
-
def init_command; end
|
193
|
-
|
194
|
-
def create_sandbox
|
195
|
-
super
|
196
|
-
debug("Creating local sandbox in #{sandbox_path}")
|
197
|
-
|
198
|
-
yield if block_given?
|
199
|
-
|
200
|
-
prepare_puppet_config
|
201
|
-
info('Finished Preparing files for transfer')
|
202
|
-
end
|
203
|
-
|
204
|
-
def cleanup_sandbox
|
205
|
-
return if sandbox_path.nil?
|
206
|
-
debug("Cleaning up local sandbox in #{sandbox_path}")
|
207
|
-
FileUtils.rmtree(sandbox_path)
|
208
|
-
end
|
209
|
-
|
210
|
-
def prepare_command
|
211
|
-
commands = []
|
212
|
-
|
213
|
-
if puppet_config
|
214
|
-
commands << [
|
215
|
-
sudo('cp'),
|
216
|
-
File.join(config[:root_path], 'puppet.conf'),
|
217
|
-
'/etc/puppet'
|
218
|
-
].join(' ')
|
219
|
-
end
|
220
|
-
|
221
|
-
command = commands.join(' && ')
|
222
|
-
debug(command)
|
223
|
-
command
|
224
|
-
end
|
225
|
-
|
226
|
-
def run_command
|
227
|
-
return config[:puppet_agent_command] unless config[:puppet_agent_command].nil?
|
228
|
-
[
|
229
|
-
custom_facts,
|
230
|
-
sudo_env('puppet'),
|
231
|
-
'agent',
|
232
|
-
puppet_server_flag,
|
233
|
-
"--waitforcert=#{config[:puppet_waitforcert]}",
|
234
|
-
puppet_masterport_flag,
|
235
|
-
puppet_certname_flag,
|
236
|
-
puppet_digest_flag,
|
237
|
-
puppet_detailed_exitcodes_flag,
|
238
|
-
puppet_logdest_flag,
|
239
|
-
puppet_test_flag,
|
240
|
-
puppet_onetime_flag,
|
241
|
-
puppet_no_daemonize_flag,
|
242
|
-
puppet_noop_flag,
|
243
|
-
puppet_environment_flag,
|
244
|
-
puppet_verbose_flag,
|
245
|
-
puppet_debug_flag,
|
246
|
-
puppet_whitelist_exit_code
|
247
|
-
].compact.join(' ')
|
248
|
-
end
|
249
|
-
|
250
|
-
protected
|
251
|
-
|
252
|
-
def load_needed_dependencies!; end
|
253
|
-
|
254
|
-
def puppet_environment_flag
|
255
|
-
config[:puppet_environment] ? "--environment=\"#{config[:puppet_environment]}\"" : nil
|
256
|
-
end
|
257
|
-
|
258
|
-
def puppet_config
|
259
|
-
config[:puppet_config_path]
|
260
|
-
end
|
261
|
-
|
262
|
-
def puppet_debian_version
|
263
|
-
config[:puppet_version] ? "=#{config[:puppet_version]}" : nil
|
264
|
-
end
|
265
|
-
|
266
|
-
def facter_debian_version
|
267
|
-
config[:facter_version] ? "=#{config[:facter_version]}" : nil
|
268
|
-
end
|
269
|
-
|
270
|
-
def puppet_redhat_version
|
271
|
-
if puppet_platform == 'amazon'
|
272
|
-
config[:puppet_version]
|
273
|
-
else
|
274
|
-
config[:puppet_version] ? "-#{config[:puppet_version]}" : nil
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
def puppet_noop_flag
|
279
|
-
config[:puppet_noop] ? '--noop' : nil
|
280
|
-
end
|
281
|
-
|
282
|
-
def puppet_debug_flag
|
283
|
-
config[:puppet_debug] ? '-d' : nil
|
284
|
-
end
|
285
|
-
|
286
|
-
def puppet_verbose_flag
|
287
|
-
config[:puppet_verbose] ? '-v' : nil
|
288
|
-
end
|
289
|
-
|
290
|
-
def puppet_platform
|
291
|
-
config[:puppet_platform].to_s.downcase
|
292
|
-
end
|
293
|
-
|
294
|
-
def update_packages_debian_cmd
|
295
|
-
config[:update_package_repos] ? "#{sudo_env('apt-get')} update" : nil
|
296
|
-
end
|
297
|
-
|
298
|
-
def update_packages_redhat_cmd
|
299
|
-
config[:update_package_repos] ? "#{sudo_env('yum')} makecache" : nil
|
300
|
-
end
|
301
|
-
|
302
|
-
def sudo_env(pm)
|
303
|
-
s = https_proxy ? "https_proxy=#{https_proxy}" : nil
|
304
|
-
p = http_proxy ? "http_proxy=#{http_proxy}" : nil
|
305
|
-
n = no_proxy ? "no_proxy=#{no_proxy}" : nil
|
306
|
-
p || s ? "#{sudo('env')} #{p} #{s} #{n} #{pm}" : sudo(pm).to_s
|
307
|
-
end
|
308
|
-
|
309
|
-
def custom_facts
|
310
|
-
return nil if config[:custom_facts].none?
|
311
|
-
bash_vars = config[:custom_facts].map { |k, v| "FACTER_#{k}=#{v}" }.join(' ')
|
312
|
-
bash_vars = "export #{bash_vars};"
|
313
|
-
debug(bash_vars)
|
314
|
-
bash_vars
|
315
|
-
end
|
316
|
-
|
317
|
-
def puppet_server_flag
|
318
|
-
config[:puppet_server] ? "--server=#{config[:puppet_server]}" : nil
|
319
|
-
end
|
320
|
-
|
321
|
-
def puppet_masterport_flag
|
322
|
-
config[:puppet_masterport] ? "--masterport=#{config[:puppet_masterport]}" : nil
|
323
|
-
end
|
324
|
-
|
325
|
-
def puppet_detailed_exitcodes_flag
|
326
|
-
config[:puppet_detailed_exitcodes] ? '--detailed-exitcodes' : nil
|
327
|
-
end
|
328
|
-
|
329
|
-
def puppet_logdest_flag
|
330
|
-
config[:puppet_logdest] ? "--logdest=#{config[:puppet_logdest]}" : nil
|
331
|
-
end
|
332
|
-
|
333
|
-
def puppet_test_flag
|
334
|
-
config[:puppet_test] ? '--test' : nil
|
335
|
-
end
|
336
|
-
|
337
|
-
def puppet_onetime_flag
|
338
|
-
config[:puppet_onetime] ? '--onetime' : nil
|
339
|
-
end
|
340
|
-
|
341
|
-
def puppet_no_daemonize_flag
|
342
|
-
config[:puppet_no_daemonize] ? '--no-daemonize' : nil
|
343
|
-
end
|
344
|
-
|
345
|
-
def puppet_no_daemonize
|
346
|
-
config[:puppet_no_daemonize]
|
347
|
-
end
|
348
|
-
|
349
|
-
def puppet_server
|
350
|
-
config[:puppet_server]
|
351
|
-
end
|
352
|
-
|
353
|
-
def puppet_certname_flag
|
354
|
-
config[:puppet_certname] ? "--certname=#{config[:puppet_certname]}" : nil
|
355
|
-
end
|
356
|
-
|
357
|
-
def puppet_digest_flag
|
358
|
-
config[:puppet_digest] ? "--digest=#{config[:puppet_digest]}" : nil
|
359
|
-
end
|
360
|
-
|
361
|
-
def puppet_apt_repo
|
362
|
-
config[:puppet_apt_repo]
|
363
|
-
end
|
364
|
-
|
365
|
-
def puppet_apt_repo_file
|
366
|
-
config[:puppet_apt_repo].split('/').last
|
367
|
-
end
|
368
|
-
|
369
|
-
def puppet_yum_repo
|
370
|
-
config[:puppet_yum_repo]
|
371
|
-
end
|
372
|
-
|
373
|
-
def proxy_parm
|
374
|
-
http_proxy ? "--httpproxy #{URI.parse(http_proxy).host.downcase} --httpport #{URI.parse(http_proxy).port} " : nil
|
375
|
-
end
|
376
|
-
|
377
|
-
def gem_proxy_parm
|
378
|
-
p = http_proxy ? "--http-proxy #{http_proxy}" : nil
|
379
|
-
n = no_proxy ? "--no-http-proxy #{no_proxy}" : nil
|
380
|
-
p ? "#{p} #{n}" : nil
|
381
|
-
end
|
382
|
-
|
383
|
-
def wget_proxy_parm
|
384
|
-
s = https_proxy ? "-e https_proxy=#{https_proxy}" : nil
|
385
|
-
p = http_proxy ? "-e http_proxy=#{http_proxy}" : nil
|
386
|
-
n = no_proxy ? "-e no_proxy=#{no_proxy}" : nil
|
387
|
-
p || s ? "-e use_proxy=yes #{p} #{s} #{n}" : nil
|
388
|
-
end
|
389
|
-
|
390
|
-
def http_proxy
|
391
|
-
config[:http_proxy]
|
392
|
-
end
|
393
|
-
|
394
|
-
def https_proxy
|
395
|
-
config[:https_proxy]
|
396
|
-
end
|
397
|
-
|
398
|
-
def no_proxy
|
399
|
-
config[:no_proxy]
|
400
|
-
end
|
401
|
-
|
402
|
-
def powershell?
|
403
|
-
powershell_shell? || !(puppet_platform =~ /^windows.*/).nil?
|
404
|
-
end
|
405
|
-
|
406
|
-
def puppet_whitelist_exit_code
|
407
|
-
if config[:puppet_whitelist_exit_code].nil?
|
408
|
-
powershell? ? '; exit $LASTEXITCODE' : nil
|
409
|
-
elsif powershell?
|
410
|
-
"; if(@(#{[config[:puppet_whitelist_exit_code]].join(', ')}) -contains $LASTEXITCODE) {exit 0} else {exit $LASTEXITCODE}"
|
411
|
-
else
|
412
|
-
'; RC=$?; [ ' + [config[:puppet_whitelist_exit_code]].flatten.map { |x| "\$RC -eq #{x}" }.join(' -o ') + ' ] && exit 0; exit $RC'
|
413
|
-
end
|
414
|
-
end
|
415
|
-
|
416
|
-
def chef_url
|
417
|
-
config[:chef_bootstrap_url]
|
418
|
-
end
|
419
|
-
|
420
|
-
def prepare_puppet_config
|
421
|
-
return unless puppet_config
|
422
|
-
|
423
|
-
info('Preparing puppet.conf')
|
424
|
-
debug("Using puppet config from #{puppet_config}")
|
425
|
-
|
426
|
-
FileUtils.cp_r(puppet_config, File.join(sandbox_path, 'puppet.conf'))
|
427
|
-
end
|
428
|
-
end
|
429
|
-
end
|
430
|
-
end
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
#
|
4
|
+
# Author:: Chris Lundquist (<chris.lundquist@github.com>) Neill Turner (<neillwturner@gmail.com>)
|
5
|
+
#
|
6
|
+
# Copyright (C) 2013,2014 Chris Lundquist, 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
|
+
# See https://github.com/neillturner/kitchen-puppet/blob/master/provisioner_options.md
|
21
|
+
# for documentation configuration parameters with puppet_agent provisioner.
|
22
|
+
#
|
23
|
+
|
24
|
+
require 'json'
|
25
|
+
require 'kitchen'
|
26
|
+
require 'kitchen/provisioner/base'
|
27
|
+
require 'kitchen/provisioner/puppet/librarian'
|
28
|
+
|
29
|
+
module Kitchen
|
30
|
+
class Busser
|
31
|
+
def non_suite_dirs
|
32
|
+
%w[data data_bags environments nodes roles puppet]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
module Provisioner
|
37
|
+
#
|
38
|
+
# Puppet Agent provisioner.
|
39
|
+
#
|
40
|
+
class PuppetAgent < Base
|
41
|
+
attr_accessor :tmp_dir
|
42
|
+
|
43
|
+
default_config :require_puppet_omnibus, false
|
44
|
+
# TODO: use something like https://github.com/fnichol/omnibus-puppet
|
45
|
+
default_config :puppet_omnibus_url, nil
|
46
|
+
default_config :puppet_environment, nil
|
47
|
+
default_config :puppet_omnibus_remote_path, '/opt/puppet'
|
48
|
+
default_config :puppet_version, nil
|
49
|
+
default_config :facter_version, nil
|
50
|
+
default_config :require_puppet_repo, true
|
51
|
+
default_config :require_chef_for_busser, true
|
52
|
+
|
53
|
+
default_config :puppet_apt_repo, 'http://apt.puppetlabs.com/puppetlabs-release-precise.deb'
|
54
|
+
default_config :puppet_yum_repo, 'https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm'
|
55
|
+
default_config :chef_bootstrap_url, 'https://www.chef.io/chef/install.sh'
|
56
|
+
|
57
|
+
default_config :puppet_agent_command, nil
|
58
|
+
|
59
|
+
default_config :http_proxy, nil
|
60
|
+
default_config :https_proxy, nil
|
61
|
+
default_config :no_proxy, nil
|
62
|
+
default_config :puppet_whitelist_exit_code, nil
|
63
|
+
|
64
|
+
default_config :puppet_config_path do |provisioner|
|
65
|
+
provisioner.calculate_path('puppet.conf', :file)
|
66
|
+
end
|
67
|
+
|
68
|
+
default_config :puppet_debug, false
|
69
|
+
default_config :puppet_verbose, false
|
70
|
+
default_config :puppet_noop, false
|
71
|
+
default_config :puppet_platform, ''
|
72
|
+
default_config :update_package_repos, true
|
73
|
+
|
74
|
+
default_config :custom_facts, {}
|
75
|
+
|
76
|
+
default_config :puppet_detailed_exitcodes, nil
|
77
|
+
default_config :puppet_logdest, nil
|
78
|
+
default_config :puppet_masterport, nil
|
79
|
+
default_config :puppet_test, false
|
80
|
+
default_config :puppet_onetime, true
|
81
|
+
default_config :puppet_no_daemonize, true
|
82
|
+
# will default to 'puppet'
|
83
|
+
default_config :puppet_server, nil
|
84
|
+
default_config :puppet_waitforcert, '0'
|
85
|
+
default_config :puppet_certname, nil
|
86
|
+
default_config :puppet_digest, nil
|
87
|
+
|
88
|
+
def calculate_path(path, type = :directory)
|
89
|
+
base = config[:test_base_path]
|
90
|
+
candidates = []
|
91
|
+
candidates << File.join(base, instance.suite.name, 'puppet', path)
|
92
|
+
candidates << File.join(base, instance.suite.name, path)
|
93
|
+
candidates << File.join(base, path)
|
94
|
+
candidates << File.join(Dir.pwd, path)
|
95
|
+
|
96
|
+
candidates.find do |c|
|
97
|
+
type == :directory ? File.directory?(c) : File.file?(c)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
102
|
+
def install_command
|
103
|
+
return unless config[:require_puppet_omnibus] || config[:require_puppet_repo]
|
104
|
+
if config[:require_puppet_omnibus]
|
105
|
+
info('Installing puppet using puppet omnibus')
|
106
|
+
version = ''
|
107
|
+
version = "-v #{config[:puppet_version]}" if config[:puppet_version]
|
108
|
+
<<-INSTALL
|
109
|
+
#{Util.shell_helpers}
|
110
|
+
|
111
|
+
if [ ! -d "#{config[:puppet_omnibus_remote_path]}" ]; then
|
112
|
+
echo "-----> Installing Puppet Omnibus"
|
113
|
+
do_download #{config[:puppet_omnibus_url]} /tmp/puppet_install.sh
|
114
|
+
#{sudo('sh')} /tmp/puppet_install.sh #{version}
|
115
|
+
fi
|
116
|
+
#{install_busser}
|
117
|
+
INSTALL
|
118
|
+
else
|
119
|
+
case puppet_platform
|
120
|
+
when 'debian', 'ubuntu'
|
121
|
+
info("Installing puppet on #{puppet_platform}")
|
122
|
+
<<-INSTALL
|
123
|
+
if [ ! $(which puppet) ]; then
|
124
|
+
#{sudo('apt-get')} -y install wget
|
125
|
+
#{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
|
126
|
+
#{sudo('dpkg')} -i #{puppet_apt_repo_file}
|
127
|
+
#{update_packages_debian_cmd}
|
128
|
+
#{sudo_env('apt-get')} -y install facter#{facter_debian_version}
|
129
|
+
#{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
|
130
|
+
#{sudo('apt-get')} -y install puppet#{puppet_debian_version}
|
131
|
+
fi
|
132
|
+
#{install_busser}
|
133
|
+
INSTALL
|
134
|
+
when 'redhat', 'centos', 'fedora', 'oracle', 'amazon'
|
135
|
+
info("Installing puppet on #{puppet_platform}")
|
136
|
+
<<-INSTALL
|
137
|
+
if [ ! $(which puppet) ]; then
|
138
|
+
#{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
|
139
|
+
#{update_packages_redhat_cmd}
|
140
|
+
#{sudo('yum')} -y install puppet#{puppet_redhat_version}
|
141
|
+
fi
|
142
|
+
#{install_busser}
|
143
|
+
INSTALL
|
144
|
+
else
|
145
|
+
info('Installing puppet, will try to determine platform os')
|
146
|
+
<<-INSTALL
|
147
|
+
if [ ! $(which puppet) ]; then
|
148
|
+
if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
|
149
|
+
#{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
|
150
|
+
#{update_packages_redhat_cmd}
|
151
|
+
#{sudo('yum')} -y install puppet#{puppet_redhat_version}
|
152
|
+
else
|
153
|
+
if [ -f /etc/system-release ] || grep -q 'Amazon Linux' /etc/system-release; then
|
154
|
+
#{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
|
155
|
+
#{update_packages_redhat_cmd}
|
156
|
+
#{sudo('yum')} -y install puppet#{puppet_redhat_version}
|
157
|
+
else
|
158
|
+
#{sudo('apt-get')} -y install wget
|
159
|
+
#{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
|
160
|
+
#{sudo('dpkg')} -i #{puppet_apt_repo_file}
|
161
|
+
#{update_packages_debian_cmd}
|
162
|
+
#{sudo('apt-get')} -y install facter#{facter_debian_version}
|
163
|
+
#{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
|
164
|
+
#{sudo('apt-get')} -y install puppet#{puppet_debian_version}
|
165
|
+
fi
|
166
|
+
fi
|
167
|
+
fi
|
168
|
+
#{install_busser}
|
169
|
+
INSTALL
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
174
|
+
|
175
|
+
def install_busser
|
176
|
+
return unless config[:require_chef_for_busser]
|
177
|
+
<<-INSTALL
|
178
|
+
#{Util.shell_helpers}
|
179
|
+
# install chef omnibus so that busser works as this is needed to run tests :(
|
180
|
+
# TODO: work out how to install enough ruby
|
181
|
+
# and set busser: { :ruby_bindir => '/usr/bin/ruby' } so that we dont need the
|
182
|
+
# whole chef client
|
183
|
+
if [ ! -d "/opt/chef" ]
|
184
|
+
then
|
185
|
+
echo "-----> Installing Chef Omnibus to install busser to run tests"
|
186
|
+
do_download #{chef_url} /tmp/install.sh
|
187
|
+
#{sudo('sh')} /tmp/install.sh
|
188
|
+
fi
|
189
|
+
INSTALL
|
190
|
+
end
|
191
|
+
|
192
|
+
def init_command; end
|
193
|
+
|
194
|
+
def create_sandbox
|
195
|
+
super
|
196
|
+
debug("Creating local sandbox in #{sandbox_path}")
|
197
|
+
|
198
|
+
yield if block_given?
|
199
|
+
|
200
|
+
prepare_puppet_config
|
201
|
+
info('Finished Preparing files for transfer')
|
202
|
+
end
|
203
|
+
|
204
|
+
def cleanup_sandbox
|
205
|
+
return if sandbox_path.nil?
|
206
|
+
debug("Cleaning up local sandbox in #{sandbox_path}")
|
207
|
+
FileUtils.rmtree(sandbox_path)
|
208
|
+
end
|
209
|
+
|
210
|
+
def prepare_command
|
211
|
+
commands = []
|
212
|
+
|
213
|
+
if puppet_config
|
214
|
+
commands << [
|
215
|
+
sudo('cp'),
|
216
|
+
File.join(config[:root_path], 'puppet.conf'),
|
217
|
+
'/etc/puppet'
|
218
|
+
].join(' ')
|
219
|
+
end
|
220
|
+
|
221
|
+
command = commands.join(' && ')
|
222
|
+
debug(command)
|
223
|
+
command
|
224
|
+
end
|
225
|
+
|
226
|
+
def run_command
|
227
|
+
return config[:puppet_agent_command] unless config[:puppet_agent_command].nil?
|
228
|
+
[
|
229
|
+
custom_facts,
|
230
|
+
sudo_env('puppet'),
|
231
|
+
'agent',
|
232
|
+
puppet_server_flag,
|
233
|
+
"--waitforcert=#{config[:puppet_waitforcert]}",
|
234
|
+
puppet_masterport_flag,
|
235
|
+
puppet_certname_flag,
|
236
|
+
puppet_digest_flag,
|
237
|
+
puppet_detailed_exitcodes_flag,
|
238
|
+
puppet_logdest_flag,
|
239
|
+
puppet_test_flag,
|
240
|
+
puppet_onetime_flag,
|
241
|
+
puppet_no_daemonize_flag,
|
242
|
+
puppet_noop_flag,
|
243
|
+
puppet_environment_flag,
|
244
|
+
puppet_verbose_flag,
|
245
|
+
puppet_debug_flag,
|
246
|
+
puppet_whitelist_exit_code
|
247
|
+
].compact.join(' ')
|
248
|
+
end
|
249
|
+
|
250
|
+
protected
|
251
|
+
|
252
|
+
def load_needed_dependencies!; end
|
253
|
+
|
254
|
+
def puppet_environment_flag
|
255
|
+
config[:puppet_environment] ? "--environment=\"#{config[:puppet_environment]}\"" : nil
|
256
|
+
end
|
257
|
+
|
258
|
+
def puppet_config
|
259
|
+
config[:puppet_config_path]
|
260
|
+
end
|
261
|
+
|
262
|
+
def puppet_debian_version
|
263
|
+
config[:puppet_version] ? "=#{config[:puppet_version]}" : nil
|
264
|
+
end
|
265
|
+
|
266
|
+
def facter_debian_version
|
267
|
+
config[:facter_version] ? "=#{config[:facter_version]}" : nil
|
268
|
+
end
|
269
|
+
|
270
|
+
def puppet_redhat_version
|
271
|
+
if puppet_platform == 'amazon'
|
272
|
+
config[:puppet_version]
|
273
|
+
else
|
274
|
+
config[:puppet_version] ? "-#{config[:puppet_version]}" : nil
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
def puppet_noop_flag
|
279
|
+
config[:puppet_noop] ? '--noop' : nil
|
280
|
+
end
|
281
|
+
|
282
|
+
def puppet_debug_flag
|
283
|
+
config[:puppet_debug] ? '-d' : nil
|
284
|
+
end
|
285
|
+
|
286
|
+
def puppet_verbose_flag
|
287
|
+
config[:puppet_verbose] ? '-v' : nil
|
288
|
+
end
|
289
|
+
|
290
|
+
def puppet_platform
|
291
|
+
config[:puppet_platform].to_s.downcase
|
292
|
+
end
|
293
|
+
|
294
|
+
def update_packages_debian_cmd
|
295
|
+
config[:update_package_repos] ? "#{sudo_env('apt-get')} update" : nil
|
296
|
+
end
|
297
|
+
|
298
|
+
def update_packages_redhat_cmd
|
299
|
+
config[:update_package_repos] ? "#{sudo_env('yum')} makecache" : nil
|
300
|
+
end
|
301
|
+
|
302
|
+
def sudo_env(pm)
|
303
|
+
s = https_proxy ? "https_proxy=#{https_proxy}" : nil
|
304
|
+
p = http_proxy ? "http_proxy=#{http_proxy}" : nil
|
305
|
+
n = no_proxy ? "no_proxy=#{no_proxy}" : nil
|
306
|
+
p || s ? "#{sudo('env')} #{p} #{s} #{n} #{pm}" : sudo(pm).to_s
|
307
|
+
end
|
308
|
+
|
309
|
+
def custom_facts
|
310
|
+
return nil if config[:custom_facts].none?
|
311
|
+
bash_vars = config[:custom_facts].map { |k, v| "FACTER_#{k}=#{v}" }.join(' ')
|
312
|
+
bash_vars = "export #{bash_vars};"
|
313
|
+
debug(bash_vars)
|
314
|
+
bash_vars
|
315
|
+
end
|
316
|
+
|
317
|
+
def puppet_server_flag
|
318
|
+
config[:puppet_server] ? "--server=#{config[:puppet_server]}" : nil
|
319
|
+
end
|
320
|
+
|
321
|
+
def puppet_masterport_flag
|
322
|
+
config[:puppet_masterport] ? "--masterport=#{config[:puppet_masterport]}" : nil
|
323
|
+
end
|
324
|
+
|
325
|
+
def puppet_detailed_exitcodes_flag
|
326
|
+
config[:puppet_detailed_exitcodes] ? '--detailed-exitcodes' : nil
|
327
|
+
end
|
328
|
+
|
329
|
+
def puppet_logdest_flag
|
330
|
+
config[:puppet_logdest] ? "--logdest=#{config[:puppet_logdest]}" : nil
|
331
|
+
end
|
332
|
+
|
333
|
+
def puppet_test_flag
|
334
|
+
config[:puppet_test] ? '--test' : nil
|
335
|
+
end
|
336
|
+
|
337
|
+
def puppet_onetime_flag
|
338
|
+
config[:puppet_onetime] ? '--onetime' : nil
|
339
|
+
end
|
340
|
+
|
341
|
+
def puppet_no_daemonize_flag
|
342
|
+
config[:puppet_no_daemonize] ? '--no-daemonize' : nil
|
343
|
+
end
|
344
|
+
|
345
|
+
def puppet_no_daemonize
|
346
|
+
config[:puppet_no_daemonize]
|
347
|
+
end
|
348
|
+
|
349
|
+
def puppet_server
|
350
|
+
config[:puppet_server]
|
351
|
+
end
|
352
|
+
|
353
|
+
def puppet_certname_flag
|
354
|
+
config[:puppet_certname] ? "--certname=#{config[:puppet_certname]}" : nil
|
355
|
+
end
|
356
|
+
|
357
|
+
def puppet_digest_flag
|
358
|
+
config[:puppet_digest] ? "--digest=#{config[:puppet_digest]}" : nil
|
359
|
+
end
|
360
|
+
|
361
|
+
def puppet_apt_repo
|
362
|
+
config[:puppet_apt_repo]
|
363
|
+
end
|
364
|
+
|
365
|
+
def puppet_apt_repo_file
|
366
|
+
config[:puppet_apt_repo].split('/').last
|
367
|
+
end
|
368
|
+
|
369
|
+
def puppet_yum_repo
|
370
|
+
config[:puppet_yum_repo]
|
371
|
+
end
|
372
|
+
|
373
|
+
def proxy_parm
|
374
|
+
http_proxy ? "--httpproxy #{URI.parse(http_proxy).host.downcase} --httpport #{URI.parse(http_proxy).port} " : nil
|
375
|
+
end
|
376
|
+
|
377
|
+
def gem_proxy_parm
|
378
|
+
p = http_proxy ? "--http-proxy #{http_proxy}" : nil
|
379
|
+
n = no_proxy ? "--no-http-proxy #{no_proxy}" : nil
|
380
|
+
p ? "#{p} #{n}" : nil
|
381
|
+
end
|
382
|
+
|
383
|
+
def wget_proxy_parm
|
384
|
+
s = https_proxy ? "-e https_proxy=#{https_proxy}" : nil
|
385
|
+
p = http_proxy ? "-e http_proxy=#{http_proxy}" : nil
|
386
|
+
n = no_proxy ? "-e no_proxy=#{no_proxy}" : nil
|
387
|
+
p || s ? "-e use_proxy=yes #{p} #{s} #{n}" : nil
|
388
|
+
end
|
389
|
+
|
390
|
+
def http_proxy
|
391
|
+
config[:http_proxy]
|
392
|
+
end
|
393
|
+
|
394
|
+
def https_proxy
|
395
|
+
config[:https_proxy]
|
396
|
+
end
|
397
|
+
|
398
|
+
def no_proxy
|
399
|
+
config[:no_proxy]
|
400
|
+
end
|
401
|
+
|
402
|
+
def powershell?
|
403
|
+
powershell_shell? || !(puppet_platform =~ /^windows.*/).nil?
|
404
|
+
end
|
405
|
+
|
406
|
+
def puppet_whitelist_exit_code
|
407
|
+
if config[:puppet_whitelist_exit_code].nil?
|
408
|
+
powershell? ? '; exit $LASTEXITCODE' : nil
|
409
|
+
elsif powershell?
|
410
|
+
"; if(@(#{[config[:puppet_whitelist_exit_code]].join(', ')}) -contains $LASTEXITCODE) {exit 0} else {exit $LASTEXITCODE}"
|
411
|
+
else
|
412
|
+
'; RC=$?; [ ' + [config[:puppet_whitelist_exit_code]].flatten.map { |x| "\$RC -eq #{x}" }.join(' -o ') + ' ] && exit 0; exit $RC'
|
413
|
+
end
|
414
|
+
end
|
415
|
+
|
416
|
+
def chef_url
|
417
|
+
config[:chef_bootstrap_url]
|
418
|
+
end
|
419
|
+
|
420
|
+
def prepare_puppet_config
|
421
|
+
return unless puppet_config
|
422
|
+
|
423
|
+
info('Preparing puppet.conf')
|
424
|
+
debug("Using puppet config from #{puppet_config}")
|
425
|
+
|
426
|
+
FileUtils.cp_r(puppet_config, File.join(sandbox_path, 'puppet.conf'))
|
427
|
+
end
|
428
|
+
end
|
429
|
+
end
|
430
|
+
end
|