puppetwash 0.2.0
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 +7 -0
- data/puppet.rb +253 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b8eef1dd676ba28105ebfb9c74b550ff32797bfcf257f472e5058633782c59c7
|
4
|
+
data.tar.gz: 5963426b4d35b391aa9355f16162e69765c882e92924b0336437f6f4837cc0d1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: abcc6fd791d8d5cbf21f05123dcd596b90dde855535854b7b20223bcb7af9d1bc1c1097a2d0b0e70a914d1690c6fb0b4449299349879afd7f419451b7be1213c
|
7
|
+
data.tar.gz: 3f4594240fcc3b1f5ad179f59c4d7a791a30fc5be789b920aee2a7c68cfd69b6111b49e12946239523460948930f8caaead1286f568fc2497e4b3866d92e7f35
|
data/puppet.rb
ADDED
@@ -0,0 +1,253 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'wash'
|
4
|
+
require 'puppetdb'
|
5
|
+
require 'json'
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
def client(config)
|
9
|
+
if config[:rbac_token]
|
10
|
+
# PE token-based auth
|
11
|
+
PuppetDB::Client.new({
|
12
|
+
server: config[:puppetdb_url],
|
13
|
+
token: config[:rbac_token],
|
14
|
+
cacert: config[:cacert]
|
15
|
+
})
|
16
|
+
else
|
17
|
+
# Cert-based auth
|
18
|
+
PuppetDB::Client.new({
|
19
|
+
server: config[:puppetdb_url],
|
20
|
+
pem: {
|
21
|
+
'ca_file' => config[:cacert],
|
22
|
+
'key' => config[:key],
|
23
|
+
'cert' => config[:cert]
|
24
|
+
}
|
25
|
+
})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def make_readable(value)
|
30
|
+
valueStr = value
|
31
|
+
unless valueStr.kind_of? String
|
32
|
+
valueStr = JSON.pretty_generate(value)
|
33
|
+
end
|
34
|
+
valueStr.chomp + "\n"
|
35
|
+
end
|
36
|
+
|
37
|
+
class Puppetwash < Wash::Entry
|
38
|
+
label 'puppet'
|
39
|
+
is_singleton
|
40
|
+
parent_of 'Instance'
|
41
|
+
state :config
|
42
|
+
description <<~DESC
|
43
|
+
A plugin for managing your Puppet instances (both PE and open source). Try `stree puppet`
|
44
|
+
to see all the things that this plugin lets you interact with.
|
45
|
+
DESC
|
46
|
+
|
47
|
+
def init(config)
|
48
|
+
@config = config
|
49
|
+
end
|
50
|
+
|
51
|
+
def list
|
52
|
+
@config.map do |name, instance_config|
|
53
|
+
Instance.new(name, instance_config)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class Instance < Wash::Entry
|
59
|
+
label 'instance'
|
60
|
+
parent_of 'Nodes'
|
61
|
+
state :config
|
62
|
+
description <<~DESC
|
63
|
+
This is a Puppet instance.
|
64
|
+
DESC
|
65
|
+
|
66
|
+
def initialize(name, config)
|
67
|
+
@name = name
|
68
|
+
@config = config
|
69
|
+
end
|
70
|
+
|
71
|
+
def list
|
72
|
+
[Nodes.new(@config)]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class Nodes < Wash::Entry
|
77
|
+
label 'nodes'
|
78
|
+
is_singleton
|
79
|
+
parent_of 'Node'
|
80
|
+
state :config
|
81
|
+
|
82
|
+
def initialize(config)
|
83
|
+
@name = 'nodes'
|
84
|
+
@config = config
|
85
|
+
end
|
86
|
+
|
87
|
+
def list
|
88
|
+
response = client(@config).request('nodes', nil)
|
89
|
+
response.data.map do |node|
|
90
|
+
Node.new(node, @config)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
class Node < Wash::Entry
|
96
|
+
label 'node'
|
97
|
+
parent_of 'CatalogJSON', 'Facts', 'Reports'
|
98
|
+
state :config
|
99
|
+
description <<~DESC
|
100
|
+
This is a managed node. Use the `meta` command to view its metadata.
|
101
|
+
DESC
|
102
|
+
|
103
|
+
def initialize(node, config)
|
104
|
+
@name = node['certname']
|
105
|
+
@config = config
|
106
|
+
@partial_metadata = node
|
107
|
+
prefetch :list
|
108
|
+
end
|
109
|
+
|
110
|
+
def list
|
111
|
+
[
|
112
|
+
CatalogJSON.new(@name, @config),
|
113
|
+
Facts.new(@name, @config),
|
114
|
+
Reports.new(@name, @config)
|
115
|
+
]
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
class CatalogJSON < Wash::Entry
|
120
|
+
label 'catalog.json'
|
121
|
+
is_singleton
|
122
|
+
state :node_name, :config
|
123
|
+
description <<~DESC
|
124
|
+
This is the node's most recent catalog. Try using `cat` to read its
|
125
|
+
contents.
|
126
|
+
DESC
|
127
|
+
|
128
|
+
def initialize(node_name, config)
|
129
|
+
@name = 'catalog.json'
|
130
|
+
@node_name = node_name
|
131
|
+
@config = config
|
132
|
+
end
|
133
|
+
|
134
|
+
def read
|
135
|
+
response = client(@config).request("catalogs/#{@node_name}", nil)
|
136
|
+
make_readable(response.data)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
class Facts < Wash::Entry
|
141
|
+
label 'facts'
|
142
|
+
is_singleton
|
143
|
+
parent_of 'Fact'
|
144
|
+
state :node_name, :config
|
145
|
+
|
146
|
+
def initialize(node_name, config)
|
147
|
+
@name = 'facts'
|
148
|
+
@node_name = node_name
|
149
|
+
@config = config
|
150
|
+
end
|
151
|
+
|
152
|
+
def list
|
153
|
+
response = client(@config).request(
|
154
|
+
'facts',
|
155
|
+
[:'=', :certname, @node_name]
|
156
|
+
)
|
157
|
+
response.data.map do |fact|
|
158
|
+
Fact.new(fact['name'], fact['value'], @node_name, @config)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
class Fact < Wash::Entry
|
164
|
+
label 'fact'
|
165
|
+
state :node_name, :config
|
166
|
+
description <<~DESC
|
167
|
+
This is a top-level fact of the given node.
|
168
|
+
DESC
|
169
|
+
|
170
|
+
def initialize(name, value, node_name, config)
|
171
|
+
@name = name
|
172
|
+
@value = value
|
173
|
+
@node_name = node_name
|
174
|
+
@config = config
|
175
|
+
prefetch :read
|
176
|
+
end
|
177
|
+
|
178
|
+
def read
|
179
|
+
make_readable(@value)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
# Report relies on end_time and hash. The others are included as useful metadata.
|
184
|
+
METADATA_FIELDS = {
|
185
|
+
'end_time': 'string',
|
186
|
+
'environment': 'string',
|
187
|
+
'status': 'string',
|
188
|
+
'noop': 'boolean',
|
189
|
+
'puppet_version': 'string',
|
190
|
+
'producer': 'string',
|
191
|
+
'hash': 'string'
|
192
|
+
}
|
193
|
+
|
194
|
+
class Reports < Wash::Entry
|
195
|
+
label 'reports'
|
196
|
+
is_singleton
|
197
|
+
parent_of 'Report'
|
198
|
+
state :node_name, :config
|
199
|
+
|
200
|
+
def initialize(node_name, config)
|
201
|
+
@name = 'reports'
|
202
|
+
@node_name = node_name
|
203
|
+
@config = config
|
204
|
+
end
|
205
|
+
|
206
|
+
def list
|
207
|
+
response = client(@config).request(
|
208
|
+
'reports',
|
209
|
+
[:extract,
|
210
|
+
METADATA_FIELDS.keys,
|
211
|
+
[:'=', :certname, @node_name]]
|
212
|
+
)
|
213
|
+
response.data.map do |report|
|
214
|
+
Report.new(report, @node_name, @config)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
class Report < Wash::Entry
|
220
|
+
label 'report'
|
221
|
+
attributes :mtime
|
222
|
+
partial_metadata_schema(
|
223
|
+
type: 'object',
|
224
|
+
properties: METADATA_FIELDS.map { |k, v| [k, { type: v }] }.to_h
|
225
|
+
)
|
226
|
+
state :node_name, :config, :hash
|
227
|
+
description <<-DESC
|
228
|
+
This is a node's report. Try using the 'meta' command to view its
|
229
|
+
metadata.
|
230
|
+
DESC
|
231
|
+
|
232
|
+
def initialize(report, node_name, config)
|
233
|
+
@name = report['end_time']
|
234
|
+
@node_name = node_name
|
235
|
+
@config = config
|
236
|
+
@hash = report['hash']
|
237
|
+
@partial_metadata = report
|
238
|
+
@mtime = Time.parse(report['end_time'])
|
239
|
+
end
|
240
|
+
|
241
|
+
def read
|
242
|
+
response = client(@config).request(
|
243
|
+
'reports',
|
244
|
+
[:and, [:'=', :certname, @node_name], [:'=', :hash, @hash]]
|
245
|
+
)
|
246
|
+
make_readable(response.data)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
Wash.enable_entry_schemas
|
251
|
+
Wash.prefetch_entry_schemas
|
252
|
+
Wash.pretty_print
|
253
|
+
Wash.run(Puppetwash, ARGV)
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: puppetwash
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Puppet
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: puppetdb-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: wash
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.12'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ruby-debug-ide
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: debase
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rcodetools
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.8'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.8'
|
97
|
+
description: A Wash plugin for examining Puppet infrastructure nodes such as PuppetDB,
|
98
|
+
Puppet Server, and PE Classifier
|
99
|
+
email:
|
100
|
+
- puppet@puppet.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- puppet.rb
|
106
|
+
homepage: https://github.com/puppetlabs/puppetwash
|
107
|
+
licenses:
|
108
|
+
- Apache-2.0
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - "~>"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '2.3'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubygems_version: 3.0.3
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: A Wash plugin for Puppet infrastructure
|
129
|
+
test_files: []
|