smart_proxy_ansible 2.1.2 → 3.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 +5 -5
- data/README.md +4 -0
- data/{bundler.plugins.d/smart_proxy_ansible.rb → bundler.d/ansible.rb} +0 -0
- data/lib/smart_proxy_ansible/api.rb +21 -15
- data/lib/smart_proxy_ansible/plugin.rb +1 -5
- data/lib/smart_proxy_ansible/roles_reader.rb +51 -25
- data/lib/smart_proxy_ansible/variables_extractor.rb +2 -2
- data/lib/smart_proxy_ansible/version.rb +1 -1
- metadata +9 -53
- data/bin/json_inventory.sh +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8c78dd643ea513a8ffc694a01c86f12495aff1e1b14c7e106db9d29ab529d26d
|
4
|
+
data.tar.gz: 8b2fde1a83bf65fb55fc122ce8ff931fd314f5289f9cf34e255d85959bebb653
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 695b0b451cc16439fd4fb76f9567f49e971c609c6d4696c19afa5feb3b90ac6a069e392ce38b177111041cae577662683cb6f594e86adc1096a6bfb5d7ac7ccc
|
7
|
+
data.tar.gz: 94a5bac7bce83785b0cc9067e9ffd20e9084e8befd575c3f6fae7da5ac7e78b202bf137daa36e6e726a8fd54de190180e42ac1af96ff6b2fcb1b9381364f2a59
|
data/README.md
CHANGED
File without changes
|
@@ -13,32 +13,38 @@ module Proxy
|
|
13
13
|
get '/roles/variables' do
|
14
14
|
variables = {}
|
15
15
|
RolesReader.list_roles.each do |role_name|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
logger.error e
|
21
|
-
end
|
16
|
+
variables.merge!(extract_variables(role_name))
|
17
|
+
rescue ReadVariablesException => e
|
18
|
+
# skip what cannot be parsed
|
19
|
+
logger.error e
|
22
20
|
end
|
23
21
|
variables.to_json
|
24
22
|
end
|
25
23
|
|
26
24
|
get '/roles/:role_name/variables' do |role_name|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
{}.to_json
|
32
|
-
end
|
25
|
+
extract_variables(role_name).to_json
|
26
|
+
rescue ReadVariablesException => e
|
27
|
+
logger.error e
|
28
|
+
{}.to_json
|
33
29
|
end
|
34
30
|
|
35
31
|
private
|
36
32
|
|
37
33
|
def extract_variables(role_name)
|
38
34
|
variables = {}
|
39
|
-
|
40
|
-
|
41
|
-
|
35
|
+
role_name_parts = role_name.split('.')
|
36
|
+
if role_name_parts.count == 3
|
37
|
+
RolesReader.collections_paths.split(':').each do |path|
|
38
|
+
variables[role_name] = VariablesExtractor
|
39
|
+
.extract_variables("#{path}/ansible_collections/#{role_name_parts[0]}/#{role_name_parts[1]}/roles/#{role_name_parts[2]}") if variables[role_name].nil? || variables[role_name].empty?
|
40
|
+
end
|
41
|
+
else
|
42
|
+
RolesReader.roles_path.split(':').each do |path|
|
43
|
+
role_path = "#{path}/#{role_name}"
|
44
|
+
if File.directory?(role_path)
|
45
|
+
variables[role_name] ||= VariablesExtractor.extract_variables(role_path)
|
46
|
+
end
|
47
|
+
end
|
42
48
|
end
|
43
49
|
variables
|
44
50
|
end
|
@@ -2,11 +2,7 @@ module Proxy
|
|
2
2
|
module Ansible
|
3
3
|
# Calls for the smart-proxy API to register the plugin
|
4
4
|
class Plugin < Proxy::Plugin
|
5
|
-
|
6
|
-
File.expand_path('../', __FILE__))
|
7
|
-
https_rackup_path File.expand_path('http_config.ru',
|
8
|
-
File.expand_path('../', __FILE__))
|
9
|
-
|
5
|
+
rackup_path File.expand_path('http_config.ru', __dir__)
|
10
6
|
settings_file 'ansible.yml'
|
11
7
|
plugin :ansible, Proxy::Ansible::VERSION
|
12
8
|
|
@@ -6,19 +6,32 @@ module Proxy
|
|
6
6
|
class RolesReader
|
7
7
|
class << self
|
8
8
|
DEFAULT_CONFIG_FILE = '/etc/ansible/ansible.cfg'.freeze
|
9
|
-
DEFAULT_ROLES_PATH = '/etc/ansible/roles'.freeze
|
9
|
+
DEFAULT_ROLES_PATH = '/etc/ansible/roles:/usr/share/ansible/roles'.freeze
|
10
|
+
DEFAULT_COLLECTIONS_PATHS = '/etc/ansible/collections:/usr/share/ansible/collections'.freeze
|
10
11
|
|
11
12
|
def list_roles
|
12
|
-
roles_path.split(':').map { |path| read_roles(path) }.flatten
|
13
|
+
roles = roles_path.split(':').map { |path| read_roles(path) }.flatten
|
14
|
+
collection_roles = collections_paths.split(':').map { |path| read_collection_roles(path) }.flatten
|
15
|
+
roles + collection_roles
|
13
16
|
end
|
14
17
|
|
15
|
-
def roles_path
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
def roles_path
|
19
|
+
config_path(path_from_config('roles_path'), DEFAULT_ROLES_PATH)
|
20
|
+
end
|
21
|
+
|
22
|
+
def collections_paths
|
23
|
+
config_path(path_from_config('collections_paths'), DEFAULT_COLLECTIONS_PATHS)
|
24
|
+
end
|
25
|
+
|
26
|
+
def config_path(config_line, default)
|
27
|
+
# Default to /etc/ansible/roles if config_line is empty
|
28
|
+
return default if config_line.empty?
|
29
|
+
|
30
|
+
config_line_key = config_line.first.split('=').first.strip
|
31
|
+
# In case of commented roles_path key "#roles_path" or #collections_paths, return default
|
32
|
+
return default if ['#roles_path', '#collections_paths'].include?(config_line_key)
|
33
|
+
|
34
|
+
config_line.first.split('=').last.strip
|
22
35
|
end
|
23
36
|
|
24
37
|
def logger
|
@@ -34,30 +47,43 @@ module Proxy
|
|
34
47
|
private
|
35
48
|
|
36
49
|
def read_roles(roles_path)
|
37
|
-
|
38
|
-
|
39
|
-
Dir.glob("#{roles_path}/*").map do |path|
|
40
|
-
path.split('/').last
|
41
|
-
end
|
50
|
+
glob_path("#{roles_path}/*").map do |path|
|
51
|
+
path.split('/').last
|
42
52
|
end
|
53
|
+
rescue Errno::ENOENT, Errno::EACCES => e
|
54
|
+
logger.debug(e.backtrace)
|
55
|
+
message = "Could not read Ansible roles #{roles_path} - #{e.message}"
|
56
|
+
raise ReadRolesException.new(message), message
|
57
|
+
end
|
58
|
+
|
59
|
+
def glob_path(path)
|
60
|
+
Dir.glob path
|
61
|
+
|
43
62
|
end
|
44
63
|
|
45
|
-
def
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
64
|
+
def read_collection_roles(collections_path)
|
65
|
+
Dir.glob("#{collections_path}/ansible_collections/*/*/roles/*").map do |path|
|
66
|
+
parts = path.split('/')
|
67
|
+
role = parts.pop
|
68
|
+
parts.pop
|
69
|
+
collection = parts.pop
|
70
|
+
author = parts.pop
|
71
|
+
"#{author}.#{collection}.#{role}"
|
51
72
|
end
|
73
|
+
rescue Errno::ENOENT, Errno::EACCES => e
|
74
|
+
logger.debug(e.backtrace)
|
75
|
+
message = "Could not read Ansible roles #{collections_path} - #{e.message}"
|
76
|
+
raise ReadRolesException.new(message), message
|
52
77
|
end
|
53
78
|
|
54
|
-
def
|
55
|
-
|
79
|
+
def path_from_config(config_key)
|
80
|
+
File.readlines(DEFAULT_CONFIG_FILE).select do |line|
|
81
|
+
line =~ /^\s*#{config_key}/
|
82
|
+
end
|
56
83
|
rescue Errno::ENOENT, Errno::EACCES => e
|
57
84
|
logger.debug(e.backtrace)
|
58
|
-
|
59
|
-
|
60
|
-
raise exception.new(exception_message), exception_message
|
85
|
+
message = "Could not read Ansible config file #{DEFAULT_CONFIG_FILE} - #{e.message}"
|
86
|
+
raise ReadConfigFileException.new(message), message
|
61
87
|
end
|
62
88
|
end
|
63
89
|
end
|
@@ -8,7 +8,7 @@ module Proxy
|
|
8
8
|
def extract_variables(role_path)
|
9
9
|
role_files = Dir.glob("#{role_path}/defaults/**/*.yml") +
|
10
10
|
Dir.glob("#{role_path}/defaults/**/*.yaml")
|
11
|
-
role_files.
|
11
|
+
role_files.reduce({}) do |memo, role_file|
|
12
12
|
loaded_yaml = {}
|
13
13
|
begin
|
14
14
|
loaded_yaml = YAML.load_file(role_file)
|
@@ -16,7 +16,7 @@ module Proxy
|
|
16
16
|
raise ReadVariablesException.new "#{role_file} is not YAML file"
|
17
17
|
end
|
18
18
|
raise ReadVariablesException.new "Could not parse YAML file: #{role_file}" unless loaded_yaml.is_a? Hash
|
19
|
-
loaded_yaml
|
19
|
+
memo.merge loaded_yaml
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_proxy_ansible
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Nečas
|
@@ -9,50 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-08-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: bundler
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - "~>"
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '1.7'
|
21
|
-
type: :development
|
22
|
-
prerelease: false
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - "~>"
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: '1.7'
|
28
14
|
- !ruby/object:Gem::Dependency
|
29
15
|
name: rake
|
30
16
|
requirement: !ruby/object:Gem::Requirement
|
31
17
|
requirements:
|
32
18
|
- - "~>"
|
33
19
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
35
|
-
type: :development
|
36
|
-
prerelease: false
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - "~>"
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: '10.0'
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: minitest
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
45
|
-
requirements:
|
46
|
-
- - "~>"
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: '0'
|
20
|
+
version: '13.0'
|
49
21
|
type: :development
|
50
22
|
prerelease: false
|
51
23
|
version_requirements: !ruby/object:Gem::Requirement
|
52
24
|
requirements:
|
53
25
|
- - "~>"
|
54
26
|
- !ruby/object:Gem::Version
|
55
|
-
version: '0'
|
27
|
+
version: '13.0'
|
56
28
|
- !ruby/object:Gem::Dependency
|
57
29
|
name: mocha
|
58
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,14 +45,14 @@ dependencies:
|
|
73
45
|
requirements:
|
74
46
|
- - "~>"
|
75
47
|
- !ruby/object:Gem::Version
|
76
|
-
version: '
|
48
|
+
version: '3'
|
77
49
|
type: :development
|
78
50
|
prerelease: false
|
79
51
|
version_requirements: !ruby/object:Gem::Requirement
|
80
52
|
requirements:
|
81
53
|
- - "~>"
|
82
54
|
- !ruby/object:Gem::Version
|
83
|
-
version: '
|
55
|
+
version: '3'
|
84
56
|
- !ruby/object:Gem::Dependency
|
85
57
|
name: rack-test
|
86
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,20 +67,6 @@ dependencies:
|
|
95
67
|
- - "~>"
|
96
68
|
- !ruby/object:Gem::Version
|
97
69
|
version: '0'
|
98
|
-
- !ruby/object:Gem::Dependency
|
99
|
-
name: rubocop
|
100
|
-
requirement: !ruby/object:Gem::Requirement
|
101
|
-
requirements:
|
102
|
-
- - '='
|
103
|
-
- !ruby/object:Gem::Version
|
104
|
-
version: 0.32.1
|
105
|
-
type: :development
|
106
|
-
prerelease: false
|
107
|
-
version_requirements: !ruby/object:Gem::Requirement
|
108
|
-
requirements:
|
109
|
-
- - '='
|
110
|
-
- !ruby/object:Gem::Version
|
111
|
-
version: 0.32.1
|
112
70
|
- !ruby/object:Gem::Dependency
|
113
71
|
name: logger
|
114
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -163,8 +121,7 @@ extra_rdoc_files:
|
|
163
121
|
files:
|
164
122
|
- LICENSE
|
165
123
|
- README.md
|
166
|
-
-
|
167
|
-
- bundler.plugins.d/smart_proxy_ansible.rb
|
124
|
+
- bundler.d/ansible.rb
|
168
125
|
- lib/smart_proxy_ansible.rb
|
169
126
|
- lib/smart_proxy_ansible/api.rb
|
170
127
|
- lib/smart_proxy_ansible/exception.rb
|
@@ -186,15 +143,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
186
143
|
requirements:
|
187
144
|
- - ">="
|
188
145
|
- !ruby/object:Gem::Version
|
189
|
-
version: '
|
146
|
+
version: '2.5'
|
190
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
148
|
requirements:
|
192
149
|
- - ">="
|
193
150
|
- !ruby/object:Gem::Version
|
194
151
|
version: '0'
|
195
152
|
requirements: []
|
196
|
-
|
197
|
-
rubygems_version: 2.6.8
|
153
|
+
rubygems_version: 3.1.2
|
198
154
|
signing_key:
|
199
155
|
specification_version: 4
|
200
156
|
summary: Smart-Proxy Ansible plugin
|