foreman_acd 0.0.5 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +82 -27
- data/app/controllers/foreman_acd/ansible_playbooks_controller.rb +122 -0
- data/app/controllers/foreman_acd/api/v2/ansible_playbooks_controller.rb +71 -0
- data/app/controllers/foreman_acd/api/v2/app_definitions_controller.rb +1 -2
- data/app/controllers/foreman_acd/api/v2/app_instances_controller.rb +54 -0
- data/app/controllers/foreman_acd/api/v2/app_playbooks_controller.rb +0 -0
- data/app/controllers/foreman_acd/app_definitions_controller.rb +36 -4
- data/app/controllers/foreman_acd/app_instances_controller.rb +24 -90
- data/app/controllers/foreman_acd/concerns/ansible_playbook_parameters.rb +23 -0
- data/app/controllers/foreman_acd/concerns/app_definition_parameters.rb +1 -1
- data/app/controllers/foreman_acd/concerns/app_instance_parameters.rb +1 -1
- data/app/controllers/foreman_acd/remote_execution_controller.rb +49 -0
- data/app/controllers/ui_acd_controller.rb +11 -4
- data/app/models/foreman_acd/acd_provider.rb +27 -0
- data/app/models/foreman_acd/ansible_playbook.rb +50 -0
- data/app/models/foreman_acd/app_definition.rb +2 -1
- data/app/models/foreman_acd/app_instance.rb +7 -0
- data/app/services/foreman_acd/app_configurator.rb +57 -0
- data/app/services/foreman_acd/app_deployer.rb +139 -0
- data/app/services/foreman_acd/inventory_creator.rb +67 -0
- data/app/views/foreman_acd/ansible_playbooks/_form.html.erb +21 -0
- data/app/views/foreman_acd/ansible_playbooks/edit.html.erb +3 -0
- data/app/views/foreman_acd/ansible_playbooks/index.html.erb +30 -0
- data/app/views/foreman_acd/ansible_playbooks/new.html.erb +3 -0
- data/app/views/foreman_acd/api/v2/ansible_playbooks/base.json.rabl +3 -0
- data/app/views/foreman_acd/api/v2/ansible_playbooks/index.json.rabl +3 -0
- data/app/views/foreman_acd/api/v2/ansible_playbooks/show.json.rabl +3 -0
- data/app/views/foreman_acd/api/v2/app_definitions/base.json.rabl +3 -0
- data/app/views/foreman_acd/api/v2/app_definitions/index.json.rabl +3 -0
- data/app/views/foreman_acd/api/v2/app_definitions/show.json.rabl +3 -0
- data/app/views/foreman_acd/api/v2/app_instances/base.json.rabl +3 -0
- data/app/views/foreman_acd/api/v2/app_instances/index.json.rabl +3 -0
- data/app/views/foreman_acd/api/v2/app_instances/show.json.rabl +3 -0
- data/app/views/foreman_acd/app_definitions/_form.html.erb +25 -19
- data/app/views/foreman_acd/app_definitions/edit.html.erb +5 -0
- data/app/views/foreman_acd/app_definitions/import.html.erb +18 -0
- data/app/views/foreman_acd/app_definitions/index.html.erb +9 -5
- data/app/views/foreman_acd/app_instances/_form.html.erb +10 -8
- data/app/views/foreman_acd/app_instances/deploy.html.erb +19 -0
- data/app/views/foreman_acd/app_instances/index.html.erb +10 -5
- data/app/views/foreman_acd/app_instances/report.html.erb +19 -0
- data/app/views/templates/job/run_acd_ansible_playbook.erb +49 -0
- data/app/views/ui_acd/ansible_data.json.rabl +6 -0
- data/app/views/ui_acd/app.json.rabl +6 -2
- data/app/views/ui_acd/app_definition.json.rabl +1 -1
- data/app/views/ui_acd/{fdata.json.rabl → foreman_data.json.rabl} +1 -1
- data/config/routes.rb +36 -1
- data/db/migrate/20190610202252_create_app_definitions.rb +1 -3
- data/db/migrate/20190625140305_create_app_instances.rb +1 -1
- data/db/migrate/20200916091018_create_ansible_playbooks.rb +20 -0
- data/db/migrate/20200917120220_add_ansible_playbook_id.rb +14 -0
- data/db/migrate/20201016002819_add_ansible_vars_all_to_app_definitions.rb +5 -0
- data/db/migrate/20201016104338_add_ansible_vars_all_to_app_instances.rb +5 -0
- data/db/seeds.d/62_acd_proxy_feature.rb +6 -0
- data/db/seeds.d/75-job_templates.rb +8 -0
- data/lib/foreman_acd/engine.rb +7 -0
- data/lib/foreman_acd/plugin.rb +84 -13
- data/lib/foreman_acd/version.rb +1 -1
- data/package.json +1 -2
- data/webpack/components/ApplicationDefinition/ApplicationDefinition.js +378 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinition.scss +1 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionActions.js +295 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionConstants.js +14 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionHelper.js +26 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionReducer.js +243 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionSelectors.js +8 -0
- data/webpack/components/ApplicationDefinition/components/AnsiblePlaybookSelector.js +49 -0
- data/webpack/components/ApplicationDefinition/index.js +33 -0
- data/webpack/components/ApplicationInstance/ApplicationInstance.js +414 -0
- data/webpack/components/ApplicationInstance/ApplicationInstance.scss +11 -0
- data/webpack/components/ApplicationInstance/ApplicationInstanceActions.js +239 -0
- data/webpack/components/ApplicationInstance/ApplicationInstanceConstants.js +14 -0
- data/webpack/components/ApplicationInstance/ApplicationInstanceReducer.js +295 -0
- data/webpack/components/ApplicationInstance/ApplicationInstanceSelectors.js +9 -0
- data/webpack/components/ApplicationInstance/components/AppDefinitionSelector.js +49 -0
- data/webpack/components/ApplicationInstance/components/Service.js +30 -0
- data/webpack/components/ApplicationInstance/components/ServiceCounter.js +37 -0
- data/webpack/components/ApplicationInstance/index.js +35 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js +155 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.scss +27 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js +86 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportConstants.js +4 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js +52 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportSelectors.js +5 -0
- data/webpack/components/ApplicationInstanceReport/components/ReportViewer.js +26 -0
- data/webpack/components/ApplicationInstanceReport/index.js +27 -0
- data/webpack/components/ParameterSelection/ParameterSelection.js +121 -192
- data/webpack/components/ParameterSelection/ParameterSelection.scss +9 -0
- data/webpack/components/ParameterSelection/ParameterSelectionActions.js +80 -104
- data/webpack/components/ParameterSelection/ParameterSelectionConstants.js +15 -19
- data/webpack/components/ParameterSelection/ParameterSelectionHelper.js +3 -35
- data/webpack/components/ParameterSelection/ParameterSelectionReducer.js +116 -84
- data/webpack/components/ParameterSelection/ParameterSelectionSelectors.js +3 -7
- data/webpack/components/ParameterSelection/__fixtures__/parameterSelection.fixtures.js +12 -21
- data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionData_1.fixtures.js +1 -1
- data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionReducer.fixtures.js +3 -45
- data/webpack/components/ParameterSelection/__tests__/ParameterSelection.test.js +20 -0
- data/webpack/components/ParameterSelection/__tests__/ParameterSelectionReducer.test.js +22 -46
- data/webpack/components/ParameterSelection/__tests__/ParameterSelectionSelectors.test.js +6 -6
- data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelection.test.js.snap +40 -265
- data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionReducer.test.js.snap +11 -96
- data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionSelectors.test.js.snap +3 -9
- data/webpack/components/ParameterSelection/index.js +6 -8
- data/webpack/components/common/AddTableEntry.js +30 -0
- data/webpack/components/common/DeleteTableEntry.js +38 -0
- data/webpack/components/common/EasyHeaderFormatter.js +18 -0
- data/webpack/components/common/EditTableEntry.js +49 -0
- data/webpack/components/common/ExtSelect.js +43 -0
- data/webpack/components/common/LockTableEntry.js +59 -0
- data/webpack/components/common/RailsData.js +27 -0
- data/webpack/components/common/__tests__/AddTableEntry.test.js +26 -0
- data/webpack/components/common/__tests__/DeleteTableEntry.test.js +29 -0
- data/webpack/components/common/__tests__/ExtSelect.test.js +38 -0
- data/webpack/components/common/__tests__/RailsData.test.js +16 -0
- data/webpack/components/common/__tests__/__snapshots__/AddParameter.test.js.snap +35 -0
- data/webpack/components/common/__tests__/__snapshots__/AddTableEntry.test.js.snap +35 -0
- data/webpack/components/common/__tests__/__snapshots__/DeleteParameter.test.js.snap +41 -0
- data/webpack/components/common/__tests__/__snapshots__/DeleteTableEntry.test.js.snap +41 -0
- data/webpack/components/common/__tests__/__snapshots__/ExtSelect.test.js.snap +18 -0
- data/webpack/components/common/__tests__/__snapshots__/RailsData.test.js.snap +10 -0
- data/webpack/helper.js +20 -0
- data/webpack/index.js +6 -0
- data/webpack/reducer.js +43 -3
- metadata +91 -39
@@ -6,19 +6,15 @@ module ForemanAcd
|
|
6
6
|
include Foreman::Controller::AutoCompleteSearch
|
7
7
|
include ::ForemanAcd::Concerns::AppInstanceParameters
|
8
8
|
|
9
|
-
before_action :find_resource, :only => [:edit, :update, :destroy, :deploy]
|
9
|
+
before_action :find_resource, :only => [:edit, :update, :destroy, :deploy, :report]
|
10
|
+
before_action :read_applications, :only => [:new, :edit]
|
10
11
|
|
11
12
|
def index
|
12
13
|
@app_instances = resource_base.search_for(params[:search], :order => params[:order]).paginate(:page => params[:page])
|
13
14
|
end
|
14
15
|
|
15
|
-
def read_applications
|
16
|
-
@applications = ForemanAcd::AppDefinition.all.map { |elem| { elem.id => elem.name } }.reduce({}) { |h, v| h.merge v }
|
17
|
-
end
|
18
|
-
|
19
16
|
def new
|
20
17
|
@app_instance = AppInstance.new
|
21
|
-
read_applications
|
22
18
|
end
|
23
19
|
|
24
20
|
def create
|
@@ -31,7 +27,6 @@ module ForemanAcd
|
|
31
27
|
end
|
32
28
|
|
33
29
|
def edit
|
34
|
-
read_applications
|
35
30
|
end
|
36
31
|
|
37
32
|
def update
|
@@ -54,105 +49,44 @@ module ForemanAcd
|
|
54
49
|
case params[:action]
|
55
50
|
when 'deploy'
|
56
51
|
:deploy
|
52
|
+
when 'report'
|
53
|
+
:report
|
57
54
|
else
|
58
55
|
super
|
59
56
|
end
|
60
57
|
end
|
61
58
|
|
62
59
|
def deploy
|
63
|
-
|
64
|
-
|
65
|
-
# Print to log for debugging purposes
|
66
|
-
logger.info("Host creation parameters:\n#{params}\n")
|
67
|
-
|
68
|
-
@host = Host.new(params)
|
69
|
-
apply_compute_profile(@host)
|
70
|
-
@host.suggest_default_pxe_loader
|
71
|
-
@host.save
|
72
|
-
success _('Successfully initiated host creation')
|
73
|
-
rescue StandardError => e
|
74
|
-
logger.error("Failed to initiate host creation: #{e.backtrace.join($INPUT_RECORD_SEPARATOR)}")
|
75
|
-
ensure
|
76
|
-
redirect_to app_instances_path
|
77
|
-
end
|
78
|
-
|
79
|
-
private
|
60
|
+
app_deployer = ForemanAcd::AppDeployer.new(@app_instance)
|
61
|
+
app_hosts = app_deployer.deploy
|
80
62
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
host.apply_compute_profile(ComputeAttributeMerge.new)
|
85
|
-
end
|
63
|
+
# save any change to the app_hosts json
|
64
|
+
@app_instance.hosts = app_hosts.to_json
|
65
|
+
@app_instance.save
|
86
66
|
|
87
|
-
|
88
|
-
def host_attributes(params, host = nil)
|
89
|
-
return {} if params.nil?
|
90
|
-
|
91
|
-
params = params.deep_clone
|
92
|
-
if params[:interfaces_attributes]
|
93
|
-
# handle both hash and array styles of nested attributes
|
94
|
-
params[:interfaces_attributes] = params[:interfaces_attributes].values if params[:interfaces_attributes].is_a?(Hash) || params[:interfaces_attributes].is_a?(ActionController::Parameters)
|
95
|
-
# map interface types
|
96
|
-
params[:interfaces_attributes] = params[:interfaces_attributes].map do |nic_attr|
|
97
|
-
interface_attributes(nic_attr, :allow_nil_type => host.nil?)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
params = host.apply_inherited_attributes(params) if host
|
101
|
-
params
|
67
|
+
@deploy_hosts = collect_host_report_data(app_hosts)
|
102
68
|
end
|
103
69
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
params
|
108
|
-
end
|
70
|
+
def report
|
71
|
+
app_hosts = JSON.parse(@app_instance.hosts)
|
72
|
+
@report_hosts = collect_host_report_data(app_hosts)
|
109
73
|
|
110
|
-
|
111
|
-
result = {}
|
112
|
-
result['managed'] = true
|
113
|
-
result['enabled'] = true
|
114
|
-
result['build'] = true
|
115
|
-
result['compute_attributes'] = { 'start' => '1' }
|
116
|
-
result['host_parameters_attributes'] = []
|
117
|
-
result
|
74
|
+
logger.debug("deploy report hosts are: #{@report_hosts.inspect}")
|
118
75
|
end
|
119
76
|
|
120
|
-
|
121
|
-
result = hardcoded_params
|
122
|
-
result['hostgroup_id'] = @app_instance.app_definition.hostgroup_id
|
123
|
-
JSON.parse(@app_instance.parameters).each do |param|
|
124
|
-
case param['type']
|
125
|
-
|
126
|
-
when 'computeprofile'
|
127
|
-
result['compute_profile_id'] = param['value']
|
128
|
-
|
129
|
-
when 'domain'
|
130
|
-
result['domain_id'] = param['value']
|
131
|
-
|
132
|
-
when 'hostname'
|
133
|
-
result['name'] = param['value']
|
134
|
-
|
135
|
-
when 'hostparam'
|
136
|
-
result['host_parameters_attributes'].push(:name => param['name'], :value => param['value'])
|
137
|
-
|
138
|
-
when 'ip'
|
139
|
-
result['ip'] = param['value']
|
140
|
-
|
141
|
-
when 'lifecycleenv'
|
142
|
-
result['content_facet_attributes'] = { 'lifecycle_environment_id' => param['value'] }
|
143
|
-
|
144
|
-
when 'ptable'
|
145
|
-
result['ptable_id'] = param['value']
|
146
|
-
|
147
|
-
when 'puppetenv'
|
148
|
-
result['environment_id'] = param['value']
|
77
|
+
private
|
149
78
|
|
150
|
-
|
151
|
-
|
79
|
+
def read_applications
|
80
|
+
@applications = AppDefinition.all.map { |elem| { elem.id => elem.name } }.reduce({}) { |h, v| h.merge v }
|
81
|
+
end
|
152
82
|
|
153
|
-
|
83
|
+
def collect_host_report_data(app_hosts)
|
84
|
+
report_data = []
|
85
|
+
app_hosts.each do |host_data|
|
86
|
+
host = Host.find(host_data['foreman_host_id'])
|
87
|
+
report_data << { id: host.id, name: host_data['hostname'], hostname: host.hostname, hostUrl: host_path(host), progress_report_id: host.progress_report_id}
|
154
88
|
end
|
155
|
-
|
89
|
+
report_data
|
156
90
|
end
|
157
91
|
end
|
158
92
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ForemanAcd
|
4
|
+
module Concerns
|
5
|
+
# Parameters for AnsiblePlaybooks
|
6
|
+
module AnsiblePlaybookParameters
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
class_methods do
|
10
|
+
def ansible_playbook_params_filter
|
11
|
+
Foreman::ParameterFilter.new(::ForemanAcd::AnsiblePlaybook).tap do |filter|
|
12
|
+
filter.permit(:name, :description, :scm_type, :path, :playfile)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def ansible_playbook_params
|
18
|
+
param_name = parameter_filter_context.api? ? 'ansible_playbook' : 'foreman_acd_ansible_playbook'
|
19
|
+
self.class.ansible_playbook_params_filter.filter_params(params, parameter_filter_context, param_name)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -9,7 +9,7 @@ module ForemanAcd
|
|
9
9
|
class_methods do
|
10
10
|
def app_definition_params_filter
|
11
11
|
Foreman::ParameterFilter.new(::ForemanAcd::AppDefinition).tap do |filter|
|
12
|
-
filter.permit(:name, :description, :
|
12
|
+
filter.permit(:name, :description, :acd_ansible_playbook_id, :services, :ansible_vars_all)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -9,7 +9,7 @@ module ForemanAcd
|
|
9
9
|
class_methods do
|
10
10
|
def app_instance_params_filter
|
11
11
|
Foreman::ParameterFilter.new(::ForemanAcd::AppInstance).tap do |filter|
|
12
|
-
filter.permit(:name, :app_definition_id, :description, :
|
12
|
+
filter.permit(:name, :app_definition_id, :description, :hosts, :ansible_vars_all)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ForemanAcd
|
4
|
+
# Class to run remote execution jobs
|
5
|
+
class RemoteExecutionController < JobInvocationsController
|
6
|
+
|
7
|
+
def new
|
8
|
+
jobs = init_configuration
|
9
|
+
@composer = jobs.first
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
customize_first = params[:customize] || false
|
14
|
+
jobs = init_configuration
|
15
|
+
|
16
|
+
if jobs.count == 1 && customize_first == false
|
17
|
+
@composer = jobs.first
|
18
|
+
@composer.trigger!
|
19
|
+
redirect_to job_invocation_path(@composer.job_invocation)
|
20
|
+
elsif customize_first == false
|
21
|
+
jobs.each do |composer|
|
22
|
+
composer.trigger
|
23
|
+
end
|
24
|
+
redirect_to job_invocations_path
|
25
|
+
else
|
26
|
+
# redirect to the job itself if we want to customize the job
|
27
|
+
@composer = jobs.first
|
28
|
+
render :action => 'new'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# to overcome the isolated namespace engine difficulties with paths
|
33
|
+
helper Rails.application.routes.url_helpers
|
34
|
+
def _routes
|
35
|
+
Rails.application.routes
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def init_configuration
|
41
|
+
app_instance = ForemanAcd::AppInstance.find_by(:name => params[:id])
|
42
|
+
app_configurator = ForemanAcd::AppConfigurator.new(app_instance)
|
43
|
+
|
44
|
+
jobs = app_configurator.configure
|
45
|
+
logger.debug("Creating #{jobs.count} job(s) to configure the app #{app_instance}. Customize first: #{params[:customize]}")
|
46
|
+
return jobs
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -6,16 +6,19 @@ class UiAcdController < ::Api::V2::BaseController
|
|
6
6
|
@app_data = {}
|
7
7
|
app_definition = ForemanAcd::AppDefinition.find(params[:id])
|
8
8
|
@app_data['app_definition'] = app_definition
|
9
|
-
@app_data['fdata'] = collect_fdata(app_definition.hostgroup_id)
|
10
9
|
end
|
11
10
|
|
12
|
-
def
|
13
|
-
@
|
11
|
+
def foreman_data
|
12
|
+
@foreman_data = collect_foreman_data(params['id'])
|
13
|
+
end
|
14
|
+
|
15
|
+
def ansible_data
|
16
|
+
@ansible_data = collect_ansible_data(params['id'])
|
14
17
|
end
|
15
18
|
|
16
19
|
private
|
17
20
|
|
18
|
-
def
|
21
|
+
def collect_foreman_data(hostgroup_id)
|
19
22
|
hg = Hostgroup.find(hostgroup_id)
|
20
23
|
fdata = OpenStruct.new(
|
21
24
|
:environments => Environment.all,
|
@@ -27,4 +30,8 @@ class UiAcdController < ::Api::V2::BaseController
|
|
27
30
|
)
|
28
31
|
fdata
|
29
32
|
end
|
33
|
+
|
34
|
+
def collect_ansible_data(playbook_id)
|
35
|
+
ForemanAcd::AnsiblePlaybook.find(playbook_id).as_unified_structobj
|
36
|
+
end
|
30
37
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ForemanAcd
|
2
|
+
class AcdProvider < RemoteExecutionProvider
|
3
|
+
class << self
|
4
|
+
def supports_effective_user?
|
5
|
+
true
|
6
|
+
end
|
7
|
+
|
8
|
+
def proxy_operation_name
|
9
|
+
'acd'
|
10
|
+
end
|
11
|
+
|
12
|
+
def humanized_name
|
13
|
+
'ACD'
|
14
|
+
end
|
15
|
+
|
16
|
+
def proxy_command_options(template_invocation, host)
|
17
|
+
super(template_invocation, host).merge(:name => host.name)
|
18
|
+
end
|
19
|
+
|
20
|
+
def ssh_password(_host); end
|
21
|
+
|
22
|
+
def ssh_key_passphrase(_host); end
|
23
|
+
|
24
|
+
def sudo_password(_host); end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ForemanAcd
|
4
|
+
# Ansible playbook
|
5
|
+
class AnsiblePlaybook < ApplicationRecord
|
6
|
+
include Authorizable
|
7
|
+
extend FriendlyId
|
8
|
+
friendly_id :name
|
9
|
+
|
10
|
+
self.table_name = 'acd_ansible_playbooks'
|
11
|
+
has_many :app_definitions, :inverse_of => :ansible_playbook, :foreign_key => 'acd_ansible_playbook_id', dependent: :restrict_with_error
|
12
|
+
validates :name, :presence => true, :uniqueness => true
|
13
|
+
scoped_search :on => :name
|
14
|
+
default_scope -> { order("acd_ansible_playbooks.name") }
|
15
|
+
|
16
|
+
def self.humanize_class_name(_name = nil)
|
17
|
+
_('Ansible playbook')
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.permission_name
|
21
|
+
'ansible_playbooks'
|
22
|
+
end
|
23
|
+
|
24
|
+
def content
|
25
|
+
case scm_type
|
26
|
+
when 'directory'
|
27
|
+
File.read(File.join(path, playfile))
|
28
|
+
else
|
29
|
+
raise NotImplementedError.new "scm_type #{scm_type.inspect} not supported!"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def as_unified_structobj
|
34
|
+
groups = []
|
35
|
+
|
36
|
+
JSON.load(self.vars).each do |group_name, vars|
|
37
|
+
groups << OpenStruct.new(
|
38
|
+
:name => group_name,
|
39
|
+
:vars => vars.map { |k,v| OpenStruct.new(:name => k, :value => v) })
|
40
|
+
end
|
41
|
+
|
42
|
+
adata = OpenStruct.new(
|
43
|
+
:id => self.id,
|
44
|
+
:name => self.name,
|
45
|
+
:groups => JSON.load(self.vars)
|
46
|
+
)
|
47
|
+
adata
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -8,9 +8,10 @@ module ForemanAcd
|
|
8
8
|
friendly_id :name
|
9
9
|
|
10
10
|
validates :name, :presence => true, :uniqueness => true
|
11
|
-
belongs_to :hostgroup, :class_name => '::Hostgroup'
|
12
11
|
has_many :app_instances, :inverse_of => :app_definition, :dependent => :destroy
|
12
|
+
belongs_to :ansible_playbook, :inverse_of => :app_definitions, :foreign_key => :acd_ansible_playbook_id
|
13
13
|
scoped_search :on => :name
|
14
|
+
default_scope -> { order("app_definitions.name") }
|
14
15
|
|
15
16
|
def self.humanize_class_name(_name = nil)
|
16
17
|
_('App Definition')
|
@@ -9,6 +9,7 @@ module ForemanAcd
|
|
9
9
|
validates :name, :presence => true, :uniqueness => true
|
10
10
|
belongs_to :app_definition, :inverse_of => :app_instances
|
11
11
|
scoped_search :on => :name
|
12
|
+
default_scope -> { order("app_instances.name") }
|
12
13
|
|
13
14
|
def self.humanize_class_name(_name = nil)
|
14
15
|
_('App Instance')
|
@@ -17,5 +18,11 @@ module ForemanAcd
|
|
17
18
|
def self.permission_name
|
18
19
|
'app_instances'
|
19
20
|
end
|
21
|
+
|
22
|
+
def foreman_hosts
|
23
|
+
app_hosts = JSON.parse(self.hosts)
|
24
|
+
host_ids = app_hosts.select{ |h| h&.key?('foreman_host_id') }.map{ |h| h['foreman_host_id'] }
|
25
|
+
::Host.find(host_ids)
|
26
|
+
end
|
20
27
|
end
|
21
28
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ForemanAcd
|
4
|
+
# application instances configurator
|
5
|
+
class AppConfigurator
|
6
|
+
|
7
|
+
delegate :logger, :to => :Rails
|
8
|
+
|
9
|
+
def initialize(app_instance)
|
10
|
+
@app_instance = app_instance
|
11
|
+
end
|
12
|
+
|
13
|
+
def configure
|
14
|
+
job_input = {}
|
15
|
+
job_input['application_name'] = @app_instance.name
|
16
|
+
job_input['playbook_id'] = @app_instance.app_definition.ansible_playbook.id
|
17
|
+
job_input['playbook_file'] = @app_instance.app_definition.ansible_playbook.playfile
|
18
|
+
|
19
|
+
logger.info("Use inventory to configure #{@app_instance.name} with ansible playbook #{@app_instance.app_definition.ansible_playbook.name}")
|
20
|
+
|
21
|
+
begin
|
22
|
+
proxy_hosts = {}
|
23
|
+
jobs = []
|
24
|
+
|
25
|
+
hosts = @app_instance.foreman_hosts
|
26
|
+
proxy_selector = RemoteExecutionProxySelector.new
|
27
|
+
hosts.each do |h|
|
28
|
+
proxy = proxy_selector.determine_proxy(h, 'SSH')
|
29
|
+
unless proxy_hosts.has_key?(proxy.name)
|
30
|
+
proxy_hosts[proxy.name] = Array.new
|
31
|
+
end
|
32
|
+
proxy_hosts[proxy.name] << h.id
|
33
|
+
end
|
34
|
+
|
35
|
+
# TODO just for testing...
|
36
|
+
#proxy_hosts = { Host.first.name => [ Host.first.id] }
|
37
|
+
|
38
|
+
# we need to compose multiple jobs. for each proxy one job.
|
39
|
+
proxy_hosts.each do |proxy_name, host_names|
|
40
|
+
# create the inventory file
|
41
|
+
inventory = ForemanAcd::InventoryCreator.new(@app_instance, host_names).create_inventory
|
42
|
+
job_input['inventory'] = YAML.dump(inventory)
|
43
|
+
|
44
|
+
composer = JobInvocationComposer.for_feature(
|
45
|
+
:run_acd_ansible_playbook,
|
46
|
+
[Host.find_by(:name => proxy_name).id],
|
47
|
+
job_input.to_hash
|
48
|
+
)
|
49
|
+
jobs << composer
|
50
|
+
end
|
51
|
+
rescue StandardError => e
|
52
|
+
logger.error("Failed to configure hosts: #{e.class}: #{e.message}\n#{e.backtrace.join($INPUT_RECORD_SEPARATOR)}")
|
53
|
+
end
|
54
|
+
jobs
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|