onceover-lookup 0.1.0 → 0.1.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/lib/onceover/lookup/cli.rb +1 -1
- data/lib/onceover/lookup/lookup.rb +72 -39
- data/lib/onceover/lookup/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23e3381ff67b431966f5eda0d964fffc58ce890c41a837cf129f664bea571544
|
4
|
+
data.tar.gz: 1ebe6755ee36b60d59c14ee8f23ea7d196b9afe1386b3467b694994c527500ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 644d575c15a0b764a80b37ab78c91254232cfa62190400d7c1726b51ad8849c6f2af732eac38932b1bd864325d18ca4af49e363cce4b5dec125fc17eb7f086c0
|
7
|
+
data.tar.gz: 9e1f2f741915e2ff7e97a4a9c53104615277f15f996c6e3d052bab3bb7a1e2a89c2049912b54cfe54c4cdf79b7e8b13ce0ca995f9703049f1b3035eaefd415f7
|
data/lib/onceover/lookup/cli.rb
CHANGED
@@ -9,7 +9,7 @@ class Onceover
|
|
9
9
|
@cmd ||= Cri::Command.define do
|
10
10
|
name 'lookup'
|
11
11
|
usage 'lookup [--name NAME]'
|
12
|
-
summary "
|
12
|
+
summary "Do a hiera lookup"
|
13
13
|
description <<-DESCRIPTION
|
14
14
|
Run the `puppet lookup` command to use onceover configuration
|
15
15
|
DESCRIPTION
|
@@ -5,8 +5,9 @@ require "json"
|
|
5
5
|
class Onceover
|
6
6
|
module Lookup
|
7
7
|
module Lookup
|
8
|
-
PUPPET_CONF
|
9
|
-
LOOKUP_TMP_DIR
|
8
|
+
PUPPET_CONF = ".puppet.conf.onceover"
|
9
|
+
LOOKUP_TMP_DIR = ".onceover/tmp"
|
10
|
+
ENVIRONMENT_CONF = ".onceover/etc/puppetlabs/code/environments/production/environment.conf"
|
10
11
|
|
11
12
|
# Figure out what hiera.yaml we should be using. If there isn't a custom
|
12
13
|
# one, then fallback to the per-environment one. We don't care if this
|
@@ -46,53 +47,85 @@ class Onceover
|
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
49
|
-
def self.
|
50
|
-
|
51
|
-
|
52
|
-
# relative path - use this
|
53
|
-
input_factset = factset
|
54
|
-
else
|
55
|
-
# resolve factset from Onceover's built-in facts
|
56
|
-
# https://stackoverflow.com/a/10083594/3441106
|
57
|
-
spec = Gem::Specification.find_by_name("onceover")
|
58
|
-
gem_root = spec.gem_dir
|
59
|
-
|
60
|
-
input_factset = File.join(gem_root, "factsets", "#{factset}.json")
|
61
|
-
end
|
50
|
+
def self.fix_environment_conf
|
51
|
+
environment_conf = File.readlines(ENVIRONMENT_CONF)
|
52
|
+
environment_conf_clean = environment_conf.reject { |e| e =~ /^config_version/ }
|
62
53
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
# must give file extension or puppet will:
|
68
|
-
# Error: Could not parse application options: undefined method `[]' for nil:NilClass
|
69
|
-
factset_tempfile = Tempfile.new(["facts", ".json"])
|
70
|
-
factset_tempfile.write(data_hash["values"].to_json)
|
71
|
-
factset_tempfile.close
|
72
|
-
rescue Errno::ENOENT => e
|
73
|
-
raise("File not found reading: #{input_factset}: #{e.message}")
|
54
|
+
if environment_conf != environment_conf_clean
|
55
|
+
File.open(ENVIRONMENT_CONF, "w") do |f|
|
56
|
+
f.puts(environment_conf_clean)
|
74
57
|
end
|
75
|
-
else
|
76
|
-
input_factset = nil
|
77
58
|
end
|
59
|
+
end
|
78
60
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
cmd += " --facts #{factset_tempfile.path}"
|
61
|
+
def self.check_setup
|
62
|
+
status = true
|
63
|
+
if ! File.exist? PUPPET_CONF
|
64
|
+
logger.error "#{PUPPET_CONF} does not exist, please run `onceover run lookup setup` to create it"
|
65
|
+
status = false
|
85
66
|
end
|
86
67
|
|
87
|
-
if !
|
88
|
-
logger.
|
89
|
-
|
68
|
+
if ! File.exist? ENVIRONMENT_CONF
|
69
|
+
logger.error "#{ENVIRONMENT_CONF} does not exist, please run `onceover run spec ...` to create it"
|
70
|
+
status = false
|
90
71
|
end
|
91
72
|
|
92
|
-
|
93
|
-
system(cmd)
|
73
|
+
status
|
94
74
|
end
|
95
75
|
|
76
|
+
def self.run(passthru, factset)
|
77
|
+
if check_setup
|
78
|
+
if factset
|
79
|
+
if factset.include? "/"
|
80
|
+
# relative path - use this
|
81
|
+
input_factset = factset
|
82
|
+
else
|
83
|
+
# resolve factset from Onceover's built-in facts
|
84
|
+
# https://stackoverflow.com/a/10083594/3441106
|
85
|
+
spec = Gem::Specification.find_by_name("onceover")
|
86
|
+
gem_root = spec.gem_dir
|
87
|
+
|
88
|
+
input_factset = File.join(gem_root, "factsets", "#{factset}.json")
|
89
|
+
end
|
90
|
+
|
91
|
+
logger.info "Extracting factset #{factset}..."
|
92
|
+
begin
|
93
|
+
data_hash = JSON.parse(File.read(input_factset))
|
94
|
+
|
95
|
+
# must give file extension or puppet will:
|
96
|
+
# Error: Could not parse application options: undefined method `[]' for nil:NilClass
|
97
|
+
factset_tempfile = Tempfile.new(["facts", ".json"])
|
98
|
+
factset_tempfile.write(data_hash["values"].to_json)
|
99
|
+
factset_tempfile.close
|
100
|
+
rescue Errno::ENOENT => e
|
101
|
+
raise("File not found reading: #{input_factset}: #{e.message}")
|
102
|
+
end
|
103
|
+
else
|
104
|
+
input_factset = nil
|
105
|
+
end
|
106
|
+
|
107
|
+
# Fix environment.conf on windows by removing any `config_version`
|
108
|
+
# since the script cant run on windows it errors the whole run. Do this
|
109
|
+
# on all platforms since it does nothing useful on Linux either
|
110
|
+
fix_environment_conf
|
111
|
+
|
112
|
+
cmd = "bundle exec puppet lookup --config #{PUPPET_CONF} #{passthru}"
|
113
|
+
if input_factset
|
114
|
+
if passthru =~ /--facts/
|
115
|
+
raise "You cannot specify both `--facts` and `--factsets`"
|
116
|
+
end
|
117
|
+
cmd += " --facts #{factset_tempfile.path}"
|
118
|
+
end
|
119
|
+
|
120
|
+
if ! Dir.exist? LOOKUP_TMP_DIR
|
121
|
+
logger.info "creating #{LOOKUP_TMP_DIR}"
|
122
|
+
FileUtils.mkdir_p LOOKUP_TMP_DIR
|
123
|
+
end
|
124
|
+
|
125
|
+
logger.info "running command: #{cmd}"
|
126
|
+
system(cmd)
|
127
|
+
end
|
128
|
+
end
|
96
129
|
end
|
97
130
|
end
|
98
131
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onceover-lookup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Declarative Systems
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|