smart_proxy_ansible 3.0.1 → 3.1.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 +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 +19 -16
- data/lib/smart_proxy_ansible/plugin.rb +1 -5
- data/lib/smart_proxy_ansible/roles_reader.rb +50 -24
- data/lib/smart_proxy_ansible/version.rb +1 -1
- metadata +9 -39
- 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: 723f4dc74c428f9eb0d34bda1f492e8b5e49eb2103f16ccb36b279db8dfb3045
|
4
|
+
data.tar.gz: 553c1a6918b5f345d7017fe9ce691bffed6903c7d1e5fdbcbe5905a863e70542
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bde47200bda54b10495128b81a19f3f6471f1c9142e034537df43e6d8b6badfcf7685a59923d5bc008263231a64d414ab5c6aecb4f0adf3342f3dfb300a35d1
|
7
|
+
data.tar.gz: 6793a645db2e1e1ac75d1136cfa5e10285a2fb6b100d97b7a67613e7e4cac504f0154b398ed066f9ea17cb8f65589a8b76df60fece50764a9bb658c9181d145a
|
data/README.md
CHANGED
File without changes
|
@@ -13,34 +13,37 @@ 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|
|
42
38
|
variables[role_name] ||= VariablesExtractor
|
43
|
-
|
39
|
+
.extract_variables("#{path}/ansible_collections/#{role_name_parts[0]}/#{role_name_parts[1]}/roles/#{role_name_parts[2]}")
|
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
|
44
47
|
end
|
45
48
|
end
|
46
49
|
variables
|
@@ -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
|
|
@@ -7,18 +7,31 @@ module Proxy
|
|
7
7
|
class << self
|
8
8
|
DEFAULT_CONFIG_FILE = '/etc/ansible/ansible.cfg'.freeze
|
9
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
|
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: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Nečas
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-05-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -17,28 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '13.0'
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
|
-
name: minitest
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- - "~>"
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '0'
|
35
|
-
type: :development
|
36
|
-
prerelease: false
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - "~>"
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: '0'
|
27
|
+
version: '13.0'
|
42
28
|
- !ruby/object:Gem::Dependency
|
43
29
|
name: mocha
|
44
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,14 +45,14 @@ dependencies:
|
|
59
45
|
requirements:
|
60
46
|
- - "~>"
|
61
47
|
- !ruby/object:Gem::Version
|
62
|
-
version: '
|
48
|
+
version: '3'
|
63
49
|
type: :development
|
64
50
|
prerelease: false
|
65
51
|
version_requirements: !ruby/object:Gem::Requirement
|
66
52
|
requirements:
|
67
53
|
- - "~>"
|
68
54
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
55
|
+
version: '3'
|
70
56
|
- !ruby/object:Gem::Dependency
|
71
57
|
name: rack-test
|
72
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,20 +67,6 @@ dependencies:
|
|
81
67
|
- - "~>"
|
82
68
|
- !ruby/object:Gem::Version
|
83
69
|
version: '0'
|
84
|
-
- !ruby/object:Gem::Dependency
|
85
|
-
name: rubocop
|
86
|
-
requirement: !ruby/object:Gem::Requirement
|
87
|
-
requirements:
|
88
|
-
- - '='
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version: 0.32.1
|
91
|
-
type: :development
|
92
|
-
prerelease: false
|
93
|
-
version_requirements: !ruby/object:Gem::Requirement
|
94
|
-
requirements:
|
95
|
-
- - '='
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: 0.32.1
|
98
70
|
- !ruby/object:Gem::Dependency
|
99
71
|
name: logger
|
100
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -149,8 +121,7 @@ extra_rdoc_files:
|
|
149
121
|
files:
|
150
122
|
- LICENSE
|
151
123
|
- README.md
|
152
|
-
-
|
153
|
-
- bundler.plugins.d/smart_proxy_ansible.rb
|
124
|
+
- bundler.d/ansible.rb
|
154
125
|
- lib/smart_proxy_ansible.rb
|
155
126
|
- lib/smart_proxy_ansible/api.rb
|
156
127
|
- lib/smart_proxy_ansible/exception.rb
|
@@ -172,15 +143,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
172
143
|
requirements:
|
173
144
|
- - ">="
|
174
145
|
- !ruby/object:Gem::Version
|
175
|
-
version: '
|
146
|
+
version: '2.5'
|
176
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
148
|
requirements:
|
178
149
|
- - ">="
|
179
150
|
- !ruby/object:Gem::Version
|
180
151
|
version: '0'
|
181
152
|
requirements: []
|
182
|
-
|
183
|
-
rubygems_version: 2.6.14
|
153
|
+
rubygems_version: 3.1.2
|
184
154
|
signing_key:
|
185
155
|
specification_version: 4
|
186
156
|
summary: Smart-Proxy Ansible plugin
|