puppet-debugger 0.16.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9873e0a4a8f2dc1ebfaafafa8675e2e942a8e6c4591dfde9aa6400c494c1adce
4
- data.tar.gz: 310d779ee5bbb993e16ac74d4856ab73a8c29a4bef12205df90dae79b450d099
3
+ metadata.gz: 064ab5d1d98f5c578ba1b5e44264f46f58758e002962a15a952cef3727f8293b
4
+ data.tar.gz: 0b277145b7b8e1331335c4426eef7fcb4da178c237003d0a52e885994834f515
5
5
  SHA512:
6
- metadata.gz: 9f2c1739d8e4a05c5b4b001819476fc8af16c7ee30d05d6616ade4602ea95755f8ef6bf1a1869f50e89ae61789325d23ab2be2984c7ab8167247e57acffb25ad
7
- data.tar.gz: 151294ae8d704da59e87180288b8e2da87ad8564fe155676653f9c3594f5883fa7f3da541f9b7ab617f87483fc3d31d12ac756ef346f2a343b0921e56c90b050
6
+ metadata.gz: 9dab8038472346e1ef354edf6de7cf5c004be3f98781a0b466304cb9d26643f2175fa3cef12d07967b9b2c507a5866754f8bcd0e7ff82e3909c0ce86b77ebde7
7
+ data.tar.gz: e734bf29bd64c5a62f78e6fc968f86b7694f046a5d98b26abf3f4e69416f8e31616de85e3ae6c503b5be523e2a5023fdebadb87d171a0efdb86db81f0703452c
@@ -1 +1 @@
1
- 2.4.5
1
+ 2.6.5
@@ -1,5 +1,11 @@
1
1
  ## Unreleased
2
2
 
3
+ ## 0.17.0
4
+ - Fix bolt issue when the catalog is referenced
5
+ - Fix bolt issue when scriptcompiler scope is used
6
+ and the debugger tries to expand the resources
7
+ in the catalog.
8
+
3
9
  ## 0.16.0
4
10
  - Load bolt puppet modules if bolt exists
5
11
  - Fix bolt datatype rendering issues
data/README.md CHANGED
@@ -31,8 +31,11 @@
31
31
 
32
32
  A interactive command line tool for evaluating and debugging the puppet language.
33
33
 
34
+ ## Documentation
35
+ Please visit https://docs.puppet-debugger.com for more info.
36
+
34
37
  ## Compatibility
35
- Requires Puppet 3.8+ and only uses the future parser.
38
+ Requires Puppet 3.8+ and only uses the future parser. Works with puppet 4-6.
36
39
 
37
40
  ## Production usage
38
41
  The puppet debugger is a developer tool that should only be used when writing puppet code. Although it might seem useful
@@ -41,18 +44,6 @@ to install on your production puppet master. Please do not install because of th
41
44
  ## Installation
42
45
  `gem install puppet-debugger`
43
46
 
44
- ## Load path
45
- puppet-debugger will load all puppet functions from your basemodulepath and environmentpath.
46
-
47
- This means if you run `puppet module install puppetlabs-stdlib` and they will be available
48
- in the debugger.
49
-
50
- ## Interactive demo
51
- I have put together a repo with a few setup instructions that will assist you in setting up a "mock" environment
52
- for usage with the puppet-debugger. This was originally intended when giving a demo of the repl, but also seems
53
- useful for other people.
54
-
55
- https://github.com/nwops/puppet-debugger-demo
56
47
 
57
48
  ## Web demo
