foreman_acd 0.6.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/app/controllers/foreman_acd/ansible_playbooks_controller.rb +90 -0
- data/app/controllers/foreman_acd/app_definitions_controller.rb +104 -7
- data/app/controllers/foreman_acd/app_instances_controller.rb +34 -32
- data/app/controllers/foreman_acd/concerns/ansible_playbook_parameters.rb +1 -1
- data/app/controllers/foreman_acd/concerns/app_instance_mixins.rb +36 -0
- data/app/controllers/foreman_acd/remote_execution_controller.rb +37 -21
- data/app/controllers/ui_acd_controller.rb +42 -3
- data/app/lib/actions/foreman_acd/deploy_all_hosts.rb +12 -7
- data/app/lib/actions/foreman_acd/run_configurator.rb +11 -7
- data/app/models/concerns/foreman_acd/host_managed_extensions.rb +41 -28
- data/app/models/foreman_acd/acd_provider.rb +7 -1
- data/app/models/foreman_acd/ansible_playbook.rb +2 -1
- data/app/models/foreman_acd/app_instance.rb +48 -3
- data/app/models/foreman_acd/foreman_host.rb +8 -0
- data/app/services/foreman_acd/acd_proxy_proxy_selector.rb +17 -0
- data/app/services/foreman_acd/app_configurator.rb +59 -15
- data/app/services/foreman_acd/app_deployer.rb +27 -4
- data/app/services/foreman_acd/inventory_creator.rb +25 -1
- data/app/views/foreman_acd/ansible_playbooks/_form.html.erb +41 -7
- data/app/views/foreman_acd/app_definitions/_form.html.erb +5 -1
- data/app/views/foreman_acd/app_definitions/import.html.erb +20 -1
- data/app/views/foreman_acd/app_definitions/index.html.erb +3 -6
- data/app/views/foreman_acd/app_instances/_form.html.erb +5 -1
- data/app/views/foreman_acd/app_instances/index.html.erb +18 -12
- data/app/views/foreman_acd/app_instances/report.html.erb +8 -3
- data/app/views/templates/job/run_acd_ansible_playbook.erb +1 -1
- data/app/views/ui_acd/host_report.json.rabl +4 -0
- data/app/views/ui_acd/report_data.json.rabl +10 -0
- data/app/views/ui_acd/validate_hostname.json.rabl +6 -0
- data/config/routes.rb +6 -0
- data/db/migrate/20210316151145_add_git_commit_to_ansible_playbooks.rb +8 -0
- data/db/migrate/20210503122809_add_git_url_to_ansible_playbooks.rb +8 -0
- data/db/migrate/20210818125913_add_is_existing_host_to_foreman_host.rb +8 -0
- data/db/migrate/20210902110645_add_initial_configure_task.rb +8 -0
- data/db/seeds.d/75-job_templates.rb +1 -1
- data/lib/foreman_acd/engine.rb +26 -4
- data/lib/foreman_acd/plugin.rb +9 -18
- data/lib/foreman_acd/version.rb +1 -1
- data/lib/foreman_acd.rb +30 -0
- data/lib/tasks/foreman_acd_tasks.rake +0 -12
- data/package.json +8 -22
- data/test/controllers/ansible_playbooks_controller_test.rb +1 -1
- data/test/controllers/app_instances_controller_test.rb +8 -3
- data/test/controllers/ui_acd_controller_test.rb +25 -6
- data/test/factories/foreman_acd_factories.rb +18 -4
- data/test/models/acd_provider_test.rb +37 -0
- data/test/models/ansible_playbook_test.rb +11 -0
- data/test/models/app_definition_test.rb +1 -1
- data/test/models/app_instance_test.rb +2 -0
- data/test/models/concerns/host_extensions_test.rb +26 -0
- data/test/models/foreman_host_test.rb +12 -0
- data/webpack/__mocks__/foremanReact/API.js +2 -0
- data/webpack/__mocks__/foremanReact/common/I18n.js +3 -0
- data/webpack/__mocks__/foremanReact/common/helpers.js +2 -0
- data/webpack/__mocks__/foremanReact/components/ForemanModal/ForemanModalActions.js +2 -0
- data/webpack/__mocks__/foremanReact/components/ForemanModal.js +7 -0
- data/webpack/__mocks__/foremanReact/components/common/forms/CommonForm.js +2 -0
- data/webpack/__mocks__/foremanReact/components/common/forms/TextInput.js +2 -0
- data/webpack/__mocks__/foremanReact/components/hosts/powerStatus.js +1 -0
- data/webpack/__snapshots__/helper.test.js.snap +14 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinition.js +35 -11
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionActions.js +12 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionConstants.js +1 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionReducer.js +30 -9
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionSelectors.js +4 -0
- data/webpack/components/ApplicationDefinition/__fixtures__/applicationDefinitionConfData_1.fixtures.js +288 -0
- data/webpack/components/ApplicationDefinition/__fixtures__/applicationDefinitionReducer.fixtures.js +79 -0
- data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinition.test.js +26 -0
- data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinitionReducer.test.js +119 -0
- data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinitionSelectors.test.js +53 -0
- data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinition.test.js.snap +226 -0
- data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinitionReducer.test.js.snap +3033 -0
- data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinitionSelectors.test.js.snap +307 -0
- data/webpack/components/ApplicationDefinition/components/AnsiblePlaybookSelector.js +2 -1
- data/webpack/components/ApplicationDefinition/components/__tests__/AnsiblePlaybookSelector.test.js +41 -0
- data/webpack/components/ApplicationDefinition/components/__tests__/__snapshots__/AnsiblePlaybookSelector.test.js.snap +121 -0
- data/webpack/components/ApplicationDefinition/index.js +8 -0
- data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImport.js +214 -0
- data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImport.scss +1 -0
- data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImportActions.js +161 -0
- data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImportConstants.js +6 -0
- data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImportReducer.js +79 -0
- data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImportSelectors.js +8 -0
- data/webpack/components/ApplicationDefinitionImport/__fixtures__/applicationDefinitionImportConfData_1.fixtures.js +129 -0
- data/webpack/components/ApplicationDefinitionImport/__fixtures__/applicationDefinitionImportReducer.fixtures.js +29 -0
- data/webpack/components/ApplicationDefinitionImport/__tests__/ApplicationDefinitionImport.test.js +20 -0
- data/webpack/components/ApplicationDefinitionImport/__tests__/ApplicationDefinitionImportReducer.test.js +43 -0
- data/webpack/components/ApplicationDefinitionImport/__tests__/ApplicationDefinitionImportSelectors.test.js +29 -0
- data/webpack/components/ApplicationDefinitionImport/__tests__/__snapshots__/ApplicationDefinitionImport.test.js.snap +62 -0
- data/webpack/components/ApplicationDefinitionImport/__tests__/__snapshots__/ApplicationDefinitionImportReducer.test.js.snap +362 -0
- data/webpack/components/ApplicationDefinitionImport/__tests__/__snapshots__/ApplicationDefinitionImportSelectors.test.js.snap +130 -0
- data/webpack/components/ApplicationDefinitionImport/index.js +32 -0
- data/webpack/components/ApplicationInstance/ApplicationInstance.js +105 -31
- data/webpack/components/ApplicationInstance/ApplicationInstanceActions.js +118 -6
- data/webpack/components/ApplicationInstance/ApplicationInstanceConstants.js +4 -0
- data/webpack/components/ApplicationInstance/ApplicationInstanceHelper.js +15 -0
- data/webpack/components/ApplicationInstance/ApplicationInstanceReducer.js +71 -30
- data/webpack/components/ApplicationInstance/ApplicationInstanceSelectors.js +4 -0
- data/webpack/components/ApplicationInstance/__fixtures__/applicationInstanceConfData_1.fixtures.js +263 -0
- data/webpack/components/ApplicationInstance/__fixtures__/applicationInstanceReducer.fixtures.js +80 -0
- data/webpack/components/ApplicationInstance/__tests__/ApplicationInstance.test.js +24 -0
- data/webpack/components/ApplicationInstance/__tests__/ApplicationInstanceReducer.test.js +131 -0
- data/webpack/components/ApplicationInstance/__tests__/ApplicationInstanceSelectors.test.js +56 -0
- data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstance.test.js.snap +300 -0
- data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstanceReducer.test.js.snap +2990 -0
- data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstanceSelectors.test.js.snap +284 -0
- data/webpack/components/ApplicationInstance/components/AppDefinitionSelector.js +1 -0
- data/webpack/components/ApplicationInstance/components/ServiceCounter.js +1 -1
- data/webpack/components/ApplicationInstance/helper.js +0 -0
- data/webpack/components/ApplicationInstance/index.js +8 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js +81 -6
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js +35 -1
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportConstants.js +3 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js +19 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportSelectors.js +4 -0
- data/webpack/components/ApplicationInstanceReport/__fixtures__/applicationInstanceReportData_1.fixtures.js +349 -0
- data/webpack/components/ApplicationInstanceReport/__fixtures__/applicationInstanceReportReducer.fixtures.js +20 -0
- data/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReport.test.js +47 -0
- data/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReportReducer.test.js +41 -0
- data/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReportSelectors.test.js +26 -0
- data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReport.test.js.snap +7 -0
- data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReportReducer.test.js.snap +718 -0
- data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReportSelectors.test.js.snap +347 -0
- data/webpack/components/ApplicationInstanceReport/components/__tests__/ReportViewer.test.js +24 -0
- data/webpack/components/ApplicationInstanceReport/components/__tests__/__snapshots__/ReportViewer.test.js.snap +24 -0
- data/webpack/components/ApplicationInstanceReport/index.js +8 -1
- data/webpack/components/ExistingHostSelection/ExistingHostSelection.js +104 -0
- data/webpack/components/ExistingHostSelection/ExistingHostSelection.scss +15 -0
- data/webpack/components/ExistingHostSelection/ExistingHostSelectionActions.js +71 -0
- data/webpack/components/ExistingHostSelection/ExistingHostSelectionConstants.js +4 -0
- data/webpack/components/ExistingHostSelection/ExistingHostSelectionHelper.js +0 -0
- data/webpack/components/ExistingHostSelection/ExistingHostSelectionReducer.js +90 -0
- data/webpack/components/ExistingHostSelection/ExistingHostSelectionSelectors.js +8 -0
- data/webpack/components/ExistingHostSelection/__fixtures__/existingHostSelectionConfData_1.fixtures.js +191 -0
- data/webpack/components/ExistingHostSelection/__fixtures__/existingHostSelectionReducer.fixtures.js +203 -0
- data/webpack/components/ExistingHostSelection/__tests__/ExistingHostSelection.test.js +19 -0
- data/webpack/components/ExistingHostSelection/__tests__/ExistingHostSelectionReducer.test.js +59 -0
- data/webpack/components/ExistingHostSelection/__tests__/ExistingHostSelectionSelectors.test.js +36 -0
- data/webpack/components/ExistingHostSelection/__tests__/__snapshots__/ExistingHostSelection.test.js.snap +35 -0
- data/webpack/components/ExistingHostSelection/__tests__/__snapshots__/ExistingHostSelectionReducer.test.js.snap +614 -0
- data/webpack/components/ExistingHostSelection/__tests__/__snapshots__/ExistingHostSelectionSelectors.test.js.snap +27 -0
- data/webpack/components/ExistingHostSelection/components/ServiceSelector.js +48 -0
- data/webpack/components/ExistingHostSelection/components/__tests__/ServiceSelector.test.js +35 -0
- data/webpack/components/ExistingHostSelection/components/__tests__/__snapshots__/ServiceSelector.test.js.snap +77 -0
- data/webpack/components/ExistingHostSelection/index.js +26 -0
- data/webpack/components/ParameterSelection/ParameterSelection.js +103 -1
- data/webpack/components/ParameterSelection/ParameterSelection.scss +7 -0
- data/webpack/components/ParameterSelection/ParameterSelectionActions.js +46 -4
- data/webpack/components/ParameterSelection/ParameterSelectionConstants.js +2 -0
- data/webpack/components/ParameterSelection/ParameterSelectionHelper.js +5 -1
- data/webpack/components/ParameterSelection/ParameterSelectionReducer.js +51 -29
- data/webpack/components/ParameterSelection/ParameterSelectionSelectors.js +2 -0
- data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionData_1.fixtures.js +124 -84
- data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionReducer.fixtures.js +10 -4
- data/webpack/components/ParameterSelection/__tests__/ParameterSelection.test.js +36 -46
- data/webpack/components/ParameterSelection/__tests__/ParameterSelectionReducer.test.js +33 -25
- data/webpack/components/ParameterSelection/__tests__/ParameterSelectionSelectors.test.js +12 -6
- data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelection.test.js.snap +84 -112
- data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionReducer.test.js.snap +1589 -878
- data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionSelectors.test.js.snap +130 -79
- data/webpack/components/ParameterSelection/index.js +4 -1
- data/webpack/components/SyncGitRepo/SyncGitRepo.js +202 -0
- data/webpack/components/SyncGitRepo/SyncGitRepo.scss +1 -0
- data/webpack/components/SyncGitRepo/SyncGitRepoActions.js +123 -0
- data/webpack/components/SyncGitRepo/SyncGitRepoConstants.js +8 -0
- data/webpack/components/SyncGitRepo/SyncGitRepoReducer.js +80 -0
- data/webpack/components/SyncGitRepo/SyncGitRepoSelectors.js +6 -0
- data/webpack/components/SyncGitRepo/__fixtures__/syncGitRepoConfData_1.fixtures.js +7 -0
- data/webpack/components/SyncGitRepo/__fixtures__/syncGitRepoReducer.fixtures.js +44 -0
- data/webpack/components/SyncGitRepo/__tests__/SyncGitRepo.test.js +27 -0
- data/webpack/components/SyncGitRepo/__tests__/SyncGitRepoReducer.test.js +95 -0
- data/webpack/components/SyncGitRepo/__tests__/SyncGitRepoSelectors.test.js +32 -0
- data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepo.test.js.snap +31 -0
- data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepoReducer.test.js.snap +137 -0
- data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepoSelectors.test.js.snap +13 -0
- data/webpack/components/SyncGitRepo/components/FormTextInput.js +42 -0
- data/webpack/components/SyncGitRepo/components/ScmTypeSelector.js +47 -0
- data/webpack/components/SyncGitRepo/index.js +28 -0
- data/webpack/components/common/DeleteTableEntry.js +16 -2
- data/webpack/components/common/ExtTextInput.js +43 -0
- data/webpack/components/common/__tests__/EditTableEntry.test.js +53 -0
- data/webpack/components/common/__tests__/LockTableEntry.test.js +35 -0
- data/webpack/components/common/__tests__/__snapshots__/DeleteTableEntry.test.js.snap +40 -2
- data/webpack/components/common/__tests__/__snapshots__/EditTableEntry.test.js.snap +81 -0
- data/webpack/components/common/__tests__/__snapshots__/LockTableEntry.test.js.snap +60 -0
- data/webpack/helper.js +35 -1
- data/webpack/helper.test.js +56 -0
- data/webpack/index.js +7 -0
- data/webpack/js-yaml.js +3874 -0
- data/webpack/reducer.js +16 -1
- data/webpack/test_setup.js +0 -2
- metadata +136 -11
- data/webpack/components/common/EasyHeaderFormatter.js +0 -18
- data/webpack/components/common/__tests__/__snapshots__/AddParameter.test.js.snap +0 -35
- data/webpack/components/common/__tests__/__snapshots__/DeleteParameter.test.js.snap +0 -41
@@ -15,15 +15,19 @@ module Actions
|
|
15
15
|
app_instance = ::ForemanAcd::AppInstance.find(input.fetch(:id))
|
16
16
|
app_configurator = ::ForemanAcd::AppConfigurator.new(app_instance)
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
result, job = app_configurator.configure
|
19
|
+
if result.success
|
20
|
+
::Foreman::Logging.logger('foreman_acd').info "Creating job to configure the app #{app_instance}"
|
21
|
+
job.trigger!
|
22
|
+
output[:configure_job_id] = job.job_invocation.id
|
23
|
+
else
|
24
|
+
::Foreman::Logging.logger('foreman_acd').error "Could not create the job to configure the app #{app_instance}: #{result.error}"
|
25
|
+
end
|
23
26
|
rescue StandardError => e
|
24
|
-
::Foreman::Logging.logger('foreman_acd').error "Error while configuring application instance: #{e}"
|
25
|
-
|
27
|
+
::Foreman::Logging.logger('foreman_acd').error "Error while configuring application instance '#{app_instance.name}': #{e}"
|
28
|
+
|
26
29
|
output[:status] = 'FAILURE'
|
30
|
+
raise "Error while configuring hosts via ansible playbook for application instance '#{app_instance.name}': (#{e.message})"
|
27
31
|
end
|
28
32
|
end
|
29
33
|
|
@@ -5,47 +5,60 @@ module ForemanAcd
|
|
5
5
|
module HostManagedExtensions
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
|
-
RUN_CONFIGURATOR_DELAY = 240
|
9
|
-
|
10
8
|
def self.prepended(base)
|
11
9
|
base.instance_eval do
|
12
|
-
before_provision :
|
13
|
-
|
14
|
-
end
|
10
|
+
before_provision :initiate_acd_app_configurator_after_host_deployment, :if => :deployed_via_acd?
|
11
|
+
before_destroy :check_deletable, :prepend => true, :if => :deployed_via_acd?
|
15
12
|
|
16
|
-
|
13
|
+
has_many :app_instances, :through => :foreman_hosts, :class_name => 'ForemanAcd::AppInstance'
|
17
14
|
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
scoped_search :relation => :app_instances,
|
16
|
+
:on => :name,
|
17
|
+
:rename => :acd_app_instance,
|
18
|
+
:only_explicit => true,
|
19
|
+
:complete_value => true,
|
20
|
+
:operators => ['= '],
|
21
|
+
:ext_method => :find_by_acd_app_instance_name
|
22
|
+
end
|
23
|
+
|
24
|
+
base.singleton_class.prepend ClassMethods
|
21
25
|
end
|
22
26
|
|
23
|
-
|
24
|
-
|
27
|
+
# New class methods for Host::Managed
|
28
|
+
module ClassMethods
|
29
|
+
def find_by_acd_app_instance_name(_key, operator, acd_instance_name)
|
30
|
+
cond = sanitize_sql_for_conditions(["acd_app_instances.name #{operator} ?", value_to_sql(operator, acd_instance_name)])
|
31
|
+
hosts = ForemanAcd::AppInstance.where(cond).joins(:foreman_hosts).pluck(:host_id)
|
32
|
+
if hosts.empty?
|
33
|
+
{ :condition => '1=0' }
|
34
|
+
else
|
35
|
+
{ :conditions => Host::Managed.arel_table[:id].in(hosts).to_sql }
|
36
|
+
end
|
37
|
+
end
|
25
38
|
end
|
26
39
|
|
27
|
-
def
|
28
|
-
|
40
|
+
def deployed_via_acd?
|
41
|
+
find_foreman_host
|
42
|
+
@foreman_host.present?
|
43
|
+
end
|
29
44
|
|
30
|
-
|
31
|
-
@app_instance_host.app_instance.foreman_hosts.each do |foreman_host|
|
32
|
-
# if there is ONE host, which is still in build phase we don't let the app_configuator run
|
33
|
-
next unless foreman_host.host.build?
|
34
|
-
::Foreman::Logging.logger('foreman_acd').info("Another host (#{foreman_host.host.name} is still in build-phase. Wait for it...")
|
35
|
-
run_it = false
|
36
|
-
break
|
37
|
-
end
|
45
|
+
private
|
38
46
|
|
39
|
-
|
47
|
+
def check_deletable
|
48
|
+
return if @foreman_host.blank?
|
49
|
+
::Foreman::Logging.logger('foreman_acd').warn "Could not delete host '#{name}' because it is used in Applications > App Instances '#{@foreman_host.app_instance.name}'"
|
50
|
+
raise _("Could not delete host '%{host_name}' because it is used in Applications > App Instances '%{app_instance_name}'") % {
|
51
|
+
:host_name => name, :app_instance_name => @foreman_host.app_instance.name
|
52
|
+
}
|
53
|
+
end
|
40
54
|
|
41
|
-
|
42
|
-
|
55
|
+
def find_foreman_host
|
56
|
+
@foreman_host = ForemanAcd::ForemanHost.find_by(:host_id => id)
|
43
57
|
end
|
44
58
|
|
45
|
-
def
|
46
|
-
|
47
|
-
|
48
|
-
@app_instance_host.app_instance)
|
59
|
+
def initiate_acd_app_configurator_after_host_deployment
|
60
|
+
return if @foreman_host.blank?
|
61
|
+
ForemanAcd.initiate_acd_app_configurator(@foreman_host.app_instance)
|
49
62
|
end
|
50
63
|
end
|
51
64
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module ForemanAcd
|
4
4
|
# Implement a RemoteExecutionProvider
|
5
|
-
class AcdProvider < RemoteExecutionProvider
|
5
|
+
class AcdProvider < ::RemoteExecutionProvider
|
6
6
|
class << self
|
7
7
|
def supports_effective_user?
|
8
8
|
true
|
@@ -25,6 +25,12 @@ module ForemanAcd
|
|
25
25
|
def ssh_key_passphrase(_host); end
|
26
26
|
|
27
27
|
def sudo_password(_host); end
|
28
|
+
|
29
|
+
# Workaround till infrastructure jobs on proxies are possible. See
|
30
|
+
# configure in services/foreman_acd/app_configurator.rb for more details.
|
31
|
+
# def required_proxy_selector_for(_template)
|
32
|
+
# AcdProxyProxySelector.new
|
33
|
+
# end
|
28
34
|
end
|
29
35
|
end
|
30
36
|
end
|
@@ -12,6 +12,7 @@ module ForemanAcd
|
|
12
12
|
self.table_name = 'acd_ansible_playbooks'
|
13
13
|
has_many :app_definitions, :inverse_of => :ansible_playbook, :foreign_key => 'acd_ansible_playbook_id', :dependent => :restrict_with_error
|
14
14
|
validates :name, :presence => true, :uniqueness => true
|
15
|
+
validates :scm_type, :presence => true
|
15
16
|
scoped_search :on => :name
|
16
17
|
|
17
18
|
default_scope do
|
@@ -44,7 +45,7 @@ module ForemanAcd
|
|
44
45
|
|
45
46
|
def content
|
46
47
|
case scm_type
|
47
|
-
when 'directory'
|
48
|
+
when 'directory' || 'git'
|
48
49
|
File.read(File.join(path, playfile))
|
49
50
|
else
|
50
51
|
raise NotImplementedError.new "scm_type #{scm_type.inspect} not supported!"
|
@@ -11,6 +11,7 @@ module ForemanAcd
|
|
11
11
|
|
12
12
|
self.table_name = 'acd_app_instances'
|
13
13
|
belongs_to :last_deploy_task, :class_name => 'ForemanTasks::Task'
|
14
|
+
belongs_to :initial_configure_task, :class_name => 'ForemanTasks::Task'
|
14
15
|
validates :name, :presence => true, :uniqueness => true
|
15
16
|
validates :app_definition, :presence => true
|
16
17
|
belongs_to :app_definition, :inverse_of => :app_instances
|
@@ -32,7 +33,7 @@ module ForemanAcd
|
|
32
33
|
end
|
33
34
|
|
34
35
|
def clean_all_hosts
|
35
|
-
remember_host_ids = foreman_hosts.map(&:host_id)
|
36
|
+
remember_host_ids = foreman_hosts.select(&:fresh_host?).map(&:host_id)
|
36
37
|
|
37
38
|
# Clean the app instance association first
|
38
39
|
foreman_hosts.update_all(:host_id => nil)
|
@@ -43,18 +44,62 @@ module ForemanAcd
|
|
43
44
|
|
44
45
|
def clean_hosts_by_id(ids = [])
|
45
46
|
# Clean the app instance association first
|
46
|
-
foreman_hosts.where(:host_id => ids).update_all(:host_id => nil)
|
47
|
+
foreman_hosts.where(:host_id => ids, :is_existing_host => false).update_all(:host_id => nil)
|
47
48
|
|
48
49
|
# Remove all hosts afterwards
|
49
50
|
delete_hosts(ids)
|
50
51
|
end
|
51
52
|
|
53
|
+
def hosts_deployment_finished?
|
54
|
+
return true if all_hosts_deployed?
|
55
|
+
|
56
|
+
::Foreman::Logging.logger('foreman_acd').info('Another host is still in build-phase. Wait for it...')
|
57
|
+
false
|
58
|
+
end
|
59
|
+
|
60
|
+
def deployment_state
|
61
|
+
return :new if last_deploy_task.nil?
|
62
|
+
return :initiated if !last_deploy_task.nil? && last_deploy_task.ended_at.nil?
|
63
|
+
|
64
|
+
state = if all_hosts_deployed?
|
65
|
+
:finished
|
66
|
+
elsif last_deploy_task.ended_at? && last_deploy_task.result != 'success'
|
67
|
+
:failed
|
68
|
+
else
|
69
|
+
:pending
|
70
|
+
end
|
71
|
+
state
|
72
|
+
end
|
73
|
+
|
74
|
+
def initial_configure_job
|
75
|
+
return nil if initial_configure_task.nil?
|
76
|
+
return JobInvocation.find(initial_configure_task.output['configure_job_id']) if initial_configure_task.output.key?('configure_job_id') &&
|
77
|
+
!initial_configure_task.output['configure_job_id'].nil?
|
78
|
+
nil
|
79
|
+
end
|
80
|
+
|
81
|
+
def initial_configure_state
|
82
|
+
return :unconfigured if initial_configure_job.nil? && initial_configure_task.nil?
|
83
|
+
return :scheduled if initial_configure_job.nil?
|
84
|
+
return :pending unless initial_configure_job.finished?
|
85
|
+
initial_configure_job.status_label.to_sym
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def all_hosts_deployed?
|
91
|
+
foreman_hosts.each do |foreman_host|
|
92
|
+
return false if foreman_host.host.nil? || foreman_host.host.build?
|
93
|
+
end
|
94
|
+
true
|
95
|
+
end
|
96
|
+
|
52
97
|
def delete_hosts(ids = [])
|
53
98
|
return if ids.empty?
|
54
99
|
ids.each do |host_id|
|
55
100
|
h = ::Host.find(host_id) unless host_id.nil?
|
56
101
|
if h
|
57
|
-
Katello::RegistrationManager.unregister_host(h, :unregistering => false) if ForemanAcd
|
102
|
+
Katello::RegistrationManager.unregister_host(h, :unregistering => false) if ForemanAcd.with_katello?
|
58
103
|
h.destroy
|
59
104
|
end
|
60
105
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ForemanAcd
|
4
|
+
# AcdProxy Selector implementing a RemoteExecutionProxySelector which
|
5
|
+
# only returns the Smart Proxy of the given host
|
6
|
+
class AcdProxyProxySelector < ::RemoteExecutionProxySelector
|
7
|
+
def determine_proxy(*args)
|
8
|
+
host, _provider = args
|
9
|
+
|
10
|
+
# We already did the determine_proxy in app_configurator. We want that REX
|
11
|
+
# isn't doing the determination of the proxy twice.
|
12
|
+
# Therefore, we will just return the host, which is the proxy!
|
13
|
+
|
14
|
+
::SmartProxy.find_by(:name => host.name)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -19,12 +19,36 @@ module ForemanAcd
|
|
19
19
|
|
20
20
|
begin
|
21
21
|
proxy_hosts = {}
|
22
|
-
|
22
|
+
job = nil
|
23
|
+
result = OpenStruct.new
|
23
24
|
|
24
25
|
hosts = @app_instance.foreman_hosts
|
26
|
+
|
27
|
+
# Important: This uses the REX Proxy Selector and not
|
28
|
+
# the AcdProxySelection because the AcdProxySelector
|
29
|
+
# does not find the proxy but only return the given
|
30
|
+
# host. This is required because we want to run the
|
31
|
+
# ansible playbook for a group of hosts on the smart proxy.
|
32
|
+
# So the process need to be:
|
33
|
+
# 1. get the proxy which is required to connect to host a,b,c
|
34
|
+
# 2. run the job on the proxy
|
35
|
+
# In 2. we need to make sure that REX doesn't try to find the
|
36
|
+
# proxy which is necessary to connect to the proxy
|
25
37
|
proxy_selector = RemoteExecutionProxySelector.new
|
26
38
|
hosts.each do |h|
|
27
|
-
|
39
|
+
begin
|
40
|
+
unless h.host
|
41
|
+
result.success = false
|
42
|
+
result.error = 'App Instance is not deployed'
|
43
|
+
return [result, job]
|
44
|
+
end
|
45
|
+
proxy = proxy_selector.determine_proxy(h.host, 'ACD')
|
46
|
+
result.success = true
|
47
|
+
rescue NoMethodError => e
|
48
|
+
result.success = false
|
49
|
+
result.error = "#{e}, Install/Update smart-proxies for ACD"
|
50
|
+
return [result, job]
|
51
|
+
end
|
28
52
|
proxy_hosts[proxy.name] = [] unless proxy_hosts.key?(proxy.name)
|
29
53
|
proxy_hosts[proxy.name] << h
|
30
54
|
end
|
@@ -32,23 +56,43 @@ module ForemanAcd
|
|
32
56
|
# TODO: just for testing...
|
33
57
|
# proxy_hosts = { Host.first.name => [ Host.first.id] }
|
34
58
|
|
35
|
-
|
59
|
+
proxy_inventories = {}
|
60
|
+
proxy_host_ids = []
|
36
61
|
proxy_hosts.each do |proxy_name, foreman_hosts|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
)
|
46
|
-
|
62
|
+
proxy_inventories[proxy_name] = ForemanAcd::InventoryCreator.new(@app_instance, foreman_hosts).create_inventory
|
63
|
+
|
64
|
+
# Workaround till infrastructure jobs on proxies are possible. See
|
65
|
+
# https://community.theforeman.org/t/infrastructure-roles/22001/33
|
66
|
+
#
|
67
|
+
# Why do we use 'foreman_hosts.first.host'? REX is 'host-centric'. During
|
68
|
+
# job execution, REX will try to find the proxy on which the job should be executed.
|
69
|
+
# We throw the first host at REX's feet so that the resolution of the
|
70
|
+
# proxy works (... which we have already done above).
|
71
|
+
# ACD on the smart proxy side will call the ansible-playbook for ALL hosts
|
72
|
+
# which are behind this smart proxy.
|
73
|
+
#
|
74
|
+
# Additionally, we disable that AcdProxyProxySelector is used.
|
75
|
+
# See required_proxy_selector_for in models/foreman_acd/acd_provider.rb
|
76
|
+
proxy_host_ids << foreman_hosts.first.host.id
|
77
|
+
|
78
|
+
# Actually, we want this:
|
79
|
+
# proxy_host_ids << Host.find_by(:name => proxy_name).id
|
47
80
|
end
|
81
|
+
|
82
|
+
job_input['inventory'] = YAML.dump(proxy_inventories)
|
83
|
+
composer = JobInvocationComposer.for_feature(
|
84
|
+
:run_acd_ansible_playbook,
|
85
|
+
proxy_host_ids,
|
86
|
+
job_input.to_hash
|
87
|
+
)
|
88
|
+
job = composer
|
48
89
|
rescue StandardError => e
|
49
|
-
|
90
|
+
result.success = false
|
91
|
+
result.error = _('Failed to configure hosts: %{err_msg}' % { :err_msg => e.message })
|
92
|
+
logger.error('Failed to configure hosts: %{err_class}: %{err_msg}' % { :err_class => e.class, :err_msg => e.message })
|
93
|
+
job = nil
|
50
94
|
end
|
51
|
-
|
95
|
+
[result, job]
|
52
96
|
end
|
53
97
|
end
|
54
98
|
end
|
@@ -9,15 +9,30 @@ module ForemanAcd
|
|
9
9
|
@app_instance = app_instance
|
10
10
|
end
|
11
11
|
|
12
|
-
def deploy
|
12
|
+
def deploy(safe_deploy)
|
13
13
|
output = []
|
14
14
|
services = JSON.parse(@app_instance.app_definition.services)
|
15
15
|
all_hosts = []
|
16
16
|
|
17
|
-
|
17
|
+
foreman_hosts = if safe_deploy
|
18
|
+
@app_instance.foreman_hosts.find(safe_deploy)
|
19
|
+
else
|
20
|
+
@app_instance.foreman_hosts
|
21
|
+
end
|
22
|
+
|
23
|
+
foreman_hosts.each do |foreman_host|
|
18
24
|
service_data = services.select { |k| k['id'] == foreman_host.service.to_i }.first
|
19
|
-
host_params = set_host_params(foreman_host, service_data)
|
20
25
|
|
26
|
+
# Handle already deployed hosts
|
27
|
+
if foreman_host.existing_host?
|
28
|
+
domain = Hostgroup.find(service_data['hostgroup']).domain.name
|
29
|
+
fqdn = "#{foreman_host.hostname}.#{domain}"
|
30
|
+
h = Host.find_by(:name => fqdn)
|
31
|
+
foreman_host.update!(:host_id => h.id)
|
32
|
+
next
|
33
|
+
end
|
34
|
+
|
35
|
+
host_params = set_host_params(foreman_host, service_data)
|
21
36
|
host = foreman_host.host.presence
|
22
37
|
|
23
38
|
is_rebuild = false
|
@@ -39,7 +54,10 @@ module ForemanAcd
|
|
39
54
|
end
|
40
55
|
|
41
56
|
# REMOVE ME (but very nice for testing)
|
42
|
-
#
|
57
|
+
# prng = Random.new
|
58
|
+
# x = prng.rand(100)
|
59
|
+
# y = prng.rand(100)
|
60
|
+
# host.mac = "00:11:22:33:#{x}:#{y}"
|
43
61
|
|
44
62
|
apply_compute_profile(host)
|
45
63
|
host.suggest_default_pxe_loader
|
@@ -67,6 +85,11 @@ module ForemanAcd
|
|
67
85
|
output << msg
|
68
86
|
end
|
69
87
|
end
|
88
|
+
|
89
|
+
# Try to start the configuration, too. In case of a app instance including only already deployed hosts
|
90
|
+
# this would start the configuration job then.
|
91
|
+
ForemanAcd.initiate_acd_app_configurator(@app_instance)
|
92
|
+
|
70
93
|
output
|
71
94
|
end
|
72
95
|
|
@@ -32,10 +32,11 @@ module ForemanAcd
|
|
32
32
|
|
33
33
|
children[ansible_group] = { 'hosts' => {} } unless children.key?(host_service['ansibleGroup'])
|
34
34
|
|
35
|
-
ansible_vars = JSON.parse(foreman_host.ansibleParameters).map { |v| { v['name'] => v['value'] } }.reduce({}, :merge!)
|
35
|
+
ansible_vars = JSON.parse(foreman_host.ansibleParameters).map { |v| { v['name'] => get_param_value(foreman_host.host, v['value']) } }.reduce({}, :merge!)
|
36
36
|
|
37
37
|
# in case there is no ansible_user defined, set "root" as default.
|
38
38
|
ansible_vars['ansible_user'] = 'root' unless ansible_vars.key?('ansible_user')
|
39
|
+
ansible_vars['ansible_ssh_private_key_file'] = ansible_or_rex_ssh_private_key(foreman_host.host)
|
39
40
|
|
40
41
|
children[ansible_group]['hosts'][foreman_host.host.name] = ansible_vars
|
41
42
|
end
|
@@ -45,6 +46,29 @@ module ForemanAcd
|
|
45
46
|
|
46
47
|
private
|
47
48
|
|
49
|
+
def get_param_value(host, value)
|
50
|
+
search_param = value.match(/PARAM\[([^\s]*)\]/)
|
51
|
+
return value if search_param.nil?
|
52
|
+
|
53
|
+
resolved_value = host.host_param(search_param[1])
|
54
|
+
logger.warn "Could not resolve ansible host param value #{value} for host #{host}" if resolved_value.nil?
|
55
|
+
|
56
|
+
resolved_value
|
57
|
+
end
|
58
|
+
|
59
|
+
def ansible_or_rex_ssh_private_key(host)
|
60
|
+
ansible_private_file = host_setting(host, 'ansible_ssh_private_key_file')
|
61
|
+
if !ansible_private_file.empty?
|
62
|
+
ansible_private_file
|
63
|
+
else
|
64
|
+
ForemanRemoteExecutionCore.settings[:ssh_identity_key_file]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def host_setting(host, setting)
|
69
|
+
host.params[setting] || Setting[setting]
|
70
|
+
end
|
71
|
+
|
48
72
|
def inventory_all_vars
|
49
73
|
JSON.parse(@app_instance.ansible_vars_all).map do |a|
|
50
74
|
{ a['name'] => a['value'] }
|
@@ -1,3 +1,39 @@
|
|
1
|
+
<% content_for(:javascripts) do %>
|
2
|
+
<%= webpacked_plugins_js_for :foreman_acd %>
|
3
|
+
<% end %>
|
4
|
+
<% content_for(:stylesheets) do %>
|
5
|
+
<%= webpacked_plugins_css_for :foreman_acd %>
|
6
|
+
<% end %>
|
7
|
+
|
8
|
+
<%
|
9
|
+
if @ansible_playbook.new_record?
|
10
|
+
json = {
|
11
|
+
"scmTypes": {"directory" => "directory", "git" => "git"},
|
12
|
+
"mode": "newPlaybook",
|
13
|
+
"organization": current_organization,
|
14
|
+
"location": current_location,
|
15
|
+
"path": "",
|
16
|
+
"gitUrl": "",
|
17
|
+
"gitCommit": "",
|
18
|
+
"scmType": "",
|
19
|
+
"appDefinitions": [],
|
20
|
+
}
|
21
|
+
|
22
|
+
else
|
23
|
+
json = {
|
24
|
+
"scmTypes": {"directory" => "directory", "git" => "git"},
|
25
|
+
"mode": "editPlaybook",
|
26
|
+
"organization": current_organization,
|
27
|
+
"location": current_location,
|
28
|
+
"path": @ansible_playbook.path,
|
29
|
+
"gitUrl": @ansible_playbook.git_url,
|
30
|
+
"gitCommit": @ansible_playbook.git_commit,
|
31
|
+
"scmType": @ansible_playbook.scm_type,
|
32
|
+
"appDefinitions": @ansible_playbook.app_definitions
|
33
|
+
}
|
34
|
+
end
|
35
|
+
%>
|
36
|
+
|
1
37
|
<%= form_for @ansible_playbook, :url => (@ansible_playbook.new_record? ? ansible_playbooks_path : ansible_playbook_path(:id => @ansible_playbook.id)) do |f| %>
|
2
38
|
<%= base_errors_for @ansible_playbook %>
|
3
39
|
|
@@ -13,18 +49,16 @@
|
|
13
49
|
|
14
50
|
<div class="tab-content">
|
15
51
|
<div class="tab-pane active" id="primary">
|
52
|
+
|
16
53
|
<%= text_f f, :name %>
|
17
54
|
<%= text_f f, :description %>
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
%>
|
22
|
-
<%= text_f f, :path, :required => true %>
|
55
|
+
<div id='ansible_playbook'>
|
56
|
+
<%= react_component('SyncGitRepo', :data => json,) %>
|
57
|
+
</div>
|
23
58
|
<%= text_f f, :playfile, :required => true %>
|
24
59
|
</div>
|
25
|
-
|
60
|
+
|
26
61
|
<%= render 'taxonomies/loc_org_tabs', :f => f, :obj => @ansible_playbook %>
|
27
62
|
</div>
|
28
|
-
|
29
63
|
<%= submit_or_cancel f %>
|
30
64
|
<% end %>
|
@@ -24,6 +24,10 @@
|
|
24
24
|
if @app_definition.ansible_vars_all.present?
|
25
25
|
json["ansibleVarsAll"] = JSON.parse(@app_definition.ansible_vars_all)
|
26
26
|
end
|
27
|
+
|
28
|
+
json["supportedPlugins"] = {}
|
29
|
+
json["supportedPlugins"]["puppet"] = defined?(ForemanPuppet) != nil
|
30
|
+
json["supportedPlugins"]["katello"] = defined?(Katello) != nil
|
27
31
|
%>
|
28
32
|
|
29
33
|
<%= form_for @app_definition, :url => (@app_definition.new_record? ? app_definitions_path : app_definition_path(:id => @app_definition.id)) do |f| %>
|
@@ -44,7 +48,7 @@
|
|
44
48
|
<%= text_f f, :description %>
|
45
49
|
|
46
50
|
<div id='app_definition'></div>
|
47
|
-
<%=
|
51
|
+
<%= react_component('ApplicationDefinition', :data => json) %>
|
48
52
|
</div>
|
49
53
|
|
50
54
|
<%= render 'taxonomies/loc_org_tabs', :f => f, :obj => @app_definition %>
|
@@ -1,3 +1,22 @@
|
|
1
|
+
<%= javascript_include_tag *webpack_asset_paths('foreman_acd', extension: 'js') %>
|
2
|
+
<%
|
3
|
+
json = {
|
4
|
+
"organization": current_organization,
|
5
|
+
"location": current_location,
|
6
|
+
"hostgroups": @hostgroups,
|
7
|
+
"foremanDataUrl": ui_acd_foreman_data_path("__id__"),
|
8
|
+
"ansibleDataUrl": ui_acd_ansible_data_path("__id__"),
|
9
|
+
"services": [],
|
10
|
+
"ansibleVarsAll": [],
|
11
|
+
}
|
12
|
+
|
13
|
+
if @app_definition.new_record?
|
14
|
+
json["mode"] = "newDefinition"
|
15
|
+
else
|
16
|
+
json["mode"] = "editDefinition"
|
17
|
+
end
|
18
|
+
%>
|
19
|
+
|
1
20
|
<% title _('Import Application Definition') %>
|
2
21
|
|
3
22
|
<%= form_for @app_definition, :url => (app_definitions_path), :html => { :multipart => true } do |f| %>
|
@@ -10,7 +29,7 @@
|
|
10
29
|
<div class="tab-pane active" id="primary">
|
11
30
|
<%= text_f f, :name %>
|
12
31
|
<%= text_f f, :description %>
|
13
|
-
<%=
|
32
|
+
<%= react_component('ApplicationDefinitionImport', json,) %>
|
14
33
|
</div>
|
15
34
|
</div>
|
16
35
|
|
@@ -1,15 +1,12 @@
|
|
1
1
|
<% title _('Application Definitions') %>
|
2
2
|
|
3
|
-
<% title_actions
|
4
|
-
new_link(_('New Application Definition')),
|
5
|
-
display_link_if_authorized(_("Import"), hash_for_import_app_definitions_path, :class => 'btn btn-default', :style => "display: none;")
|
6
|
-
) %>
|
3
|
+
<% title_actions new_link(_('New Application Definition')), display_link_if_authorized(_("Import"), hash_for_import_app_definitions_path, :class => 'btn btn-default') %>
|
7
4
|
|
8
5
|
<table class="table table-bordered table-striped">
|
9
6
|
<tr>
|
10
7
|
<th><%= sort :name, :as => s_('AppDefinition|Name') %></th>
|
11
8
|
<th><%= _('Description') %></th>
|
12
|
-
<th
|
9
|
+
<th><%= _('Actions') %></th>
|
13
10
|
</tr>
|
14
11
|
<% for app_definition in @app_definitions %>
|
15
12
|
<tr>
|
@@ -19,7 +16,7 @@
|
|
19
16
|
<%= action_buttons(
|
20
17
|
display_delete_if_authorized(hash_for_app_definition_path(:id => app_definition),
|
21
18
|
:data => { 'confirm': _('Delete %s?') % app_definition.name }),
|
22
|
-
|
19
|
+
display_link_if_authorized(_("Export"), hash_for_export_app_definition_path(:id => app_definition))
|
23
20
|
) %>
|
24
21
|
</td>
|
25
22
|
</tr>
|
@@ -24,6 +24,10 @@
|
|
24
24
|
"ansibleVarsAll": @app_instance.ansible_vars_all.blank? ? [] : JSON.parse(@app_instance.ansible_vars_all),
|
25
25
|
}
|
26
26
|
end
|
27
|
+
|
28
|
+
json["supportedPlugins"] = {}
|
29
|
+
json["supportedPlugins"]["puppet"] = defined?(ForemanPuppet) != nil
|
30
|
+
json["supportedPlugins"]["katello"] = defined?(Katello) != nil
|
27
31
|
%>
|
28
32
|
|
29
33
|
<%= form_for @app_instance, :url => (@app_instance.new_record? ? app_instances_path : app_instance_path(:id => @app_instance.id)) do |f| %>
|
@@ -38,7 +42,7 @@
|
|
38
42
|
<%= text_f f, :description %>
|
39
43
|
|
40
44
|
<div id='app_instance'></div>
|
41
|
-
<%=
|
45
|
+
<%= react_component('ApplicationInstance', :data => json) %>
|
42
46
|
</div>
|
43
47
|
</div>
|
44
48
|
</div>
|