puppet-repl 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +16 -0
- data/Gemfile +8 -3
- data/Gemfile.lock +7 -0
- data/README.md +1 -0
- data/VERSION +1 -1
- data/lib/puppet-repl/cli.rb +3 -15
- data/lib/puppet-repl/support.rb +72 -24
- data/lib/version.rb +1 -1
- data/puppet-repl.gemspec +6 -17
- data/spec/puppet-repl_spec.rb +20 -2
- data/spec/spec_helper.rb +0 -1
- data/spec/support_spec.rb +5 -2
- metadata +5 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d5637d4132c4a51886e9ed737581c7a8f99b261
|
4
|
+
data.tar.gz: 00af9d2c0e0ad195268e6d35545ad8ab67627d1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46953cae49824a46ef5d0b86c5766790f8e5395bfda8805f4467146599d8e7750a275c97bd2edfca23972302a59ef46a2d00d5ea273559c7890c8cac1117d737
|
7
|
+
data.tar.gz: fceeea3fff2318bce930f6d722313a293c558c6b8f4cc2ac72410f0cb2f315fa670db5573be592a14d737dc832a00a806f5c993425e3ee842381facf8971a164
|
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
language: ruby
|
2
|
+
cache: bundler
|
3
|
+
install: "bundle install --without development"
|
4
|
+
before_script: "bundle exec puppet module install puppetlabs-stdlib"
|
5
|
+
script: "bundle exec rake spec SPEC_OPTS='--format documentation'"
|
6
|
+
rvm:
|
7
|
+
- 1.9.3
|
8
|
+
- 2.0.0
|
9
|
+
- 2.2.1
|
10
|
+
env:
|
11
|
+
matrix:
|
12
|
+
- PUPPET_GEM_VERSION="~> 3.8"
|
13
|
+
- PUPPET_GEM_VERSION="~> 4.2"
|
14
|
+
- PUPPET_GEM_VERSION="~> 4.3"
|
15
|
+
notifications:
|
16
|
+
email: corey@logicminds.biz
|
data/Gemfile
CHANGED
@@ -3,14 +3,19 @@ source "http://rubygems.org"
|
|
3
3
|
# Example:
|
4
4
|
# gem "activesupport", ">= 2.3.5"
|
5
5
|
gem 'puppet', ">= 3.8"
|
6
|
+
gem 'facterdb'
|
6
7
|
# Add dependencies to develop your gem here.
|
7
8
|
# Include everything needed to run rake, tests, features, etc.
|
8
|
-
|
9
|
+
|
10
|
+
group :test do
|
9
11
|
gem "rspec"
|
10
|
-
gem 'pry'
|
11
|
-
gem "rdoc", "~> 3.12"
|
12
12
|
gem "bundler"
|
13
13
|
gem "jeweler", "~> 2.0.1"
|
14
14
|
gem "simplecov", ">= 0"
|
15
15
|
gem 'rake'
|
16
16
|
end
|
17
|
+
|
18
|
+
group :development do
|
19
|
+
gem 'pry'
|
20
|
+
gem "rdoc", "~> 3.12"
|
21
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -11,6 +11,10 @@ GEM
|
|
11
11
|
docile (1.1.5)
|
12
12
|
facter (2.4.6)
|
13
13
|
CFPropertyList (~> 2.2.6)
|
14
|
+
facterdb (0.3.1)
|
15
|
+
facter
|
16
|
+
jgrep
|
17
|
+
json
|
14
18
|
faraday (0.9.2)
|
15
19
|
multipart-post (>= 1.2, < 3)
|
16
20
|
git (1.2.9.1)
|
@@ -34,6 +38,8 @@ GEM
|
|
34
38
|
nokogiri (>= 1.5.10)
|
35
39
|
rake
|
36
40
|
rdoc
|
41
|
+
jgrep (1.4.0)
|
42
|
+
json
|
37
43
|
json (1.8.3)
|
38
44
|
json_pure (1.8.3)
|
39
45
|
jwt (1.5.1)
|
@@ -88,6 +94,7 @@ PLATFORMS
|
|
88
94
|
|
89
95
|
DEPENDENCIES
|
90
96
|
bundler
|
97
|
+
facterdb
|
91
98
|
jeweler (~> 2.0.1)
|
92
99
|
pry
|
93
100
|
puppet (>= 3.8)
|
data/README.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/puppet-repl/cli.rb
CHANGED
@@ -1,19 +1,11 @@
|
|
1
1
|
require 'puppet'
|
2
|
-
require 'puppet/pops'
|
3
2
|
require 'readline'
|
3
|
+
require 'json'
|
4
4
|
require_relative 'support'
|
5
5
|
module PuppetRepl
|
6
6
|
class Cli
|
7
7
|
include PuppetRepl::Support
|
8
8
|
|
9
|
-
def initialize
|
10
|
-
begin
|
11
|
-
Puppet.initialize_settings
|
12
|
-
rescue
|
13
|
-
# do nothing otherwise calling init twice raises an error
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
9
|
def puppet_eval(input)
|
18
10
|
begin
|
19
11
|
parser.evaluate_string(scope, input)
|
@@ -41,8 +33,8 @@ module PuppetRepl
|
|
41
33
|
PuppetRepl::Cli.print_repl_desc
|
42
34
|
when 'functions'
|
43
35
|
puts function_map.keys.sort
|
44
|
-
when '
|
45
|
-
puts
|
36
|
+
when 'facts'
|
37
|
+
puts JSON.pretty_generate(node.facts)
|
46
38
|
when '_'
|
47
39
|
puts(" => #{@last_item}")
|
48
40
|
when 'environment'
|
@@ -60,10 +52,6 @@ module PuppetRepl
|
|
60
52
|
end
|
61
53
|
end
|
62
54
|
|
63
|
-
def self.ripl_start
|
64
|
-
Ripl.start
|
65
|
-
end
|
66
|
-
|
67
55
|
def self.print_repl_desc
|
68
56
|
puts(<<-EOT)
|
69
57
|
Ruby Version: #{RUBY_VERSION}
|
data/lib/puppet-repl/support.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'puppet/pops'
|
2
|
+
require 'facterdb'
|
3
|
+
|
1
4
|
module PuppetRepl
|
2
5
|
module Support
|
3
6
|
|
@@ -9,11 +12,38 @@ module PuppetRepl
|
|
9
12
|
dirs.flatten
|
10
13
|
end
|
11
14
|
|
15
|
+
# this is required in order to load things only when we need them
|
16
|
+
def do_initialize
|
17
|
+
begin
|
18
|
+
Puppet.initialize_settings
|
19
|
+
rescue
|
20
|
+
# do nothing otherwise calling init twice raises an error
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
12
24
|
def puppet_lib_dir
|
13
25
|
# returns something like "/Library/Ruby/Gems/2.0.0/gems/puppet-4.2.2/lib/puppet.rb"
|
14
26
|
@puppet_lib_dir ||= File.dirname(Puppet.method(:[]).source_location.first)
|
15
27
|
end
|
16
28
|
|
29
|
+
def new_parser
|
30
|
+
@new_parser ||= Puppet::Parser::ParserFactory.parser
|
31
|
+
# setting the file and string results in evaulting the string
|
32
|
+
# setting the file and not the string results in evaulting the file
|
33
|
+
@new_parser.file = 'repl'
|
34
|
+
#this defines what to parse, and where it came from (can use ‘repl’ as the filename)
|
35
|
+
@new_parser
|
36
|
+
end
|
37
|
+
|
38
|
+
def puppet_evaluate(input)
|
39
|
+
new_parser.string = input
|
40
|
+
result = new_parser.parse
|
41
|
+
#- this creates the top level definitions
|
42
|
+
# repl is just a fake name for the module
|
43
|
+
#result = result.instantiate('repl')
|
44
|
+
result.safeevaluate(scope) #- this evaluates and returns the result
|
45
|
+
end
|
46
|
+
|
17
47
|
# returns a array of function files
|
18
48
|
def function_files
|
19
49
|
search_dirs = lib_dirs.map do |lib_dir|
|
@@ -37,6 +67,7 @@ module PuppetRepl
|
|
37
67
|
# returns a map of functions
|
38
68
|
def function_map
|
39
69
|
unless @functions
|
70
|
+
do_initialize
|
40
71
|
@functions = {}
|
41
72
|
function_files.each do |file|
|
42
73
|
obj = {}
|
@@ -63,6 +94,7 @@ module PuppetRepl
|
|
63
94
|
|
64
95
|
# returns a future parser for evaluating code
|
65
96
|
def parser
|
97
|
+
Puppet::Parser::ParserFactory.evaluating_parser
|
66
98
|
@parser || ::Puppet::Pops::Parser::EvaluatingParser.new
|
67
99
|
end
|
68
100
|
|
@@ -74,11 +106,15 @@ module PuppetRepl
|
|
74
106
|
# creates a puppet environment given a module path and environment name
|
75
107
|
# this is cached
|
76
108
|
def puppet_environment
|
77
|
-
@puppet_environment
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
109
|
+
unless @puppet_environment
|
110
|
+
do_initialize
|
111
|
+
@puppet_environment = Puppet::Node::Environment.create(
|
112
|
+
puppet_env_name,
|
113
|
+
module_dirs,
|
114
|
+
manifests_dir
|
115
|
+
)
|
116
|
+
end
|
117
|
+
@puppet_environment
|
82
118
|
end
|
83
119
|
|
84
120
|
# def functions
|
@@ -94,16 +130,16 @@ module PuppetRepl
|
|
94
130
|
@compiler
|
95
131
|
end
|
96
132
|
|
97
|
-
def
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
133
|
+
def node
|
134
|
+
@node ||= create_node
|
135
|
+
end
|
136
|
+
|
137
|
+
def create_scope
|
102
138
|
@compiler = create_compiler(node)
|
103
139
|
scope = Puppet::Parser::Scope.new(compiler)
|
104
|
-
scope.source = Puppet::Resource::Type.new(:node,
|
140
|
+
scope.source = Puppet::Resource::Type.new(:node, node.name)
|
105
141
|
scope.parent = @compiler.topscope
|
106
|
-
|
142
|
+
compiler.compile # this will load everything into the scope
|
107
143
|
scope
|
108
144
|
end
|
109
145
|
|
@@ -111,28 +147,40 @@ module PuppetRepl
|
|
111
147
|
Puppet::Parser::Compiler.new(node)
|
112
148
|
end
|
113
149
|
|
114
|
-
def
|
115
|
-
|
150
|
+
def facterdb_filter
|
151
|
+
'operatingsystem=RedHat and operatingsystemrelease=/^7/ and architecture=x86_64 and facterversion=/^2.4\./'
|
152
|
+
end
|
153
|
+
|
154
|
+
# uses facterdb (cached facts) and retrives the facts given a filter
|
155
|
+
def facts
|
156
|
+
unless @facts
|
157
|
+
@facts ||= FacterDB.get_facts(facterdb_filter).first
|
158
|
+
end
|
159
|
+
@facts
|
160
|
+
end
|
161
|
+
|
162
|
+
# creates a node object
|
163
|
+
def create_node
|
164
|
+
options = {}
|
165
|
+
options[:parameters] = facts
|
166
|
+
options[:facts] = facts
|
167
|
+
options[:classes] = []
|
168
|
+
options[:environment] = puppet_environment
|
169
|
+
Puppet::Node.new(facts[:fqdn], options)
|
116
170
|
end
|
117
171
|
|
118
172
|
def scope
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
# do nothing otherwise calling init twice raises an error
|
173
|
+
unless @scope
|
174
|
+
do_initialize
|
175
|
+
@scope ||= create_scope
|
123
176
|
end
|
124
|
-
@scope
|
177
|
+
@scope
|
125
178
|
end
|
126
179
|
|
127
180
|
def manifests_dir
|
128
181
|
File.join(Puppet[:environmentpath],puppet_env_name,'manifests')
|
129
182
|
end
|
130
183
|
|
131
|
-
def build_node(name, opts = {})
|
132
|
-
opts.merge!({:environment => node_environment})
|
133
|
-
Puppet::Node.new(name, opts)
|
134
|
-
end
|
135
|
-
|
136
184
|
end
|
137
185
|
end
|
138
186
|
#scope.environment.known_resource_types
|
data/lib/version.rb
CHANGED
data/puppet-repl.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "puppet-repl"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Corey Osman"]
|
12
|
-
s.date = "2016-02-
|
12
|
+
s.date = "2016-02-26"
|
13
13
|
s.description = "A interactive command line tool for evaluating the puppet language"
|
14
14
|
s.email = "corey@nwops.io"
|
15
15
|
s.executables = ["prepl"]
|
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.files = [
|
21
21
|
".document",
|
22
22
|
".rspec",
|
23
|
+
".travis.yml",
|
23
24
|
"Gemfile",
|
24
25
|
"Gemfile.lock",
|
25
26
|
"LICENSE.txt",
|
@@ -47,32 +48,20 @@ Gem::Specification.new do |s|
|
|
47
48
|
|
48
49
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
50
|
s.add_runtime_dependency(%q<puppet>, [">= 3.8"])
|
50
|
-
s.
|
51
|
+
s.add_runtime_dependency(%q<facterdb>, [">= 0"])
|
51
52
|
s.add_development_dependency(%q<pry>, [">= 0"])
|
52
53
|
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
53
|
-
s.add_development_dependency(%q<bundler>, [">= 0"])
|
54
|
-
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
55
|
-
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
56
|
-
s.add_development_dependency(%q<rake>, [">= 0"])
|
57
54
|
else
|
58
55
|
s.add_dependency(%q<puppet>, [">= 3.8"])
|
59
|
-
s.add_dependency(%q<
|
56
|
+
s.add_dependency(%q<facterdb>, [">= 0"])
|
60
57
|
s.add_dependency(%q<pry>, [">= 0"])
|
61
58
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
62
|
-
s.add_dependency(%q<bundler>, [">= 0"])
|
63
|
-
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
64
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
65
|
-
s.add_dependency(%q<rake>, [">= 0"])
|
66
59
|
end
|
67
60
|
else
|
68
61
|
s.add_dependency(%q<puppet>, [">= 3.8"])
|
69
|
-
s.add_dependency(%q<
|
62
|
+
s.add_dependency(%q<facterdb>, [">= 0"])
|
70
63
|
s.add_dependency(%q<pry>, [">= 0"])
|
71
64
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
72
|
-
s.add_dependency(%q<bundler>, [">= 0"])
|
73
|
-
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
74
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
75
|
-
s.add_dependency(%q<rake>, [">= 0"])
|
76
65
|
end
|
77
66
|
end
|
78
67
|
|
data/spec/puppet-repl_spec.rb
CHANGED
@@ -14,7 +14,7 @@ describe "PuppetRepl" do
|
|
14
14
|
'help'
|
15
15
|
end
|
16
16
|
it 'can show the help screen' do
|
17
|
-
repl_output = "Ruby Version: #{RUBY_VERSION}\nPuppet Version: 4.3.2\nPuppet Repl Version: 0.0.
|
17
|
+
repl_output = "Ruby Version: #{RUBY_VERSION}\nPuppet Version: 4.3.2\nPuppet Repl Version: 0.0.3\nCreated by: NWOps <corey@nwops.io>\nType \"exit\", \"functions\", \"types\", \"reset\", \"help\" for more information.\n\n"
|
18
18
|
expect{repl.handle_input(input)}.to output(repl_output).to_stdout
|
19
19
|
end
|
20
20
|
end
|
@@ -64,7 +64,6 @@ describe "PuppetRepl" do
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
|
68
67
|
describe 'each block' do
|
69
68
|
let(:input) do
|
70
69
|
"['/tmp/test3', '/tmp/test4'].each |String $path| { file{$path: ensure => present} }"
|
@@ -74,4 +73,23 @@ describe "PuppetRepl" do
|
|
74
73
|
expect{repl.handle_input(input)}.to output(repl_output).to_stdout
|
75
74
|
end
|
76
75
|
end
|
76
|
+
|
77
|
+
describe 'facts' do
|
78
|
+
let(:input) do
|
79
|
+
"$::fqdn"
|
80
|
+
end
|
81
|
+
it 'should be able to resolve fqdn' do
|
82
|
+
repl_output = " => foo.example.com\n"
|
83
|
+
expect{repl.handle_input(input)}.to output(repl_output).to_stdout
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'print facts' do
|
88
|
+
let(:input) do
|
89
|
+
"facts"
|
90
|
+
end
|
91
|
+
it 'should be able to print facts' do
|
92
|
+
expect{repl.handle_input(input)}.to output(/"kernel": "Linux"/).to_stdout
|
93
|
+
end
|
94
|
+
end
|
77
95
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/support_spec.rb
CHANGED
@@ -31,13 +31,16 @@ describe 'support' do
|
|
31
31
|
|
32
32
|
it 'should return lib dirs' do
|
33
33
|
expect(repl.lib_dirs.count).to be >= 1
|
34
|
-
|
35
|
-
|
36
34
|
end
|
37
35
|
|
38
36
|
it 'should return module dirs' do
|
39
37
|
expect(repl.module_dirs.count).to be >= 1
|
38
|
+
end
|
40
39
|
|
40
|
+
it 'should return a list of facts' do
|
41
|
+
expect(repl.facts).to be_instance_of(Hash)
|
42
|
+
expect(repl.facts[:fqdn]).to eq('foo.example.com')
|
41
43
|
end
|
42
44
|
|
45
|
+
|
43
46
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-repl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Corey Osman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puppet
|
@@ -25,13 +25,13 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.8'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: facterdb
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
|
-
type: :
|
34
|
+
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
@@ -66,62 +66,6 @@ dependencies:
|
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.12'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: bundler
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - '>='
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - '>='
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: jeweler
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ~>
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 2.0.1
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ~>
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 2.0.1
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: simplecov
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - '>='
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - '>='
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: rake
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - '>='
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - '>='
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
69
|
description: A interactive command line tool for evaluating the puppet language
|
126
70
|
email: corey@nwops.io
|
127
71
|
executables:
|
@@ -133,6 +77,7 @@ extra_rdoc_files:
|
|
133
77
|
files:
|
134
78
|
- .document
|
135
79
|
- .rspec
|
80
|
+
- .travis.yml
|
136
81
|
- Gemfile
|
137
82
|
- Gemfile.lock
|
138
83
|
- LICENSE.txt
|