dopi 0.17.0 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/Gemfile +5 -1
- data/Gemfile.lock +29 -27
- data/Vagrantfile +2 -2
- data/dopi.gemspec +2 -2
- data/lib/dopi.rb +1 -0
- data/lib/dopi/command.rb +10 -1
- data/lib/dopi/command/ssh/puppet_agent_run.rb +11 -35
- data/lib/dopi/command/winrm/puppet_agent_run.rb +17 -32
- data/lib/dopi/command_parser/puppet_run.rb +149 -0
- data/lib/dopi/connector/winrm.rb +36 -32
- data/lib/dopi/version.rb +1 -1
- data/spec/fixtures/puppet/manifests/site.pp +5 -0
- data/spec/fixtures/testenv_plan.yaml +61 -2
- metadata +9 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 76172f4760eaf3ed0a244457346f69b44901e51a
|
|
4
|
+
data.tar.gz: 22e167ba7260b906a39cd3114056b8b6b2f6c5c0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e3b32d4ab26d002dc7d6bf90ec174dd6ed39682000919e4d6cdf6024968cc419e6df7563e5cc9590cbc1cdc0680dcb7f697f720f2285e47cd859329f845e0742
|
|
7
|
+
data.tar.gz: d18f82635f8fe8097b5ef3cb6b7393d0054c12a01bc390ee5c84d4177d5deb2490f95fa83bb8224d5af78faeb5b7d9c50c808b73210e35b01668b7b68c544a0c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
All notable changes to DOPi will be documented in this file.
|
|
3
3
|
|
|
4
|
+
## [0.18.1] - 2017-05-24
|
|
5
|
+
### Fixed
|
|
6
|
+
- Update dependencies
|
|
7
|
+
|
|
8
|
+
## [0.18.0] - 2017-05-24
|
|
9
|
+
### Changed
|
|
10
|
+
- Updated the winrm gem to version 2 and migrated the connector to use the new interface
|
|
11
|
+
- The puppet_agent_run plugin for ssh and winrm got an update. It is now possible to configure
|
|
12
|
+
reruns if there are changes or errors. For more details see the plugin documentation.
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
- Winrm now closes the connections correctly.
|
|
16
|
+
|
|
4
17
|
## [0.17.0] - 2017-03-28
|
|
5
18
|
### Added
|
|
6
19
|
- The log format of the trace output now uses the formatter from dopv which is now in dop_common
|
data/Gemfile
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
source 'https://rubygems.org'
|
|
2
2
|
|
|
3
3
|
# Use local path as source for dop_common for testing
|
|
4
|
-
#
|
|
4
|
+
#gem 'dop_common', :path => '../dop_common'
|
|
5
|
+
|
|
6
|
+
# There are problems with the hiera puppetlabs RPM, so we can't really
|
|
7
|
+
# depend on the hiera gem in the spec file. Make sure this is installed
|
|
8
|
+
gem 'hiera'
|
|
5
9
|
|
|
6
10
|
# Specify your gem's dependencies in dopi.gemspec
|
|
7
11
|
gemspec
|
data/Gemfile.lock
CHANGED
|
@@ -1,90 +1,91 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
dopi (0.
|
|
4
|
+
dopi (0.18.0)
|
|
5
5
|
curses (~> 1)
|
|
6
|
-
dop_common (~> 0.
|
|
6
|
+
dop_common (~> 0.15, >= 0.15.0)
|
|
7
7
|
gli (~> 2)
|
|
8
8
|
logger-colors (~> 1)
|
|
9
9
|
mcollective-client (~> 2)
|
|
10
10
|
parallel (~> 1)
|
|
11
|
-
winrm (~>
|
|
11
|
+
winrm (~> 2)
|
|
12
12
|
|
|
13
13
|
GEM
|
|
14
14
|
remote: https://rubygems.org/
|
|
15
15
|
specs:
|
|
16
16
|
builder (3.2.3)
|
|
17
|
-
curses (1.2.
|
|
17
|
+
curses (1.2.2)
|
|
18
18
|
diff-lcs (1.3)
|
|
19
19
|
docile (1.1.5)
|
|
20
|
-
dop_common (0.
|
|
20
|
+
dop_common (0.15.0)
|
|
21
21
|
hashdiff (~> 0.3, >= 0.3.1)
|
|
22
|
-
hiera (~> 3)
|
|
23
22
|
lockfile (~> 2)
|
|
24
23
|
rb-inotify (~> 0.9)
|
|
24
|
+
erubis (2.7.0)
|
|
25
25
|
ffi (1.9.18)
|
|
26
26
|
gli (2.16.0)
|
|
27
27
|
gssapi (1.2.0)
|
|
28
28
|
ffi (>= 1.0.1)
|
|
29
29
|
gyoku (1.3.1)
|
|
30
30
|
builder (>= 2.1.2)
|
|
31
|
-
hashdiff (0.3.
|
|
31
|
+
hashdiff (0.3.4)
|
|
32
32
|
hiera (3.3.1)
|
|
33
33
|
httpclient (2.8.3)
|
|
34
|
-
json (2.0
|
|
34
|
+
json (2.1.0)
|
|
35
35
|
little-plugger (1.1.4)
|
|
36
36
|
lockfile (2.1.3)
|
|
37
37
|
logger-colors (1.0.0)
|
|
38
|
-
logging (2.2.
|
|
38
|
+
logging (2.2.2)
|
|
39
39
|
little-plugger (~> 1.1)
|
|
40
40
|
multi_json (~> 1.10)
|
|
41
|
-
mcollective-client (2.10.
|
|
41
|
+
mcollective-client (2.10.4)
|
|
42
42
|
json
|
|
43
43
|
stomp
|
|
44
44
|
systemu
|
|
45
45
|
mixlib-shellout (2.2.7)
|
|
46
46
|
multi_json (1.12.1)
|
|
47
47
|
nori (2.6.0)
|
|
48
|
-
parallel (1.11.
|
|
48
|
+
parallel (1.11.2)
|
|
49
49
|
rake (12.0.0)
|
|
50
50
|
rb-inotify (0.9.8)
|
|
51
51
|
ffi (>= 0.5.0)
|
|
52
|
-
rspec (3.
|
|
53
|
-
rspec-core (~> 3.
|
|
54
|
-
rspec-expectations (~> 3.
|
|
55
|
-
rspec-mocks (~> 3.
|
|
56
|
-
rspec-command (1.0.
|
|
52
|
+
rspec (3.6.0)
|
|
53
|
+
rspec-core (~> 3.6.0)
|
|
54
|
+
rspec-expectations (~> 3.6.0)
|
|
55
|
+
rspec-mocks (~> 3.6.0)
|
|
56
|
+
rspec-command (1.0.3)
|
|
57
57
|
mixlib-shellout (~> 2.0)
|
|
58
58
|
rspec (~> 3.2)
|
|
59
59
|
rspec-its (~> 1.2)
|
|
60
|
-
rspec-core (3.
|
|
61
|
-
rspec-support (~> 3.
|
|
62
|
-
rspec-expectations (3.
|
|
60
|
+
rspec-core (3.6.0)
|
|
61
|
+
rspec-support (~> 3.6.0)
|
|
62
|
+
rspec-expectations (3.6.0)
|
|
63
63
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
64
|
-
rspec-support (~> 3.
|
|
64
|
+
rspec-support (~> 3.6.0)
|
|
65
65
|
rspec-its (1.2.0)
|
|
66
66
|
rspec-core (>= 3.0.0)
|
|
67
67
|
rspec-expectations (>= 3.0.0)
|
|
68
|
-
rspec-mocks (3.
|
|
68
|
+
rspec-mocks (3.6.0)
|
|
69
69
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
70
|
-
rspec-support (~> 3.
|
|
71
|
-
rspec-support (3.
|
|
72
|
-
rubyntlm (0.6.
|
|
70
|
+
rspec-support (~> 3.6.0)
|
|
71
|
+
rspec-support (3.6.0)
|
|
72
|
+
rubyntlm (0.6.2)
|
|
73
73
|
simplecov (0.14.1)
|
|
74
74
|
docile (~> 1.1.0)
|
|
75
75
|
json (>= 1.8, < 3)
|
|
76
76
|
simplecov-html (~> 0.10.0)
|
|
77
|
-
simplecov-html (0.10.
|
|
77
|
+
simplecov-html (0.10.1)
|
|
78
78
|
stomp (1.4.3)
|
|
79
79
|
systemu (2.6.5)
|
|
80
|
-
winrm (
|
|
80
|
+
winrm (2.2.3)
|
|
81
81
|
builder (>= 2.1.2)
|
|
82
|
+
erubis (~> 2.7)
|
|
82
83
|
gssapi (~> 1.2)
|
|
83
84
|
gyoku (~> 1.0)
|
|
84
85
|
httpclient (~> 2.2, >= 2.2.0.2)
|
|
85
86
|
logging (>= 1.6.1, < 3.0)
|
|
86
87
|
nori (~> 2.0)
|
|
87
|
-
rubyntlm (~> 0.6.0)
|
|
88
|
+
rubyntlm (~> 0.6.0, >= 0.6.1)
|
|
88
89
|
|
|
89
90
|
PLATFORMS
|
|
90
91
|
ruby
|
|
@@ -92,6 +93,7 @@ PLATFORMS
|
|
|
92
93
|
DEPENDENCIES
|
|
93
94
|
bundler (~> 1.3)
|
|
94
95
|
dopi!
|
|
96
|
+
hiera
|
|
95
97
|
rake
|
|
96
98
|
rspec
|
|
97
99
|
rspec-command
|
data/Vagrantfile
CHANGED
|
@@ -35,9 +35,9 @@ Vagrant.configure(2) do |config|
|
|
|
35
35
|
# disable the default folder sync on the nodes
|
|
36
36
|
# and rsync all the stuff to the puppetmaster
|
|
37
37
|
if node.name == 'puppetmaster.example.com'
|
|
38
|
-
|
|
38
|
+
machine.vm.synced_folder ".", "/vagrant", type: "rsync", rsync__exclude: ".bundle/"
|
|
39
39
|
else
|
|
40
|
-
|
|
40
|
+
machine.vm.synced_folder ".", "/vagrant", disabled: true
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
end
|
data/dopi.gemspec
CHANGED
|
@@ -28,11 +28,11 @@ Gem::Specification.new do |spec|
|
|
|
28
28
|
# Code quality
|
|
29
29
|
spec.add_development_dependency 'simplecov'
|
|
30
30
|
|
|
31
|
-
spec.add_runtime_dependency 'dop_common', '~> 0.
|
|
31
|
+
spec.add_runtime_dependency 'dop_common', '~> 0.15', '>= 0.15.0'
|
|
32
32
|
spec.add_runtime_dependency 'gli', '~> 2'
|
|
33
33
|
spec.add_runtime_dependency 'logger-colors', '~> 1'
|
|
34
34
|
spec.add_runtime_dependency 'mcollective-client', '~> 2'
|
|
35
|
-
spec.add_runtime_dependency 'winrm', '~>
|
|
35
|
+
spec.add_runtime_dependency 'winrm', '~> 2'
|
|
36
36
|
spec.add_runtime_dependency 'parallel', '~> 1'
|
|
37
37
|
|
|
38
38
|
# curses was removed in ruby 2.1
|
data/lib/dopi.rb
CHANGED
|
@@ -10,6 +10,7 @@ require "dopi/command_parser/arguments"
|
|
|
10
10
|
require "dopi/command_parser/credentials"
|
|
11
11
|
require "dopi/command_parser/exit_code"
|
|
12
12
|
require "dopi/command_parser/output"
|
|
13
|
+
require "dopi/command_parser/puppet_run"
|
|
13
14
|
require "dopi/connector/local"
|
|
14
15
|
require "dopi/connector/ssh"
|
|
15
16
|
require "dopi/connector/winrm"
|
data/lib/dopi/command.rb
CHANGED
|
@@ -96,7 +96,13 @@ module Dopi
|
|
|
96
96
|
log(:info, "#{name} [OK]") if state_done?
|
|
97
97
|
else
|
|
98
98
|
state_fail
|
|
99
|
-
|
|
99
|
+
if @is_verify_command
|
|
100
|
+
log(:info, "#{name} [FAILED]")
|
|
101
|
+
else
|
|
102
|
+
log(:error, "#{name} [FAILED]")
|
|
103
|
+
log_file = @step.plan.context_logger.current_log_file
|
|
104
|
+
log(:error, "Check the log file #{log_file} for the full debug log of the node")
|
|
105
|
+
end
|
|
100
106
|
end
|
|
101
107
|
end
|
|
102
108
|
end
|
|
@@ -110,10 +116,13 @@ module Dopi
|
|
|
110
116
|
send_signal(:abort)
|
|
111
117
|
rescue CommandExecutionError => e
|
|
112
118
|
log(:error, "Command failed: #{e.message}", false)
|
|
119
|
+
log_file = @step.plan.context_logger.current_log_file
|
|
120
|
+
log(:error, "Check the log file #{log_file} for the full debug log of the node", false)
|
|
113
121
|
Dopi.log.error(e) if DopCommon.config.trace
|
|
114
122
|
state_fail unless noop
|
|
115
123
|
rescue => e
|
|
116
124
|
log(:error, "Unexpected error!!! This is a Bug", false)
|
|
125
|
+
Dopi.log.error(e.class)
|
|
117
126
|
Dopi.log.error(e.message)
|
|
118
127
|
Dopi.log.error(e.backtrace)
|
|
119
128
|
state_fail unless noop
|
|
@@ -6,57 +6,33 @@ module Dopi
|
|
|
6
6
|
class Ssh
|
|
7
7
|
class PuppetAgentRun < Dopi::Command
|
|
8
8
|
include Dopi::Connector::Ssh
|
|
9
|
-
include Dopi::CommandParser::
|
|
10
|
-
include Dopi::CommandParser::Arguments
|
|
11
|
-
include Dopi::CommandParser::ExitCode
|
|
12
|
-
include Dopi::CommandParser::Output
|
|
9
|
+
include Dopi::CommandParser::PuppetRun
|
|
13
10
|
|
|
14
11
|
public
|
|
15
|
-
|
|
16
|
-
def initialize(command_parser, step, node, is_verify_command)
|
|
17
|
-
command_parser.overwrite_defaults = { :plugin_timeout => 1800 }
|
|
18
|
-
super(command_parser, step, node, is_verify_command)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
12
|
def validate
|
|
22
13
|
validate_ssh
|
|
23
|
-
|
|
24
|
-
validate_arguments
|
|
25
|
-
validate_exit_code
|
|
26
|
-
validate_output
|
|
14
|
+
validate_puppet_run
|
|
27
15
|
end
|
|
28
16
|
|
|
29
|
-
def
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
check_output(cmd_stderr) &&
|
|
33
|
-
check_exit_code(cmd_exit_code)
|
|
17
|
+
def initialize(command_parser, step, node, is_verify_command)
|
|
18
|
+
command_parser.overwrite_defaults = { :plugin_timeout => 1800 }
|
|
19
|
+
super(command_parser, step, node, is_verify_command)
|
|
34
20
|
end
|
|
35
21
|
|
|
36
|
-
def
|
|
37
|
-
|
|
22
|
+
def puppet_bin
|
|
23
|
+
'/usr/bin/puppet'
|
|
38
24
|
end
|
|
39
25
|
|
|
40
|
-
def
|
|
41
|
-
|
|
26
|
+
def check_run_lock
|
|
27
|
+
ssh_command(env, "test -f $(#{puppet_bin} config print statedir)/agent_catalog_run.lock")
|
|
42
28
|
end
|
|
43
29
|
|
|
44
|
-
def
|
|
45
|
-
{
|
|
46
|
-
'^Error:'
|
|
47
|
-
],
|
|
48
|
-
:warning => [
|
|
49
|
-
'^Warning:'
|
|
50
|
-
]
|
|
51
|
-
}
|
|
30
|
+
def puppet_run
|
|
31
|
+
ssh_command(env, "#{puppet_bin} agent --test --color false #{arguments}")
|
|
52
32
|
end
|
|
53
33
|
|
|
54
34
|
private
|
|
55
35
|
|
|
56
|
-
def command_string
|
|
57
|
-
"puppet agent --test --color false #{arguments}"
|
|
58
|
-
end
|
|
59
|
-
|
|
60
36
|
end
|
|
61
37
|
end
|
|
62
38
|
end
|
|
@@ -1,60 +1,45 @@
|
|
|
1
1
|
#
|
|
2
|
-
#
|
|
2
|
+
# SSH custom command
|
|
3
3
|
#
|
|
4
4
|
module Dopi
|
|
5
5
|
class Command
|
|
6
6
|
class Winrm
|
|
7
7
|
class PuppetAgentRun < Dopi::Command
|
|
8
8
|
include Dopi::Connector::Winrm
|
|
9
|
-
include Dopi::CommandParser::
|
|
10
|
-
include Dopi::CommandParser::ExitCode
|
|
11
|
-
include Dopi::CommandParser::Output
|
|
9
|
+
include Dopi::CommandParser::PuppetRun
|
|
12
10
|
|
|
13
11
|
public
|
|
12
|
+
def validate
|
|
13
|
+
validate_winrm
|
|
14
|
+
validate_puppet_run
|
|
15
|
+
end
|
|
14
16
|
|
|
15
17
|
def initialize(command_parser, step, node, is_verify_command)
|
|
16
18
|
command_parser.overwrite_defaults = { :plugin_timeout => 1800 }
|
|
17
19
|
super(command_parser, step, node, is_verify_command)
|
|
18
20
|
end
|
|
19
21
|
|
|
20
|
-
def
|
|
21
|
-
|
|
22
|
-
validate_arguments
|
|
23
|
-
validate_exit_code
|
|
24
|
-
validate_output
|
|
22
|
+
def puppet_bin
|
|
23
|
+
'puppet'
|
|
25
24
|
end
|
|
26
25
|
|
|
27
|
-
def
|
|
28
|
-
|
|
29
|
-
check_output(cmd_stdout) &&
|
|
30
|
-
check_output(cmd_stderr) &&
|
|
31
|
-
check_exit_code(cmd_exit_code)
|
|
26
|
+
def check_run_lock_b
|
|
27
|
+
false
|
|
32
28
|
end
|
|
33
29
|
|
|
34
|
-
def
|
|
35
|
-
|
|
30
|
+
def check_run_lock
|
|
31
|
+
winrm_powershell_command <<-cmd
|
|
32
|
+
$Statedir = #{puppet_bin} config print statedir
|
|
33
|
+
if(-not( Test-Path "$Statedir/agent_catalog_run.lock" )) { exit 1 }
|
|
34
|
+
cmd
|
|
36
35
|
end
|
|
37
36
|
|
|
38
|
-
def
|
|
39
|
-
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def parse_output_defaults
|
|
43
|
-
{ :error => [
|
|
44
|
-
'^Error:'
|
|
45
|
-
],
|
|
46
|
-
:warning => [
|
|
47
|
-
'^Warning:'
|
|
48
|
-
]
|
|
49
|
-
}
|
|
37
|
+
def puppet_run
|
|
38
|
+
winrm_powershell_command("#{puppet_bin} agent --test --color false #{arguments}")
|
|
50
39
|
end
|
|
51
40
|
|
|
52
41
|
private
|
|
53
42
|
|
|
54
|
-
def command_string
|
|
55
|
-
"puppet agent --test --color false #{arguments}"
|
|
56
|
-
end
|
|
57
|
-
|
|
58
43
|
end
|
|
59
44
|
end
|
|
60
45
|
end
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
#
|
|
2
|
+
# This is a mixin for command plugins that need to parse puppet_run specific
|
|
3
|
+
# options and for some methods to wrap the rerun logic.
|
|
4
|
+
#
|
|
5
|
+
module Dopi
|
|
6
|
+
module CommandParser
|
|
7
|
+
module PuppetRun
|
|
8
|
+
include Dopi::CommandParser::Env
|
|
9
|
+
include Dopi::CommandParser::Arguments
|
|
10
|
+
include Dopi::CommandParser::Output
|
|
11
|
+
|
|
12
|
+
public
|
|
13
|
+
|
|
14
|
+
def validate_puppet_run
|
|
15
|
+
validate_env
|
|
16
|
+
validate_arguments
|
|
17
|
+
validate_output
|
|
18
|
+
log_validation_method('rerun_on_change_valid?', CommandParsingError)
|
|
19
|
+
log_validation_method('rerun_on_error_valid?', CommandParsingError)
|
|
20
|
+
log_validation_method('max_rerun_valid?', CommandParsingError)
|
|
21
|
+
log_validation_method('wait_if_already_running_valid?', CommandParsingError)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def rerun_on_change
|
|
25
|
+
@rerun_on_change ||= rerun_on_change_valid? ? hash[:rerun_on_change] : false
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def rerun_on_error
|
|
29
|
+
@rerun_on_error ||= rerun_on_error_valid? ? hash[:rerun_on_error] : false
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def max_rerun
|
|
33
|
+
@max_rerun ||= max_rerun_valid? ? hash[:max_rerun] : 1
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def wait_if_already_running
|
|
37
|
+
@wait_if_already_running ||= wait_if_already_running_valid? ? hash[:wait_if_already_running] : true
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def run
|
|
41
|
+
runs = 0
|
|
42
|
+
loop do
|
|
43
|
+
raise GracefulExit if signals[:stop]
|
|
44
|
+
if check_run_lock_wrapper
|
|
45
|
+
if wait_if_already_running
|
|
46
|
+
log(:info, "Puppet run already in progress, waiting 10s to check again if finished")
|
|
47
|
+
sleep(10)
|
|
48
|
+
else
|
|
49
|
+
log(:error, "Puppet run already in progress and wait_if_already_running = false")
|
|
50
|
+
return false
|
|
51
|
+
end
|
|
52
|
+
else
|
|
53
|
+
runs += 1
|
|
54
|
+
if runs < 2
|
|
55
|
+
log(:info, "Starting Puppet Run")
|
|
56
|
+
else
|
|
57
|
+
log(:info, "Starting Puppet Rerun #{runs - 1} of #{max_rerun}")
|
|
58
|
+
end
|
|
59
|
+
case puppet_run_wrapper
|
|
60
|
+
when :done then return true
|
|
61
|
+
when :change
|
|
62
|
+
if rerun_on_change
|
|
63
|
+
if runs < 2
|
|
64
|
+
log(:info, "Puppet had changes and rerun_on_change = true")
|
|
65
|
+
else
|
|
66
|
+
log(:warn, "Puppet had still changes after multiple reruns. Please fix your Puppet manifests")
|
|
67
|
+
end
|
|
68
|
+
return true if max_rerun < runs
|
|
69
|
+
else
|
|
70
|
+
return true
|
|
71
|
+
end
|
|
72
|
+
else
|
|
73
|
+
if rerun_on_error
|
|
74
|
+
log(:warn, "Puppet had ERRORS during the run and rerun_on_errors = true. Please fix your Puppet manifests")
|
|
75
|
+
if max_rerun < runs
|
|
76
|
+
log(:error, "Puppet had ERRORS during the run! max_reruns (#{max_rerun}) reached!")
|
|
77
|
+
return false
|
|
78
|
+
end
|
|
79
|
+
else
|
|
80
|
+
return false
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def check_run_lock_wrapper
|
|
88
|
+
cmd_stdout, cmd_stderr, cmd_exitcode = check_run_lock
|
|
89
|
+
return true if cmd_exitcode == 0
|
|
90
|
+
return false
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# puppet run wrapper method
|
|
94
|
+
# this will return :done, :change or :error
|
|
95
|
+
def puppet_run_wrapper
|
|
96
|
+
cmd_stdout, cmd_stderr, cmd_exitcode = puppet_run
|
|
97
|
+
return :error unless (check_output(cmd_stdout) && check_output(cmd_stderr))
|
|
98
|
+
case cmd_exitcode
|
|
99
|
+
when 0 then return :done
|
|
100
|
+
when 2 then return :change
|
|
101
|
+
else return :error
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def parse_output_defaults
|
|
106
|
+
{ :error => [
|
|
107
|
+
'^Error:'
|
|
108
|
+
],
|
|
109
|
+
:warning => [
|
|
110
|
+
'^Warning:'
|
|
111
|
+
]
|
|
112
|
+
}
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
private
|
|
116
|
+
|
|
117
|
+
def rerun_on_change_valid?
|
|
118
|
+
return false unless hash.kind_of?(Hash)
|
|
119
|
+
return false if hash[:rerun_on_change].nil? # is optional
|
|
120
|
+
hash[:rerun_on_change].kind_of?(TrueClass) or hash[:rerun_on_change].kind_of?(FalseClass) or
|
|
121
|
+
raise CommandParsingError, "Plugin #{name}: The value for 'rerun_on_change' must be boolean"
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def rerun_on_error_valid?
|
|
125
|
+
return false unless hash.kind_of?(Hash)
|
|
126
|
+
return false if hash[:rerun_on_error].nil? # is optional
|
|
127
|
+
hash[:rerun_on_error].kind_of?(TrueClass) or hash[:rerun_on_error].kind_of?(FalseClass) or
|
|
128
|
+
raise CommandParsingError, "Plugin #{name}: The value for 'rerun_on_error' must be boolean"
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def max_rerun_valid?
|
|
132
|
+
return false unless hash.kind_of?(Hash)
|
|
133
|
+
return false if hash[:max_rerun].nil? # is optional
|
|
134
|
+
hash[:max_rerun].kind_of?(Fixnum) or
|
|
135
|
+
raise CommandParsingError, "Plugin #{name}: The value for 'max_rerun' has to be a number"
|
|
136
|
+
hash[:max_rerun] > 0 or
|
|
137
|
+
raise CommandParsingError, "Plugin #{name}: The value for 'max_rerun' has to be > 0"
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def wait_if_already_running_valid?
|
|
141
|
+
return false unless hash.kind_of?(Hash)
|
|
142
|
+
return false if hash[:wait_if_already_running].nil? # is optional
|
|
143
|
+
hash[:wait_if_already_running].kind_of?(TrueClass) or hash[:wait_if_already_running].kind_of?(FalseClass) or
|
|
144
|
+
raise CommandParsingError, "Plugin #{name}: The value for 'wait_if_already_running' must be boolean"
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
data/lib/dopi/connector/winrm.rb
CHANGED
|
@@ -18,59 +18,63 @@ module Dopi
|
|
|
18
18
|
validate_credentials
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def winrm_command(command_string)
|
|
21
|
+
def winrm_command(command_string, use_shell = :cmd)
|
|
22
22
|
cmd_stdout = ""
|
|
23
23
|
cmd_stderr = ""
|
|
24
24
|
log(:debug, "Executing '#{command_string}' for command #{name}")
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
winrm.shell(use_shell) do |shell|
|
|
26
|
+
result = shell.run(command_string) do |stdout, stderr|
|
|
27
|
+
unless stdout.nil? or stdout.empty?
|
|
28
|
+
cmd_stdout << stdout
|
|
29
|
+
log(:debug, stdout)
|
|
30
|
+
end
|
|
31
|
+
unless stderr.nil? or stderr.empty?
|
|
32
|
+
cmd_stderr << stderr
|
|
33
|
+
log(:error, stderr)
|
|
34
|
+
end
|
|
33
35
|
end
|
|
36
|
+
return [cmd_stdout, cmd_stderr, result.exitcode]
|
|
34
37
|
end
|
|
35
|
-
winrm.close
|
|
36
|
-
[cmd_stdout, cmd_stderr, result[:exitcode]]
|
|
37
38
|
end
|
|
38
39
|
|
|
39
40
|
def winrm_powershell_command(command_string)
|
|
40
|
-
|
|
41
|
-
script = WinRM::PowershellScript.new(command_string)
|
|
42
|
-
winrm_command("powershell -encodedCommand #{script.encoded()}")
|
|
41
|
+
winrm_command(command_string, :powershell)
|
|
43
42
|
end
|
|
44
43
|
|
|
45
44
|
def winrm
|
|
46
|
-
|
|
45
|
+
working_winrm_connection = nil
|
|
47
46
|
credentials.each do |credential|
|
|
48
47
|
begin
|
|
49
|
-
|
|
50
|
-
endpoint,
|
|
51
|
-
auth_method(credential),
|
|
52
|
-
:realm
|
|
53
|
-
:service
|
|
54
|
-
:keytab
|
|
55
|
-
:user
|
|
56
|
-
:
|
|
57
|
-
:disable_sspi
|
|
58
|
-
:basic_auth_only
|
|
59
|
-
:ca_trust_path
|
|
48
|
+
winrm_connection = WinRM::Connection.new(
|
|
49
|
+
:endpoint => endpoint,
|
|
50
|
+
:transport => auth_method(credential),
|
|
51
|
+
:realm => credential.realm,
|
|
52
|
+
:service => credential.service,
|
|
53
|
+
:keytab => credential.keytab,
|
|
54
|
+
:user => credential.username,
|
|
55
|
+
:password => credential.password,
|
|
56
|
+
:disable_sspi => disable_sspi,
|
|
57
|
+
:basic_auth_only => basic_auth_only,
|
|
58
|
+
:ca_trust_path => ca_trust_path,
|
|
59
|
+
:operation_timeout => operation_timeout,
|
|
60
60
|
)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
winrm_connection.shell(:cmd) do |shell|
|
|
62
|
+
output = shell.run('exit') # test connection
|
|
63
|
+
if output.exitcode == 0
|
|
64
|
+
working_winrm_connection = winrm_connection
|
|
65
|
+
end
|
|
66
|
+
end
|
|
65
67
|
rescue WinRM::WinRMAuthorizationError, GSSAPI::GssApiError => e
|
|
66
68
|
log(:warn, "Unable to login with credential #{credential.name} : #{e.message}")
|
|
67
69
|
rescue SocketError => e
|
|
68
70
|
raise CommandConnectionError,
|
|
69
71
|
"A problem occurred while trying to connect to node #{@node.name} : #{e.message}"
|
|
70
|
-
|
|
72
|
+
rescue WinRM::WinRMWMIError => e
|
|
73
|
+
raise CommandExecutionError,
|
|
74
|
+
"A problem occurred while trying to connect to node #{@node.name} : #{e.message}"
|
|
71
75
|
end
|
|
72
76
|
end
|
|
73
|
-
|
|
77
|
+
working_winrm_connection or
|
|
74
78
|
raise CommandExecutionError,
|
|
75
79
|
"Unable to login with any of the given credentials: #{credentials.map{|c| c.name}.join(', ')}"
|
|
76
80
|
end
|
data/lib/dopi/version.rb
CHANGED
|
@@ -7,6 +7,11 @@ $role = hiera('role')
|
|
|
7
7
|
class base {
|
|
8
8
|
hiera_include('classes')
|
|
9
9
|
|
|
10
|
+
file{'/tmp/testfile':
|
|
11
|
+
ensure => present,
|
|
12
|
+
content => "testdata",
|
|
13
|
+
}
|
|
14
|
+
|
|
10
15
|
file{'/usr/libexec/mcollective/': ensure => directory}
|
|
11
16
|
file{'/usr/libexec/mcollective/mcollective': ensure => directory}
|
|
12
17
|
}
|
|
@@ -34,7 +34,7 @@ steps:
|
|
|
34
34
|
exec: 'rpm'
|
|
35
35
|
arguments: '-ivh https://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm'
|
|
36
36
|
|
|
37
|
-
- name: 'install puppet on all the nodes'
|
|
37
|
+
- name: 'install puppet on all the linux nodes'
|
|
38
38
|
nodes_by_config: {os: 'linux'}
|
|
39
39
|
command:
|
|
40
40
|
verify_commands:
|
|
@@ -44,6 +44,41 @@ steps:
|
|
|
44
44
|
exec: 'yum'
|
|
45
45
|
arguments: 'install -y puppet'
|
|
46
46
|
|
|
47
|
+
- name: 'install puppet on all the linux nodes'
|
|
48
|
+
nodes_by_config: {os: 'linux'}
|
|
49
|
+
command:
|
|
50
|
+
verify_commands:
|
|
51
|
+
- plugin: 'ssh/file_exists'
|
|
52
|
+
file: '/usr/bin/puppet'
|
|
53
|
+
plugin: 'ssh/custom'
|
|
54
|
+
exec: 'yum'
|
|
55
|
+
arguments: 'install -y puppet'
|
|
56
|
+
|
|
57
|
+
- name: 'Install chocolatey on all the windows nodes'
|
|
58
|
+
nodes_by_config: {os: 'windows'}
|
|
59
|
+
command:
|
|
60
|
+
verify_commands:
|
|
61
|
+
- title: 'Check if chocolatey is installed'
|
|
62
|
+
plugin: 'winrm/powershell'
|
|
63
|
+
exec: 'choco -?'
|
|
64
|
+
plugin: 'winrm/powershell'
|
|
65
|
+
exec: |
|
|
66
|
+
$Policy = Get-ExecutionPolicy
|
|
67
|
+
If ($Policy -eq "Restricted") {
|
|
68
|
+
Set-ExecutionPolicy AllSigned
|
|
69
|
+
}
|
|
70
|
+
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
|
|
71
|
+
|
|
72
|
+
- name: 'Install puppet on all the windows nodes'
|
|
73
|
+
nodes_by_config: {os: 'windows'}
|
|
74
|
+
command:
|
|
75
|
+
verify_commands:
|
|
76
|
+
- title: 'Check if puppet is installed'
|
|
77
|
+
plugin: 'winrm/powershell'
|
|
78
|
+
exec: 'puppet help'
|
|
79
|
+
plugin: 'winrm/powershell'
|
|
80
|
+
exec: 'choco install -y puppet'
|
|
81
|
+
|
|
47
82
|
- name: 'copy the puppet configuration to the right place'
|
|
48
83
|
roles: 'puppetmaster'
|
|
49
84
|
command:
|
|
@@ -129,7 +164,7 @@ steps:
|
|
|
129
164
|
exec: 'puppet'
|
|
130
165
|
arguments: 'apply /etc/puppet/manifests/site.pp'
|
|
131
166
|
|
|
132
|
-
- name: 'Add puppetmaster to all hosts files'
|
|
167
|
+
- name: 'Add puppetmaster to all hosts files on linux'
|
|
133
168
|
nodes_by_config: {os: 'linux'}
|
|
134
169
|
command:
|
|
135
170
|
verify_commands:
|
|
@@ -140,6 +175,19 @@ steps:
|
|
|
140
175
|
exec: "echo"
|
|
141
176
|
arguments: '"192.168.56.101 puppetmaster.example.com puppetmaster" >> /etc/hosts'
|
|
142
177
|
|
|
178
|
+
- name: 'Add puppetmaster to all hosts files on windows'
|
|
179
|
+
nodes_by_config: {os: 'windows'}
|
|
180
|
+
command:
|
|
181
|
+
verify_commands:
|
|
182
|
+
- plugin: 'winrm/file_contains'
|
|
183
|
+
file: 'C:\Windows\System32\Drivers\etc\hosts'
|
|
184
|
+
pattern: 'puppetmaster.example.com'
|
|
185
|
+
plugin: 'winrm/powershell'
|
|
186
|
+
exec: "Add-Content"
|
|
187
|
+
arguments:
|
|
188
|
+
- 'C:\Windows\System32\Drivers\etc\hosts'
|
|
189
|
+
- '"`n192.168.56.101 puppetmaster.example.com puppetmaster"'
|
|
190
|
+
|
|
143
191
|
- name: 'Add broker to all hosts files'
|
|
144
192
|
nodes_by_config: {os: 'linux'}
|
|
145
193
|
command:
|
|
@@ -157,3 +205,14 @@ steps:
|
|
|
157
205
|
command:
|
|
158
206
|
plugin: 'ssh/puppet_agent_run'
|
|
159
207
|
arguments: '--server puppetmaster.example.com'
|
|
208
|
+
|
|
209
|
+
# There is an issue with the domain name which gets not set
|
|
210
|
+
# by Vagrant
|
|
211
|
+
# - name: "run puppet on the windows nodes"
|
|
212
|
+
# nodes_by_config: {os: 'windows'}
|
|
213
|
+
# command:
|
|
214
|
+
# - plugin: 'winrm/puppet_agent_run'
|
|
215
|
+
# arguments: '--server puppetmaster.example.com'
|
|
216
|
+
# rerun_on_change: true
|
|
217
|
+
# rerun_on_error: true
|
|
218
|
+
# max_rerun: 3
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dopi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.18.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andreas Zuber
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2017-
|
|
12
|
+
date: 2017-05-31 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: bundler
|
|
@@ -101,20 +101,20 @@ dependencies:
|
|
|
101
101
|
requirements:
|
|
102
102
|
- - "~>"
|
|
103
103
|
- !ruby/object:Gem::Version
|
|
104
|
-
version: '0.
|
|
104
|
+
version: '0.15'
|
|
105
105
|
- - ">="
|
|
106
106
|
- !ruby/object:Gem::Version
|
|
107
|
-
version: 0.
|
|
107
|
+
version: 0.15.0
|
|
108
108
|
type: :runtime
|
|
109
109
|
prerelease: false
|
|
110
110
|
version_requirements: !ruby/object:Gem::Requirement
|
|
111
111
|
requirements:
|
|
112
112
|
- - "~>"
|
|
113
113
|
- !ruby/object:Gem::Version
|
|
114
|
-
version: '0.
|
|
114
|
+
version: '0.15'
|
|
115
115
|
- - ">="
|
|
116
116
|
- !ruby/object:Gem::Version
|
|
117
|
-
version: 0.
|
|
117
|
+
version: 0.15.0
|
|
118
118
|
- !ruby/object:Gem::Dependency
|
|
119
119
|
name: gli
|
|
120
120
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -163,14 +163,14 @@ dependencies:
|
|
|
163
163
|
requirements:
|
|
164
164
|
- - "~>"
|
|
165
165
|
- !ruby/object:Gem::Version
|
|
166
|
-
version: '
|
|
166
|
+
version: '2'
|
|
167
167
|
type: :runtime
|
|
168
168
|
prerelease: false
|
|
169
169
|
version_requirements: !ruby/object:Gem::Requirement
|
|
170
170
|
requirements:
|
|
171
171
|
- - "~>"
|
|
172
172
|
- !ruby/object:Gem::Version
|
|
173
|
-
version: '
|
|
173
|
+
version: '2'
|
|
174
174
|
- !ruby/object:Gem::Dependency
|
|
175
175
|
name: parallel
|
|
176
176
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -278,6 +278,7 @@ files:
|
|
|
278
278
|
- lib/dopi/command_parser/exec.rb
|
|
279
279
|
- lib/dopi/command_parser/exit_code.rb
|
|
280
280
|
- lib/dopi/command_parser/output.rb
|
|
281
|
+
- lib/dopi/command_parser/puppet_run.rb
|
|
281
282
|
- lib/dopi/command_set.rb
|
|
282
283
|
- lib/dopi/connector/local.rb
|
|
283
284
|
- lib/dopi/connector/ssh.rb
|