58
49
  There is a web version of the [puppet-debugger](https://demo.puppet-debugger.com) online but is somewhat
@@ -90,242 +81,6 @@ Type "exit", "functions", "vars", "krt", "whereami", "facts", "resources", "clas
90
81
 
91
82
  ```
92
83
 
93
- ## Using Variables
94
-
95
- ```
96
- MacBook-Pro-2/tmp % puppet debugger
97
- Ruby Version: 2.0.0
98
- Puppet Version: 3.8.5
99
- Puppet Debugger Version: 0.0.7
100
- Created by: NWOps <corey@nwops.io>
101
- Type "exit", "functions", "vars", "krt", "facts", "reset", "help" for more information.
102
-
103
- >>
104
-
105
- >> $config_file = '/etc/httpd/httpd.conf'
106
- => "/etc/httpd/httpd.conf"
107
- >> file{$config_file: ensure => present, content => 'hello'}
108
- => Puppet::Type::File {
109
- path => "/etc/httpd/httpd.conf",
110
- provider => posix,
111
- ensure => present,
112
- content => "{md5}5d41402abc4b2a76b9719d911017c592",
113
- checksum => nil,
114
- backup => "puppet",
115
- replace => true,
116
- links => manage,
117
- purge => false,
118
- sourceselect => first,
119
- show_diff => true,
120
- validate_replacement => "%",
121
- source_permissions => use,
122
- selinux_ignore_defaults => false,
123
- loglevel => notice,
124
- name => "/etc/httpd/httpd.conf",
125
- title => "/etc/httpd/httpd.conf"
126
- }
127
- >>
128
- ```
129
- ### Listing variables
130
- To see the current variables in the scope use the `vars` keyword.
131
-
132
- ![variables](resources/variables.png)
133
-
134
- ## Listing functions
135
- Knowing what functions are available and where they come from is extremely helpful especially in a debugger session. Run the `functions` keyword to get a name spaced list of functions. You can further filter out functions by passing in a filter argument. `functions stdlib`
136
-
137
- ![functions](resources/functions.png)
138
-
139
- ## Using functions
140
- Functions will run and produce the desired output. If you type the word `functions`
141
- a list of available functions will be displayed on the screen along with a namespace to help you identify where they came from.
142
-
143
- ```
144
- >> split('hello/there/one/two/three','/')
145
- => ["hello", "there", "one", "two", "three"]
146
-
147
- ```
148
-
149
- So you can imagine how much fun this can be trying out different types of functions.
150
-
151
- ## Duplicate resource error
152
- Just like normal puppet code you cannot create duplicate resources.
153
-
154
- ```
155
- >> file{'/tmp/failure2.txt': ensure => present}
156
- => Evaluation Error: Error while evaluating a Resource Statement, Duplicate declaration: File[/tmp/failure2.txt] is already declared in file :1; cannot redeclare at line 1 at line 1:1
157
-
158
- ```
159
- You can reset the parser by running `reset` within the debugger without having to exit.
160
-
161
- ## Setting the puppet log level
162
- If you want to see what puppet is doing behind the scenes you can set the log level
163
- via `:set loglevel debug`. Valid log levels are `debug`, `info`, `warning` and other
164
- levels defined in puppet [config reference](https://docs.puppetlabs.com/puppet/4.4/reference/configuration.html#loglevel) .
165
-
166
- ![hiera](resources/hiera.png)
167
-
168
- ## Remote nodes
169
- This is new for 0.2.0. The puppet-debugger now has the ability to pull in remote node information. Instead of mocking facts you can pull in real information! Get real facts and real node classification from the puppet master and then play with the info in the debugger session. This is made possible by using the puppet node indirector interface.
170
-
171
- ie. `puppet node find hostname --terminus rest --render-as yaml`
172
-
173
- In order to use this feature you will need to setup a few things.
174
-
175
- ### Setup
176
- 1. Allow node rest calls to your workstation on the puppet master(s)
177
- See https://github.com/nwops/puppet-debugger/issues/17 for more info on allowing this rule.
178
-
179
- 2. Ensure you have the same code that your puppet master does. Since this pulls in classification you will need to have all the puppet modules defined in your
180
- environmentpath or basemodulepath. The simple thing to do is to point your basemodulepath to your fixtures directory if using rspec-puppet or some other high level modules directory. For PE users you will want to ensure you have all the
181
- pe specific modules in your development environment. Not doing this step will result in class not found errors.
182
-
183
- 3. Set the server config in your local puppet.conf. (on your development machine)
184
-
185
- a. Find your puppet config file `puppet config print config`
186
-
187
- b. edit the config file with an editor
188
-
189
- c. add `server = <hostname>` to your main block
190
-
191
- 4. If using hiera you also need to set the path to your hiera config file since
192
- the puppet-debugger will be compiling puppet code which could in turn call hiera
193
- functions. Additionally, make sure your hiera config points to the correct
194
- data location.
195
-
196
- ```
197
- [main]
198
- server = pe-puppet.localdomain
199
- basemodulepath = /Users/cosman/github/puppet-debugger-demo/modules:/Users/cosman/Downloads/pe_modules
200
- hiera_config = /Users/cosman/github/puppet-debugger-demo/hieradata/hiera.yaml
201
-
202
-
203
- ```
204
-
205
- ### Usage
206
- There are two ways of using the remote node feature. You can either
207
- pass in the node name from the command line or set the node name from the debugger session.
208
-
209
- #### Command line:
210
- `puppet debugger -n node_name`
211
-
212
- ![command line](resources/command_line_node.png)
213
-
214
- #### From debugger session:
215
- `:set node node_name`
216
-
217
- ![command line](resources/set_node.png)
218
-
219
-
220
- This is also extremely useful to check classification rules and variables by your ENC. So instead of running your ENC script manually we get the puppet master to run this indirectly and return the results to you.
221
-
222
- ## Auto Complete
223
- The puppet-debugger uses readline internally. So any variable or function is also available for auto completion.
224
- Press the tab key to engage the auto complete functionality.
225
-
226
- Currently native functions are not available in auto complete. See #24
227
-
228
- ## FacterDB and using different fact sets
229
- The puppet-debugger internally leverages the [facterdb](https://github.com/camptocamp/facterdb/) gem to load pre-cached facts into the debugger session. At some point you
230
- may need to override the debugger's default fact set with something of your own choosing. You can do this by setting one of the environment variables below.
231
-
232
- * `DEBUGGER_FACTERDB_FILTER` Sets the entire filter
233
- * `DEBUGGER_FACTER_OS_VERSION` Sets the OS version (only works with RHEL clones and Fedora)
234
- * `DEBUGGER_FACTER_OS_NAME` Sets the OS name (only works with RHEL clones and Fedora)
235
- * `DEBUGGER_FACTER_VERSION` Sets the facter version to use in the debugger session (uses facter 3.1 for puppet 4.4+ and facter 2.4 for 3.8-4.4)
236
-
237
- By default it looks something like `operatingsystem=Fedora and operatingsystemrelease=23 and architecture=x86_64 and facterversion=/^3\\.1/`
238
- depending on the puppet version currently running.
239
-
240
- You can display the current facterdb filter by running `facterdb_filter` from the debugger session.
241
-
242
- Why do facter versions matter? While facter and puppet work independently just fine, newer forge modules utilize certain data structures found only in newer versions of facter.
243
- So its really up to the puppet code you use. With facter 3, almost every fact is now a data structure. So if you are having issues with facts not existing in the debugger you may need to change the facter version `REPL_FACTER_VERSION` to something different.
244
-
245
- ## Custom FacterDB Facts
246
- As of FacterDB 0.4.0 we can now supply custom [external fact sets](https://github.com/camptocamp/facterdb#supplying-custom-external-facts) to facterDB.. This is a huge deal because you can take the facts from any system and play around with the fact data in the debugger. This makes the debugger appear as it was run on that system. Moreover, you can create shareable fact sets for your entire team. To use an external fact set you first need to grab the facts from the system you wish to "mock". This can be done with `puppet facts` or even puppetdb queries and then create a file with the values hash.
247
-
248
-
249
- Take the values from the values hash only and place inside a new file.
250
- ```
251
- {
252
- "name": "macbook-pro-10.domain",
253
- "values": {
254
- "custom_datacenter_fact": "iceland",
255
- "puppetversion": "5.3.2",
256
- "architecture": "x86_64",
257
- "kernel": "Darwin",
258
- "domain": "domain"
259
- }
260
- }
261
-
262
- ```
263
-
264
- This can be easily done if you have `jq` installed.
265
-
266
- `puppet facts | jq '.values' > /tmp/custom_facts/datacenter_a/2.4/os_x.facts`
267
-
268
- Once you have created a directory with one or more fact files you just need to set an environment variable to tell facterDB about the custom fact sets.
269
-
270
- `export FACTERDB_SEARCH_PATHS="/tmp/custom_facts/"`
271
-
272
- Now everytime you start the puppet debugger, facterDB will use these custom fact files
273
- as part of the facterDB database. However, you will still need to provide a search filter that references your custom fact because there are over a thousand facterDB fact sets.
274
-
275
- `puppet debugger --facterdb-filter 'custom_datacenter_fact=iceland'`
276
-
277
-
278
- Alternatively you can bypass the internal facterDB database by setting `export FACTERDB_SKIP_DEFAULTDB=true` and force your custom facts to be the only facts facterDB uses.
279
-
280
- *Note: when exporting facterDB environment variables you will also change the behavior for rspec_puppet_facts and other gems that also rely on facterDB. So please remember to unset the variables if not needed*
281
-
282
- ## Playback support
283
- puppet-debugger now supports playing back files or urls and loading the content into the debugger session. This means if you want to start a debugger session from an existing file or url you can play the content back in the debugger.
284
- You can also playback a file that contains puppet code and debugger commands.
285
-
286
- `play https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw`
287
-
288
- or
289
-
290
- `puppet debugger -p https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw`
291
-
292
- or just use STDIN `puppet debugger <some_file>` or `echo "abs(-3)" | puppet debugger`
293
-
294
- ### Web based playback support
295
- If using the [web based debugger](https://www.puppet-debugger.com) you can playback a shared url
296
- which would start a debugger session and then load the content from the url or parameter.
297
-
298
- Example:
299
- https://puppet-debugger.com/play?url=https://gist.github.com/logicminds/64f0fe9f64339f18f097a9f42acd6276
300
-
301
- or for single commands
302
-
303
- https://www.puppet-debugger.com/play?content=vars
304
-
305
- Please note the web based debugger only contains a minimal amount of puppet modules. So its likely
306
- that your code may not work if using third party modules. This may change in the future though.
307
-
308
- ## Plugins
309
- The puppet debugger has a plugin system that allows anyone to create new functionality
310
- for the puppet debugger. By default the puppet debugger ships with serveral core
311
- plugins that provide basic usage. Any non core plugin can be installed as a separate
312
- gem. The following is a list of plugins we wrote or know about.
313
-
314
-
315
- | Name | Project Url | Type | Description |
316
- | ------------- |:-------------:| -----:| -------------:|
317
- | playbooks | [playbooks](https://gitlab.com/puppet-debugger/puppet-debugger-playbooks) | editing | Allows group playback of scripted puppet commands |
318
-
319
-
320
- ## Development
321
- * [Plugin Development Guide](Plugin_development.md)
322
-
323
- ## Troubleshooting
324
- Please file an issue so we can track bugs.
325
-
326
-
327
- Pull requests welcomed.
328
-
329
84
  ## Copyright
330
85
 
331
86
  Copyright (c) 2018 NWOPS, LLC. See LICENSE.txt for
@@ -9,51 +9,7 @@ require 'puppet/util/log'
9
9
  require 'puppet-debugger/debugger_code'
10
10
  require 'puppet-debugger/support/errors'
11
11
  require 'plugins/puppet-debugger/input_responders/commands'
12
-
13
-
14
- # monkey patch in some color effects string methods
15
- class String
16
- def red
17
- "\033[31m#{self}\033[0m"
18
- end
19
-
20
- def bold
21
- "\033[1m#{self}\033[22m"
22
- end
23
-
24
- def black
25
- "\033[30m#{self}\033[0m"
26
- end
27
-
28
- def green
29
- "\033[32m#{self}\033[0m"
30
- end
31
-
32
- def cyan
33
- "\033[36m#{self}\033[0m"
34
- end
35
-
36
- def yellow
37
- "\033[33m#{self}\033[0m"
38
- end
39
-
40
- def warning
41
- yellow
42
- end
43
-
44
- def fatal
45
- red
46
- end
47
-
48
- def info
49
- green
50
- end
51
-
52
- def camel_case
53
- return self if self !~ /_/ && self =~ /[A-Z]+.*/
54
- split('_').map(&:capitalize).join
55
- end
56
- end
12
+ require 'puppet-debugger/monkey_patches'
57
13
 
58
14
  Puppet::Util::Log.newdesttype :buffer do
59
15
  require 'puppet/util/colors'
@@ -106,7 +106,7 @@ module PuppetDebugger
106
106
  end
107
107
 
108
108
  def contains_resources?(result)
109
- !Array(result).flatten.find { |r| r.class.to_s =~ /Puppet::Pops::Types/ }.nil?
109
+ !Array(result).flatten.find { |r| r.class.to_s =~ /Puppet::Pops::Types::PResourceType/ }.nil?
110
110
  end
111
111
 
112
112
  def normalize_output(result)
@@ -0,0 +1,54 @@
1
+ # monkey patch in some color effects string methods
2
+ class String
3
+ def red
4
+ "\033[31m#{self}\033[0m"
5
+ end
6
+
7
+ def bold
8
+ "\033[1m#{self}\033[22m"
9
+ end
10
+
11
+ def black
12
+ "\033[30m#{self}\033[0m"
13
+ end
14
+
15
+ def green
16
+ "\033[32m#{self}\033[0m"
17
+ end
18
+
19
+ def cyan
20
+ "\033[36m#{self}\033[0m"
21
+ end
22
+
23
+ def yellow
24
+ "\033[33m#{self}\033[0m"
25
+ end
26
+
27
+ def warning
28
+ yellow
29
+ end
30
+
31
+ def fatal
32
+ red
33
+ end
34
+
35
+ def info
36
+ green
37
+ end
38
+
39
+ def camel_case
40
+ return self if self !~ /_/ && self =~ /[A-Z]+.*/
41
+ split('_').map(&:capitalize).join
42
+ end
43
+ end
44
+
45
+ # Bolt plans utilize the PAL Script Compiler to compile the code and thus
46
+ # don't store a catalog with the scope. This is due to not needing the catalog
47
+ # in the scope. The debugger relies on the catalog being present in the scope
48
+ # and thus uses all the methods to discover various data in the catalog
49
+ # We monkey patch in a catalog here instead of changing our API for simplicity.
50
+ class Puppet::Parser::ScriptCompiler
51
+ def catalog
52
+ @catalog ||= Puppet::Resource::Catalog.new(@node_name, @environment, 'bolt')
53
+ end
54
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PuppetDebugger
4
- VERSION = "0.16.0"
4
+ VERSION = "0.17.0"
5
5
  end
@@ -218,8 +218,9 @@ describe "PuppetDebugger" do
218
218
  end
219
219
  it "shows type" do
220
220
  if Gem::Version.new(Puppet.version) > Gem::Version.new("4.4")
221
+ out = "\n => Tuple[Integer[1, 1], Integer[2, 2], Integer[3, 3], Integer[4, 4]]\n"
221
222
  debugger.handle_input(input)
222
- expect(output.string.strip.split("\n").count).to eq(6)
223
+ expect(output.string).to eq(out)
223
224
  end
224
225
  end
225
226
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-debugger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Osman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-08 00:00:00.000000000 Z
11
+ date: 2020-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: table_print
@@ -180,6 +180,7 @@ files:
180
180
  - lib/puppet-debugger/debugger_code.rb
181
181
  - lib/puppet-debugger/hooks.rb
182
182
  - lib/puppet-debugger/input_responder_plugin.rb
183
+ - lib/puppet-debugger/monkey_patches.rb
183
184
  - lib/puppet-debugger/plugin_test_helper.rb
184
185
  - lib/puppet-debugger/support.rb
185
186
  - lib/puppet-debugger/support/compiler.rb
@@ -288,7 +289,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
288
289
  - !ruby/object:Gem::Version
289
290
  version: '0'
290
291
  requirements: []
291
- rubygems_version: 3.1.2
292
+ rubygems_version: 3.0.3
292
293
  signing_key:
293
294
  specification_version: 4
294
295
  summary: A repl based debugger for the puppet language