smart_proxy_acd_core 0.0.1 → 0.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 +4 -4
- data/lib/smart_proxy_acd_core/acd_runner.rb +43 -18
- data/lib/smart_proxy_acd_core/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: 215b06ad56d650035cdc4079ee6fcad40333f619366e9be8d4bc8c9451b9a207
|
4
|
+
data.tar.gz: 295fd6ae912f62f4dddc0e59fda3afb9b72c9e059df33dd7fc46878185b07996
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6812cf3394f08d4d184841043ea653e7fe1bd4d59c39b7726c356667061975af4262383f9dc0d3d577093c65da44f849281d4f547f7b70003ba13465cdfdb6a5
|
7
|
+
data.tar.gz: e5bab31f198a74744bab097dac0426928855e7d38e77248b72dea2b81c1d9426593a344e9103e6e85308ae2a637bad3ccbcc9cdffa0bb153ab8e765a07affaad
|
@@ -3,13 +3,14 @@ require 'tempfile'
|
|
3
3
|
require 'rest-client'
|
4
4
|
require 'tmpdir'
|
5
5
|
|
6
|
+
# rubocop:disable ClassLength
|
7
|
+
|
6
8
|
module SmartProxyAcdCore
|
7
9
|
# Implements the AcdRunner to be used by foreman_remote_execution
|
8
10
|
class AcdRunner < ForemanTasksCore::Runner::CommandRunner
|
9
11
|
DEFAULT_REFRESH_INTERVAL = 1
|
10
12
|
|
11
13
|
class << self
|
12
|
-
|
13
14
|
def parse_dynflow_settings(path)
|
14
15
|
return @dynflow_settings if defined? @dynflow_settings
|
15
16
|
if File.exist?(path)
|
@@ -52,8 +53,8 @@ module SmartProxyAcdCore
|
|
52
53
|
|
53
54
|
def get_playbook(playbook_id)
|
54
55
|
logger.debug("Get playbook with id #{playbook_id}")
|
55
|
-
response = playbook_resource(playbook_id).get
|
56
|
-
if response.code.to_s !=
|
56
|
+
response = playbook_resource(playbook_id).get
|
57
|
+
if response.code.to_s != '200'
|
57
58
|
raise "Failed performing callback to Foreman server: #{response.code} #{response.body}"
|
58
59
|
end
|
59
60
|
tmp_file = Tempfile.new.path
|
@@ -68,17 +69,17 @@ module SmartProxyAcdCore
|
|
68
69
|
end
|
69
70
|
|
70
71
|
def store_playbook
|
71
|
-
logger.debug(
|
72
|
+
logger.debug('Unpack ansible playbook')
|
72
73
|
dir = Dir.mktmpdir
|
73
|
-
raise
|
74
|
+
raise 'Could not create temporary directory to run ansible playbook' if dir.nil? || !Dir.exist?(dir)
|
74
75
|
command = "base64 -d #{@playbook_tmp_base64_file} | tar xz -C #{dir}"
|
75
76
|
system(command)
|
76
77
|
@playbook_tmp_dir = dir
|
77
78
|
end
|
78
79
|
|
79
80
|
def cleanup
|
80
|
-
File.unlink(@playbook_tmp_base64_file) if File.
|
81
|
-
FileUtils.rm_rf(@playbook_tmp_dir) if Dir.
|
81
|
+
File.unlink(@playbook_tmp_base64_file) if File.exist?(@playbook_tmp_base64_file)
|
82
|
+
FileUtils.rm_rf(@playbook_tmp_dir) if Dir.exist?(@playbook_tmp_dir)
|
82
83
|
end
|
83
84
|
|
84
85
|
def start
|
@@ -89,13 +90,13 @@ module SmartProxyAcdCore
|
|
89
90
|
store_playbook
|
90
91
|
|
91
92
|
@playbook_path = File.join(@playbook_tmp_dir, @playbook_file)
|
92
|
-
raise "Could not run playbook: playbook file #{@playbook_file} not found in playbook dir #{@playbook_tmp_dir}" unless File.
|
93
|
+
raise "Could not run playbook: playbook file #{@playbook_file} not found in playbook dir #{@playbook_tmp_dir}" unless File.exist?(@playbook_path)
|
93
94
|
|
94
|
-
publish_data(
|
95
|
+
publish_data('Write temporary inventory', 'stdout')
|
95
96
|
write_inventory
|
96
97
|
|
97
98
|
command = generate_command
|
98
|
-
logger.debug("Running command
|
99
|
+
logger.debug("Running command #{command.join(' ')}")
|
99
100
|
initialize_command(*command)
|
100
101
|
end
|
101
102
|
|
@@ -113,7 +114,7 @@ module SmartProxyAcdCore
|
|
113
114
|
private
|
114
115
|
|
115
116
|
def parse_acd_job
|
116
|
-
@acd_job = YAML.
|
117
|
+
@acd_job = YAML.safe_load(@options['script'])
|
117
118
|
@application_name = @acd_job['application_name']
|
118
119
|
@playbook_id = @acd_job['playbook_id']
|
119
120
|
@playbook_file = @acd_job['playbook_file']
|
@@ -131,25 +132,49 @@ module SmartProxyAcdCore
|
|
131
132
|
end
|
132
133
|
|
133
134
|
def environment
|
134
|
-
env={}
|
135
|
+
env = {}
|
135
136
|
env['ANSIBLE_CALLBACK_WHITELIST'] = ''
|
136
137
|
env['ANSIBLE_LOAD_CALLBACK_PLUGINS'] = '0'
|
137
138
|
env
|
138
139
|
end
|
139
140
|
|
141
|
+
def setup_verbosity
|
142
|
+
verbosity = ''
|
143
|
+
if @acd_job['verbose']
|
144
|
+
verbosity_level = @acd_job['verbose'].split(' ').first.to_i
|
145
|
+
if verbosity_level.positive?
|
146
|
+
verbosity = '-'
|
147
|
+
verbosity_level.times do
|
148
|
+
verbosity += 'v'
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
verbosity
|
153
|
+
end
|
154
|
+
|
155
|
+
def valid_tags(tag)
|
156
|
+
re = /^\w+(\s*,\s*\w+)*$/
|
157
|
+
return true if @acd_job[tag] && @acd_job[tag].match?(re)
|
158
|
+
end
|
159
|
+
|
140
160
|
def generate_command
|
141
161
|
logger.debug("Generate command with #{@inventory_path} to run #{@playbook_id} with path #{@playbook_path}")
|
142
162
|
command = [environment]
|
143
|
-
command <<
|
144
|
-
command <<
|
163
|
+
command << 'ansible-playbook'
|
164
|
+
command << '-i'
|
145
165
|
command << @inventory_path
|
146
|
-
|
147
|
-
|
148
|
-
|
166
|
+
verbose = setup_verbosity
|
167
|
+
command << verbose unless verbose.empty?
|
168
|
+
command << "--tags '#{@acd_job['tags']}'" if valid_tags('tags')
|
169
|
+
command << "--skip-tags '#{@acd_job['skip_tags']}'" if valid_tags('skip_tags')
|
170
|
+
if @acd_job.key?('extra_vars') && !@acd_job['extra_vars'].nil? && !@acd_job['extra_vars'].empty?
|
171
|
+
command << '--extra-vars'
|
149
172
|
command << "'#{@acd_job['extra_vars']}'"
|
150
173
|
end
|
151
|
-
command <<
|
174
|
+
command << @playbook_path.to_s
|
152
175
|
command
|
153
176
|
end
|
154
177
|
end
|
155
178
|
end
|
179
|
+
|
180
|
+
# rubocop:enable ClassLength
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_proxy_acd_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernhard suttner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: foreman-tasks-core
|