cem_acpt 0.2.4 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/spec.yml +30 -0
- data/Gemfile +4 -3
- data/Gemfile.lock +95 -43
- data/README.md +144 -83
- data/cem_acpt.gemspec +12 -7
- data/exe/cem_acpt +41 -7
- data/lib/cem_acpt/config.rb +340 -0
- data/lib/cem_acpt/core_extensions.rb +17 -61
- data/lib/cem_acpt/goss/api/action_response.rb +175 -0
- data/lib/cem_acpt/goss/api.rb +83 -0
- data/lib/cem_acpt/goss.rb +8 -0
- data/lib/cem_acpt/image_name_builder.rb +0 -9
- data/lib/cem_acpt/logging/formatter.rb +97 -0
- data/lib/cem_acpt/logging.rb +168 -142
- data/lib/cem_acpt/platform/base.rb +26 -37
- data/lib/cem_acpt/platform/gcp.rb +48 -62
- data/lib/cem_acpt/platform.rb +30 -28
- data/lib/cem_acpt/provision/terraform/linux.rb +47 -0
- data/lib/cem_acpt/provision/terraform/os_data.rb +72 -0
- data/lib/cem_acpt/provision/terraform/windows.rb +22 -0
- data/lib/cem_acpt/provision/terraform.rb +193 -0
- data/lib/cem_acpt/provision.rb +20 -0
- data/lib/cem_acpt/puppet_helpers.rb +0 -1
- data/lib/cem_acpt/test_data.rb +23 -13
- data/lib/cem_acpt/test_runner/log_formatter/goss_action_response.rb +104 -0
- data/lib/cem_acpt/test_runner/log_formatter.rb +10 -0
- data/lib/cem_acpt/test_runner.rb +170 -3
- data/lib/cem_acpt/utils/puppet.rb +29 -0
- data/lib/cem_acpt/utils/ssh.rb +197 -0
- data/lib/cem_acpt/utils/terminal.rb +27 -0
- data/lib/cem_acpt/utils.rb +4 -138
- data/lib/cem_acpt/version.rb +1 -1
- data/lib/cem_acpt.rb +73 -23
- data/lib/terraform/gcp/linux/goss/puppet_idempotent.yaml +10 -0
- data/lib/terraform/gcp/linux/goss/puppet_noop.yaml +12 -0
- data/lib/terraform/gcp/linux/main.tf +191 -0
- data/lib/terraform/gcp/linux/systemd/goss-acpt.service +8 -0
- data/lib/terraform/gcp/linux/systemd/goss-idempotent.service +8 -0
- data/lib/terraform/gcp/linux/systemd/goss-noop.service +8 -0
- data/lib/terraform/gcp/windows/.keep +0 -0
- data/sample_config.yaml +22 -21
- metadata +151 -51
- data/lib/cem_acpt/bootstrap/bootstrapper.rb +0 -206
- data/lib/cem_acpt/bootstrap/operating_system/rhel_family.rb +0 -129
- data/lib/cem_acpt/bootstrap/operating_system.rb +0 -17
- data/lib/cem_acpt/bootstrap.rb +0 -12
- data/lib/cem_acpt/context.rb +0 -153
- data/lib/cem_acpt/platform/base/cmd.rb +0 -71
- data/lib/cem_acpt/platform/gcp/cmd.rb +0 -353
- data/lib/cem_acpt/platform/gcp/compute.rb +0 -332
- data/lib/cem_acpt/platform/vmpooler.rb +0 -24
- data/lib/cem_acpt/rspec_utils.rb +0 -242
- data/lib/cem_acpt/shared_objects.rb +0 -537
- data/lib/cem_acpt/spec_helper_acceptance.rb +0 -184
- data/lib/cem_acpt/test_runner/run_handler.rb +0 -187
- data/lib/cem_acpt/test_runner/runner.rb +0 -210
- data/lib/cem_acpt/test_runner/runner_result.rb +0 -103
@@ -0,0 +1,8 @@
|
|
1
|
+
[Unit]
|
2
|
+
Description=unit file for goss server acpt endpoint service
|
3
|
+
|
4
|
+
[Service]
|
5
|
+
ExecStart=/usr/local/bin/goss -g /opt/cem_acpt/goss/puppet_idempotent.yaml serve -f json -l ":8081" --endpoint "/idempotent" --cache "10m"
|
6
|
+
|
7
|
+
[Install]
|
8
|
+
WantedBy=multi-user.target
|
File without changes
|
data/sample_config.yaml
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
test_data:
|
2
2
|
for_each:
|
3
3
|
collection:
|
4
|
-
- puppet6
|
5
4
|
- puppet7
|
6
5
|
vars:
|
7
6
|
test_static_var: 'static_var_value'
|
@@ -21,24 +20,24 @@ test_data:
|
|
21
20
|
delete_vars:
|
22
21
|
- 'framework_vars'
|
23
22
|
|
24
|
-
platform:
|
23
|
+
platform:
|
24
|
+
name: gcp
|
25
|
+
project: 'team-sse'
|
26
|
+
region: 'us-west1'
|
27
|
+
zone: 'us-west1-b'
|
28
|
+
subnetwork: 'cem-acpt-subnet'
|
29
|
+
|
30
|
+
# terraform:
|
31
|
+
# environment:
|
32
|
+
# TF_LOG: 'DEBUG'
|
33
|
+
|
34
|
+
actions:
|
35
|
+
only:
|
36
|
+
- 'acpt'
|
25
37
|
|
26
38
|
node_data:
|
27
39
|
machine_type: 'e2-small'
|
28
|
-
|
29
|
-
name: 'some-project'
|
30
|
-
zone: 'us-west1-b'
|
31
|
-
disk:
|
32
|
-
name: 'disk-1'
|
33
|
-
size: 20
|
34
|
-
type: 'pd-standard'
|
35
|
-
network_interface:
|
36
|
-
tier: 'STANDARD'
|
37
|
-
subnetwork: 'some-subnet'
|
38
|
-
metadata:
|
39
|
-
ephemeral_ssh_key:
|
40
|
-
lifetime: 2
|
41
|
-
keydir: '/tmp/acpt_test_keys'
|
40
|
+
disk_size: 40
|
42
41
|
|
43
42
|
image_name_builder:
|
44
43
|
character_substitutions:
|
@@ -48,11 +47,13 @@ image_name_builder:
|
|
48
47
|
- '$image_fam'
|
49
48
|
- '$collection'
|
50
49
|
- '$firewall'
|
51
|
-
join_with: '-'
|
50
|
+
join_with: '-'
|
52
51
|
|
53
52
|
tests:
|
54
|
-
- cis_rhel-
|
55
|
-
- cis_rhel-7_iptables_server_1
|
56
|
-
- cis_rhel-8_firewalld_server_1
|
53
|
+
# - cis_rhel-7_firewalld_server_2
|
57
54
|
- cis_rhel-8_firewalld_server_2
|
58
|
-
-
|
55
|
+
# - cis_oel-7_firewalld_server_2
|
56
|
+
# - cis_oel-8_firewalld_server_2
|
57
|
+
# - cis_alma-8_firewalld_server_2
|
58
|
+
# - stig_rhel-7_firewalld_public_3
|
59
|
+
# - stig_rhel-8_firewalld_public_3
|
metadata
CHANGED
@@ -1,122 +1,214 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cem_acpt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- puppetlabs
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
+
name: async-http
|
14
15
|
requirement: !ruby/object:Gem::Requirement
|
15
16
|
requirements:
|
16
|
-
- - "
|
17
|
+
- - ">="
|
17
18
|
- !ruby/object:Gem::Version
|
18
|
-
version:
|
19
|
-
|
20
|
-
|
19
|
+
version: '0.60'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0.70'
|
21
23
|
type: :runtime
|
24
|
+
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.60'
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
32
|
+
version: '0.70'
|
27
33
|
- !ruby/object:Gem::Dependency
|
34
|
+
name: concurrent-ruby
|
28
35
|
requirement: !ruby/object:Gem::Requirement
|
29
36
|
requirements:
|
30
|
-
- - "
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.1'
|
40
|
+
- - "<"
|
31
41
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
42
|
+
version: '2.0'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.1'
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '2.0'
|
53
|
+
- !ruby/object:Gem::Dependency
|
33
54
|
name: deep_merge
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '1.2'
|
60
|
+
- - "<"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '2.0'
|
63
|
+
type: :runtime
|
34
64
|
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.2'
|
70
|
+
- - "<"
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '2.0'
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: ed25519
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '1.2'
|
80
|
+
- - "<"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
35
83
|
type: :runtime
|
84
|
+
prerelease: false
|
36
85
|
version_requirements: !ruby/object:Gem::Requirement
|
37
86
|
requirements:
|
38
|
-
- - "
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.2'
|
90
|
+
- - "<"
|
39
91
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
92
|
+
version: '2.0'
|
41
93
|
- !ruby/object:Gem::Dependency
|
94
|
+
name: bcrypt_pbkdf
|
42
95
|
requirement: !ruby/object:Gem::Requirement
|
43
96
|
requirements:
|
44
|
-
- - "
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '1.0'
|
100
|
+
- - "<"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '2.0'
|
103
|
+
type: :runtime
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
45
108
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
109
|
+
version: '1.0'
|
110
|
+
- - "<"
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '2.0'
|
113
|
+
- !ruby/object:Gem::Dependency
|
47
114
|
name: net-ssh
|
115
|
+
requirement: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '7.1'
|
120
|
+
- - "<"
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '7.2'
|
123
|
+
type: :runtime
|
48
124
|
prerelease: false
|
125
|
+
version_requirements: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '7.1'
|
130
|
+
- - "<"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '7.2'
|
133
|
+
- !ruby/object:Gem::Dependency
|
134
|
+
name: parallel
|
135
|
+
requirement: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '1.22'
|
49
140
|
type: :runtime
|
141
|
+
prerelease: false
|
50
142
|
version_requirements: !ruby/object:Gem::Requirement
|
51
143
|
requirements:
|
52
144
|
- - "~>"
|
53
145
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
146
|
+
version: '1.22'
|
55
147
|
- !ruby/object:Gem::Dependency
|
148
|
+
name: puppet-modulebuilder
|
56
149
|
requirement: !ruby/object:Gem::Requirement
|
57
150
|
requirements:
|
58
|
-
- - "
|
151
|
+
- - ">="
|
59
152
|
- !ruby/object:Gem::Version
|
60
153
|
version: 0.0.1
|
61
|
-
name: puppet-modulebuilder
|
62
|
-
prerelease: false
|
63
154
|
type: :runtime
|
155
|
+
prerelease: false
|
64
156
|
version_requirements: !ruby/object:Gem::Requirement
|
65
157
|
requirements:
|
66
|
-
- - "
|
158
|
+
- - ">="
|
67
159
|
- !ruby/object:Gem::Version
|
68
160
|
version: 0.0.1
|
69
161
|
- !ruby/object:Gem::Dependency
|
162
|
+
name: ruby-terraform
|
70
163
|
requirement: !ruby/object:Gem::Requirement
|
71
164
|
requirements:
|
72
|
-
- - "
|
165
|
+
- - "~>"
|
73
166
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
75
|
-
name: rake
|
76
|
-
prerelease: false
|
167
|
+
version: '1.7'
|
77
168
|
type: :runtime
|
169
|
+
prerelease: false
|
78
170
|
version_requirements: !ruby/object:Gem::Requirement
|
79
171
|
requirements:
|
80
|
-
- - "
|
172
|
+
- - "~>"
|
81
173
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
174
|
+
version: '1.7'
|
83
175
|
- !ruby/object:Gem::Dependency
|
176
|
+
name: serverspec
|
84
177
|
requirement: !ruby/object:Gem::Requirement
|
85
178
|
requirements:
|
86
|
-
- - "
|
179
|
+
- - "~>"
|
87
180
|
- !ruby/object:Gem::Version
|
88
|
-
version: '
|
89
|
-
name: rspec
|
90
|
-
prerelease: false
|
181
|
+
version: '2.42'
|
91
182
|
type: :runtime
|
183
|
+
prerelease: false
|
92
184
|
version_requirements: !ruby/object:Gem::Requirement
|
93
185
|
requirements:
|
94
|
-
- - "
|
186
|
+
- - "~>"
|
95
187
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
188
|
+
version: '2.42'
|
97
189
|
- !ruby/object:Gem::Dependency
|
190
|
+
name: pry
|
98
191
|
requirement: !ruby/object:Gem::Requirement
|
99
192
|
requirements:
|
100
193
|
- - ">="
|
101
194
|
- !ruby/object:Gem::Version
|
102
195
|
version: '0'
|
103
|
-
|
196
|
+
type: :development
|
104
197
|
prerelease: false
|
105
|
-
type: :runtime
|
106
198
|
version_requirements: !ruby/object:Gem::Requirement
|
107
199
|
requirements:
|
108
200
|
- - ">="
|
109
201
|
- !ruby/object:Gem::Version
|
110
202
|
version: '0'
|
111
203
|
- !ruby/object:Gem::Dependency
|
204
|
+
name: rubocop
|
112
205
|
requirement: !ruby/object:Gem::Requirement
|
113
206
|
requirements:
|
114
207
|
- - ">="
|
115
208
|
- !ruby/object:Gem::Version
|
116
209
|
version: '0'
|
117
|
-
name: rubocop
|
118
|
-
prerelease: false
|
119
210
|
type: :development
|
211
|
+
prerelease: false
|
120
212
|
version_requirements: !ruby/object:Gem::Requirement
|
121
213
|
requirements:
|
122
214
|
- - ">="
|
@@ -130,6 +222,7 @@ executables:
|
|
130
222
|
extensions: []
|
131
223
|
extra_rdoc_files: []
|
132
224
|
files:
|
225
|
+
- ".github/workflows/spec.yml"
|
133
226
|
- ".gitignore"
|
134
227
|
- ".rspec"
|
135
228
|
- CODEOWNERS
|
@@ -142,32 +235,39 @@ files:
|
|
142
235
|
- cem_acpt.gemspec
|
143
236
|
- exe/cem_acpt
|
144
237
|
- lib/cem_acpt.rb
|
145
|
-
- lib/cem_acpt/
|
146
|
-
- lib/cem_acpt/bootstrap/bootstrapper.rb
|
147
|
-
- lib/cem_acpt/bootstrap/operating_system.rb
|
148
|
-
- lib/cem_acpt/bootstrap/operating_system/rhel_family.rb
|
149
|
-
- lib/cem_acpt/context.rb
|
238
|
+
- lib/cem_acpt/config.rb
|
150
239
|
- lib/cem_acpt/core_extensions.rb
|
240
|
+
- lib/cem_acpt/goss.rb
|
241
|
+
- lib/cem_acpt/goss/api.rb
|
242
|
+
- lib/cem_acpt/goss/api/action_response.rb
|
151
243
|
- lib/cem_acpt/image_name_builder.rb
|
152
244
|
- lib/cem_acpt/logging.rb
|
245
|
+
- lib/cem_acpt/logging/formatter.rb
|
153
246
|
- lib/cem_acpt/platform.rb
|
154
247
|
- lib/cem_acpt/platform/base.rb
|
155
|
-
- lib/cem_acpt/platform/base/cmd.rb
|
156
248
|
- lib/cem_acpt/platform/gcp.rb
|
157
|
-
- lib/cem_acpt/
|
158
|
-
- lib/cem_acpt/
|
159
|
-
- lib/cem_acpt/
|
249
|
+
- lib/cem_acpt/provision.rb
|
250
|
+
- lib/cem_acpt/provision/terraform.rb
|
251
|
+
- lib/cem_acpt/provision/terraform/linux.rb
|
252
|
+
- lib/cem_acpt/provision/terraform/os_data.rb
|
253
|
+
- lib/cem_acpt/provision/terraform/windows.rb
|
160
254
|
- lib/cem_acpt/puppet_helpers.rb
|
161
|
-
- lib/cem_acpt/rspec_utils.rb
|
162
|
-
- lib/cem_acpt/shared_objects.rb
|
163
|
-
- lib/cem_acpt/spec_helper_acceptance.rb
|
164
255
|
- lib/cem_acpt/test_data.rb
|
165
256
|
- lib/cem_acpt/test_runner.rb
|
166
|
-
- lib/cem_acpt/test_runner/
|
167
|
-
- lib/cem_acpt/test_runner/
|
168
|
-
- lib/cem_acpt/test_runner/runner_result.rb
|
257
|
+
- lib/cem_acpt/test_runner/log_formatter.rb
|
258
|
+
- lib/cem_acpt/test_runner/log_formatter/goss_action_response.rb
|
169
259
|
- lib/cem_acpt/utils.rb
|
260
|
+
- lib/cem_acpt/utils/puppet.rb
|
261
|
+
- lib/cem_acpt/utils/ssh.rb
|
262
|
+
- lib/cem_acpt/utils/terminal.rb
|
170
263
|
- lib/cem_acpt/version.rb
|
264
|
+
- lib/terraform/gcp/linux/goss/puppet_idempotent.yaml
|
265
|
+
- lib/terraform/gcp/linux/goss/puppet_noop.yaml
|
266
|
+
- lib/terraform/gcp/linux/main.tf
|
267
|
+
- lib/terraform/gcp/linux/systemd/goss-acpt.service
|
268
|
+
- lib/terraform/gcp/linux/systemd/goss-idempotent.service
|
269
|
+
- lib/terraform/gcp/linux/systemd/goss-noop.service
|
270
|
+
- lib/terraform/gcp/windows/.keep
|
171
271
|
- sample_config.yaml
|
172
272
|
homepage: https://github.com/puppetlabs/cem_acpt
|
173
273
|
licenses:
|
@@ -191,7 +291,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
291
|
- !ruby/object:Gem::Version
|
192
292
|
version: '0'
|
193
293
|
requirements: []
|
194
|
-
rubygems_version: 3.
|
294
|
+
rubygems_version: 3.4.6
|
195
295
|
signing_key:
|
196
296
|
specification_version: 4
|
197
297
|
summary: CEM Acceptance Tests
|
@@ -1,206 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'operating_system'
|
4
|
-
|
5
|
-
# Currently unused in this implementation.
|
6
|
-
module CemAcpt::Bootstrap
|
7
|
-
# This class runs bootstrapping commands on the VM after it
|
8
|
-
# is provisioned. This can include installing repos,
|
9
|
-
# installing Puppet, installing other programs,
|
10
|
-
# starting services, and running other commands.
|
11
|
-
class Bootstrapper
|
12
|
-
STATE_ORDER = [:repo, :package, :service, :command, :complete].freeze
|
13
|
-
STATE_ACTIONS = {
|
14
|
-
repo: :run_repo_installs,
|
15
|
-
package: :run_package_installs,
|
16
|
-
service: :run_service_starts,
|
17
|
-
command: :run_commands,
|
18
|
-
}.freeze
|
19
|
-
UNIVERSAL_DEPS = [
|
20
|
-
'git',
|
21
|
-
'curl',
|
22
|
-
'puppet-agent',
|
23
|
-
].freeze
|
24
|
-
include CemAcpt::Bootstrap::OperatingSystem
|
25
|
-
|
26
|
-
def initialize(instance_name, instance_image, cmd, collection: 'puppet7', repos: [], packages: [], services: [], commands: [])
|
27
|
-
os, major_version = instance_image.split('-')
|
28
|
-
use_os(os)
|
29
|
-
@instance_name = instance_name.split('.').first
|
30
|
-
@cmd_provider = cmd
|
31
|
-
@collection = collection
|
32
|
-
@os = os
|
33
|
-
@major_version = major_version
|
34
|
-
@repos = repos
|
35
|
-
@packages = packages
|
36
|
-
@services = services
|
37
|
-
@commands = commands
|
38
|
-
@logfile = '/var/log/bootstrap.log'
|
39
|
-
@state = 0
|
40
|
-
@retries = 0
|
41
|
-
@results = {}
|
42
|
-
end
|
43
|
-
|
44
|
-
def ruby_version
|
45
|
-
return @ruby_version if defined?(@ruby_version)
|
46
|
-
|
47
|
-
@ruby_version = determine_ruby_version(@collection)
|
48
|
-
@ruby_version
|
49
|
-
end
|
50
|
-
|
51
|
-
def repos
|
52
|
-
@repos.push(puppet_agent_repo).uniq
|
53
|
-
end
|
54
|
-
|
55
|
-
def packages
|
56
|
-
(@packages + UNIVERSAL_DEPS).uniq
|
57
|
-
end
|
58
|
-
|
59
|
-
def services
|
60
|
-
@services.uniq
|
61
|
-
end
|
62
|
-
|
63
|
-
def commands
|
64
|
-
@commands + ruby_install_commands
|
65
|
-
end
|
66
|
-
|
67
|
-
def instance_available?
|
68
|
-
@instance_available ||= test_connection
|
69
|
-
end
|
70
|
-
|
71
|
-
def run
|
72
|
-
raise 'Instance is not available' unless instance_available?
|
73
|
-
|
74
|
-
@results = {}
|
75
|
-
transition_state
|
76
|
-
@results
|
77
|
-
rescue StandardError => e
|
78
|
-
return_results_with_error(e)
|
79
|
-
end
|
80
|
-
|
81
|
-
private
|
82
|
-
|
83
|
-
def return_results_with_error(error)
|
84
|
-
@results[:_error] = {
|
85
|
-
error: error,
|
86
|
-
details: {
|
87
|
-
instance_name: @instance_name,
|
88
|
-
instance_image: @instance_image,
|
89
|
-
collection: @collection,
|
90
|
-
os: @os,
|
91
|
-
major_version: @major_version,
|
92
|
-
repos: repos,
|
93
|
-
packages: packages,
|
94
|
-
services: services,
|
95
|
-
commands: commands,
|
96
|
-
state: @state,
|
97
|
-
retries: @retries,
|
98
|
-
},
|
99
|
-
}
|
100
|
-
@results
|
101
|
-
end
|
102
|
-
|
103
|
-
def execute_state_action
|
104
|
-
state_sym = STATE_ORDER[@state]
|
105
|
-
send(STATE_ACTIONS[state_sym])
|
106
|
-
end
|
107
|
-
|
108
|
-
def transition_state
|
109
|
-
raise @last_error if @results.key?(:_error)
|
110
|
-
return if @state == STATE_ORDER.length - 1
|
111
|
-
|
112
|
-
begin
|
113
|
-
execute_state_action
|
114
|
-
rescue StandardError => e
|
115
|
-
@last_error_time = Time.now
|
116
|
-
@last_errored_state = @state
|
117
|
-
@last_error = e
|
118
|
-
handle_state_error
|
119
|
-
end
|
120
|
-
@state += 1
|
121
|
-
transition_state
|
122
|
-
end
|
123
|
-
|
124
|
-
def run_repo_installs
|
125
|
-
raise 'Instance is not available' unless instance_available?
|
126
|
-
|
127
|
-
run_ssh_command_with_formatting(repo_install_cmd(repos), :repo_installs)
|
128
|
-
end
|
129
|
-
|
130
|
-
def run_package_installs
|
131
|
-
raise 'Instance is not available' unless instance_available?
|
132
|
-
|
133
|
-
run_ssh_command_with_formatting(package_install_cmd(packages), :package_installs)
|
134
|
-
end
|
135
|
-
|
136
|
-
def run_service_starts
|
137
|
-
raise 'Instance is not available' unless instance_available?
|
138
|
-
|
139
|
-
run_ssh_command_with_formatting(service_start_cmd(services), :service_starts)
|
140
|
-
end
|
141
|
-
|
142
|
-
def run_commands
|
143
|
-
raise 'Instance is not available' unless instance_available?
|
144
|
-
|
145
|
-
run_ssh_command_with_formatting(commands.join(';'), :command_runs)
|
146
|
-
end
|
147
|
-
|
148
|
-
def handle_state_error
|
149
|
-
@retries = 0 unless @last_errored_state == @state
|
150
|
-
|
151
|
-
raise @last_error unless @retries < 3
|
152
|
-
|
153
|
-
@retries += 1
|
154
|
-
@state = @last_errored_state
|
155
|
-
transition_state
|
156
|
-
end
|
157
|
-
|
158
|
-
def run_ssh_command_with_formatting(cmd, results_key, log_file: '/tmp/puppet-bootstrap.log')
|
159
|
-
key = results_key.to_sym
|
160
|
-
@results[key] = {}
|
161
|
-
@results[key][:started] = Time.now
|
162
|
-
if cmd.nil? || cmd.empty?
|
163
|
-
@results[key][:results] = 'No command(s) to run'
|
164
|
-
@results[key][:finished] = Time.now
|
165
|
-
return
|
166
|
-
end
|
167
|
-
cmd = "#{cmd} | tee -a #{log_file}"
|
168
|
-
ssh_results = @cmd_provider.ssh(@instance_name, cmd)
|
169
|
-
@results[key][:results] = ssh_results.gsub(%r{\s+}, ' ').split('\n')
|
170
|
-
@results[key][:finished] = Time.now
|
171
|
-
end
|
172
|
-
|
173
|
-
def verify_command(results_key)
|
174
|
-
send("verify_#{results_key}".to_sym)
|
175
|
-
end
|
176
|
-
|
177
|
-
def test_connection
|
178
|
-
return true if @cmd_provider.ssh_ready?(@instance_name)
|
179
|
-
|
180
|
-
raise "Connection test failed for #{@instance_name}"
|
181
|
-
end
|
182
|
-
|
183
|
-
def determine_ruby_version(collection)
|
184
|
-
case collection
|
185
|
-
when 'puppet7'
|
186
|
-
'2.7'
|
187
|
-
when 'puppet6'
|
188
|
-
'2.5'
|
189
|
-
else
|
190
|
-
raise "Cannot determine Ruby version, unsupported collection: #{collection}"
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
def ruby_install_commands
|
195
|
-
[
|
196
|
-
'curl -sSL https://raw.githubusercontent.com/rvm/rvm/stable/binscripts/rvm-installer -o rvm-installer',
|
197
|
-
'curl -sSL https://raw.githubusercontent.com/rvm/rvm/stable/binscripts/rvm-installer.asc -o rvm-installer.asc',
|
198
|
-
'chmod +x rvm-installer',
|
199
|
-
'gpg --verify rvm-installer.asc rvm-installer && sudo ./rvm-installer',
|
200
|
-
"sudo rvm install #{ruby_version} && sudo rvm use #{ruby_version} --default",
|
201
|
-
'gem install bundler',
|
202
|
-
'[[ -f ./Gemfile ]] && bundle install',
|
203
|
-
]
|
204
|
-
end
|
205
|
-
end
|
206
|
-
end
|