foreman_ansible 2.2.14 → 2.3.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/Rakefile +2 -0
- data/app/controllers/ansible_roles_controller.rb +4 -11
- data/app/controllers/ansible_variables_controller.rb +80 -0
- data/app/controllers/api/v2/ansible_roles_controller.rb +2 -0
- data/app/controllers/api/v2/ansible_variables_controller.rb +68 -0
- data/app/controllers/concerns/foreman/controller/parameters/ansible_variable.rb +36 -0
- data/app/controllers/foreman_ansible/api/v2/hostgroups_controller_extensions.rb +2 -0
- data/app/controllers/foreman_ansible/api/v2/hostgroups_param_group_extensions.rb +2 -0
- data/app/controllers/foreman_ansible/api/v2/hosts_controller_extensions.rb +2 -0
- data/app/controllers/foreman_ansible/api/v2/hosts_param_group_extensions.rb +2 -0
- data/app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb +2 -0
- data/app/controllers/foreman_ansible/concerns/hosts_controller_extensions.rb +2 -0
- data/app/controllers/foreman_ansible/concerns/import_controller_helper.rb +24 -0
- data/app/controllers/foreman_ansible/concerns/job_invocation_helper.rb +2 -0
- data/app/helpers/foreman_ansible/ansible_plugin_helper.rb +2 -0
- data/app/helpers/foreman_ansible/ansible_reports_helper.rb +6 -4
- data/app/helpers/foreman_ansible/ansible_roles_helper.rb +2 -0
- data/app/helpers/foreman_ansible/hosts_helper_extensions.rb +2 -0
- data/app/lib/actions/foreman_ansible/helpers/host_common.rb +2 -0
- data/app/lib/actions/foreman_ansible/helpers/play_roles_description.rb +2 -0
- data/app/lib/proxy_api/ansible.rb +16 -0
- data/app/models/ansible_role.rb +5 -0
- data/app/models/ansible_variable.rb +23 -0
- data/app/models/concerns/foreman_ansible/host_managed_extensions.rb +3 -1
- data/app/models/concerns/foreman_ansible/hostgroup_extensions.rb +2 -0
- data/app/models/foreman_ansible/ansible_provider.rb +2 -0
- data/app/models/foreman_ansible/fact_name.rb +2 -0
- data/app/models/host_ansible_role.rb +2 -0
- data/app/models/hostgroup_ansible_role.rb +2 -0
- data/app/models/setting/ansible.rb +7 -5
- data/app/overrides/ansible_roles_tab.rb +2 -0
- data/app/overrides/ansible_variables_edit.rb +15 -0
- data/app/overrides/hostgroup_ansible_roles_tab.rb +2 -0
- data/app/overrides/hostgroup_play_roles.rb +2 -0
- data/app/overrides/report_output.rb +2 -0
- data/app/services/foreman_ansible/ansible_report_importer.rb +15 -0
- data/app/services/foreman_ansible/ansible_report_scanner.rb +2 -0
- data/app/services/foreman_ansible/api_roles_importer.rb +2 -0
- data/app/services/foreman_ansible/fact_importer.rb +2 -0
- data/app/services/foreman_ansible/fact_parser.rb +13 -1
- data/app/services/foreman_ansible/fact_sparser.rb +2 -0
- data/app/services/foreman_ansible/insights_notification_builder.rb +2 -0
- data/app/services/foreman_ansible/insights_plan_runner.rb +3 -2
- data/app/services/foreman_ansible/inventory_creator.rb +0 -6
- data/app/services/foreman_ansible/operating_system_parser.rb +3 -1
- data/app/services/foreman_ansible/playbook_creator.rb +2 -0
- data/app/services/foreman_ansible/proxy_api.rb +24 -0
- data/app/services/foreman_ansible/renderer_methods.rb +2 -0
- data/app/services/foreman_ansible/roles_importer.rb +4 -17
- data/app/services/foreman_ansible/structured_fact_importer.rb +2 -0
- data/app/services/foreman_ansible/ui_roles_importer.rb +2 -0
- data/app/services/foreman_ansible/variables_importer.rb +100 -0
- data/app/views/ansible_roles/index.html.erb +13 -3
- data/app/views/ansible_variables/_ansible_roles_list.html.erb +15 -0
- data/app/views/ansible_variables/_validator_text.html.erb +5 -0
- data/app/views/ansible_variables/edit.html.erb +17 -0
- data/app/views/ansible_variables/import.html.erb +53 -0
- data/app/views/ansible_variables/index.html.erb +46 -0
- data/app/views/api/v2/ansible_roles/import.json.rabl +2 -0
- data/app/views/api/v2/ansible_roles/index.json.rabl +2 -0
- data/app/views/api/v2/ansible_roles/obsolete.json.rabl +2 -0
- data/app/views/api/v2/ansible_roles/show.json.rabl +2 -0
- data/app/views/api/v2/ansible_variables/import.json.rabl +3 -0
- data/app/views/api/v2/ansible_variables/index.json.rabl +3 -0
- data/app/views/api/v2/ansible_variables/obsolete.json.rabl +3 -0
- data/app/views/api/v2/ansible_variables/show.json.rabl +20 -0
- data/app/views/foreman_ansible/api/v2/ansible_roles/import.json.rabl +2 -0
- data/app/views/foreman_ansible/api/v2/ansible_roles/index.json.rabl +2 -0
- data/app/views/foreman_ansible/api/v2/ansible_roles/obsolete.json.rabl +2 -0
- data/app/views/foreman_ansible/api/v2/ansible_roles/show.json.rabl +2 -0
- data/config/routes.rb +17 -0
- data/db/migrate/20160705082036_create_ansible_role.rb +2 -0
- data/db/migrate/20160706074540_create_join_table_hosts_ansible_roles.rb +2 -0
- data/db/migrate/20160707195442_create_host_ansible_roles.rb +2 -0
- data/db/migrate/20160729094457_add_columns_to_ansible_role.rb +2 -0
- data/db/migrate/20160802153302_create_join_table_hostgroup_ansible_roles.rb +2 -0
- data/db/migrate/20160805094233_add_primary_key_hostgroup_ansible_roles.rb +2 -0
- data/db/migrate/20161122154057_automatically_set_role_timestamps.rb +2 -0
- data/db/migrate/20180410125416_rename_ansible_job_categories.rb +6 -3
- data/db/migrate/20180628125416_add_ansible_role_id_to_lookup_keys.rb +14 -0
- data/db/seeds.d/62_ansible_proxy_feature.rb +2 -0
- data/db/seeds.d/75_job_templates.rb +3 -1
- data/db/seeds.d/90_notification_blueprints.rb +2 -0
- data/lib/foreman_ansible.rb +2 -0
- data/lib/foreman_ansible/engine.rb +2 -0
- data/lib/foreman_ansible/register.rb +28 -1
- data/lib/foreman_ansible/remote_execution.rb +2 -0
- data/lib/foreman_ansible/version.rb +3 -1
- data/locale/action_names.rb +2 -2
- data/locale/de/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/de/foreman_ansible.edit.po +444 -0
- data/locale/de/foreman_ansible.po +56 -17
- data/locale/de/foreman_ansible.po.time_stamp +0 -0
- data/locale/en/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/en/foreman_ansible.edit.po +442 -0
- data/locale/en/foreman_ansible.po +56 -17
- data/locale/en/foreman_ansible.po.time_stamp +0 -0
- data/locale/es/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/es/foreman_ansible.edit.po +444 -0
- data/locale/es/foreman_ansible.po +56 -17
- data/locale/es/foreman_ansible.po.time_stamp +0 -0
- data/locale/foreman_ansible.pot +174 -93
- data/locale/fr/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/fr/foreman_ansible.edit.po +444 -0
- data/locale/fr/foreman_ansible.po +56 -17
- data/locale/fr/foreman_ansible.po.time_stamp +0 -0
- data/locale/it/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/it/foreman_ansible.edit.po +444 -0
- data/locale/it/foreman_ansible.po +56 -17
- data/locale/it/foreman_ansible.po.time_stamp +0 -0
- data/locale/ja/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/ja/foreman_ansible.edit.po +444 -0
- data/locale/ja/foreman_ansible.po +56 -17
- data/locale/ja/foreman_ansible.po.time_stamp +0 -0
- data/locale/ko/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/ko/foreman_ansible.edit.po +444 -0
- data/locale/ko/foreman_ansible.po +56 -17
- data/locale/ko/foreman_ansible.po.time_stamp +0 -0
- data/locale/pt_BR/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/pt_BR/foreman_ansible.edit.po +444 -0
- data/locale/pt_BR/foreman_ansible.po +56 -17
- data/locale/pt_BR/foreman_ansible.po.time_stamp +0 -0
- data/locale/ru/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/ru/foreman_ansible.edit.po +445 -0
- data/locale/ru/foreman_ansible.po +56 -17
- data/locale/ru/foreman_ansible.po.time_stamp +0 -0
- data/locale/zh_CN/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/zh_CN/foreman_ansible.edit.po +444 -0
- data/locale/zh_CN/foreman_ansible.po +56 -17
- data/locale/zh_CN/foreman_ansible.po.time_stamp +0 -0
- data/locale/zh_TW/LC_MESSAGES/foreman_ansible.mo +0 -0
- data/locale/zh_TW/foreman_ansible.edit.po +444 -0
- data/locale/zh_TW/foreman_ansible.po +56 -17
- data/locale/zh_TW/foreman_ansible.po.time_stamp +0 -0
- data/test/factories/ansible_proxy.rb +2 -0
- data/test/factories/ansible_roles.rb +2 -0
- data/test/factories/ansible_variables.rb +8 -0
- data/test/functional/ansible_roles_controller_test.rb +2 -0
- data/test/functional/ansible_variables_controller_test.rb +36 -0
- data/test/functional/api/v2/ansible_roles_controller_test.rb +21 -9
- data/test/functional/api/v2/ansible_variables_controller_test.rb +41 -0
- data/test/functional/api/v2/hostgroups_controller_test.rb +2 -0
- data/test/functional/api/v2/hosts_controller_test.rb +2 -0
- data/test/functional/hosts_controller_test.rb +2 -0
- data/test/test_plugin_helper.rb +2 -0
- data/test/unit/ansible_provider_test.rb +2 -0
- data/test/unit/ansible_role_test.rb +5 -9
- data/test/unit/ansible_variable_test.rb +14 -0
- data/test/unit/concerns/config_reports_extensions_test.rb +2 -0
- data/test/unit/concerns/host_managed_extensions_test.rb +2 -0
- data/test/unit/concerns/hostgroup_extensions_test.rb +2 -0
- data/test/unit/helpers/ansible_reports_helper_test.rb +2 -0
- data/test/unit/host_ansible_role_test.rb +2 -0
- data/test/unit/hostgroup_ansible_role_test.rb +2 -0
- data/test/unit/lib/foreman_ansible_core/command_creator_test.rb +2 -0
- data/test/unit/lib/foreman_ansible_core/playbook_runner_test.rb +2 -0
- data/test/unit/lib/proxy_api/ansible_test.rb +2 -0
- data/test/unit/services/ansible_report_importer_test.rb +15 -0
- data/test/unit/services/ansible_variables_importer_test.rb +39 -0
- data/test/unit/services/api_roles_importer_test.rb +2 -0
- data/test/unit/services/fact_importer_test.rb +2 -0
- data/test/unit/services/fact_parser_test.rb +47 -0
- data/test/unit/services/fact_sparser_test.rb +2 -0
- data/test/unit/services/insights_plan_runner_test.rb +2 -0
- data/test/unit/services/inventory_creator_test.rb +1 -13
- data/test/unit/services/roles_importer_test.rb +2 -0
- data/test/unit/services/structured_fact_importer_test.rb +2 -0
- data/test/unit/services/ui_roles_importer_test.rb +2 -0
- metadata +101 -42
- data/test/unit/lib/foreman_ansible_core/roles_reader_test.rb +0 -92
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0dc5e5a7b0474fef241b4607911073f5e3b94bbc
|
|
4
|
+
data.tar.gz: 0e57147506ec6cac87ca5107e832bfe80d594ecb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aca0209523ab2b7eac8ad76877ef2946a1a7fa9ce04c860cb972dcee73296f8d9c7afeac575170265a0a946084e5f5d2d0393628deeaf624a5d18784809bcae2
|
|
7
|
+
data.tar.gz: 44db93653e958c13d72d80e68f8c7b188c59059078b942397d25664cbda18ec1756b0a709e3e15c75ba4aee319622f31a77f615894b4210f0a155f9fcca5634d
|
data/Rakefile
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# UI controller for ansible roles
|
|
2
4
|
class AnsibleRolesController < ::ApplicationController
|
|
3
5
|
include Foreman::Controller::AutoCompleteSearch
|
|
4
|
-
|
|
5
|
-
before_action :find_resource, :only => [:destroy]
|
|
6
|
-
before_action :find_proxy, :only => [:import]
|
|
7
|
-
before_action :create_importer, :only => [:import, :confirm_import]
|
|
8
|
-
before_action :default_order, :only => [:index]
|
|
6
|
+
include ForemanAnsible::Concerns::ImportControllerHelper
|
|
9
7
|
|
|
10
8
|
def index
|
|
11
9
|
@ansible_roles = resource_base.search_for(params[:search],
|
|
@@ -33,7 +31,7 @@ class AnsibleRolesController < ::ApplicationController
|
|
|
33
31
|
end
|
|
34
32
|
|
|
35
33
|
def confirm_import
|
|
36
|
-
@importer.finish_import(params[:changed]
|
|
34
|
+
@importer.finish_import(params[:changed]&.to_unsafe_h)
|
|
37
35
|
success _('Import of roles successfully finished.')
|
|
38
36
|
redirect_to ansible_roles_path
|
|
39
37
|
end
|
|
@@ -44,11 +42,6 @@ class AnsibleRolesController < ::ApplicationController
|
|
|
44
42
|
params[:order] ||= 'name ASC'
|
|
45
43
|
end
|
|
46
44
|
|
|
47
|
-
def find_proxy
|
|
48
|
-
return nil unless params[:proxy]
|
|
49
|
-
@proxy = SmartProxy.authorized(:view_smart_proxies).find(params[:proxy])
|
|
50
|
-
end
|
|
51
|
-
|
|
52
45
|
def create_importer
|
|
53
46
|
@importer = ForemanAnsible::UiRolesImporter.new(@proxy)
|
|
54
47
|
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# UI controller for ansible variables
|
|
4
|
+
class AnsibleVariablesController < ::LookupKeysController
|
|
5
|
+
include Foreman::Controller::AutoCompleteSearch
|
|
6
|
+
include ForemanAnsible::Concerns::ImportControllerHelper
|
|
7
|
+
include Foreman::Controller::Parameters::AnsibleVariable
|
|
8
|
+
|
|
9
|
+
before_action :import_new_roles, :only => [:confirm_import]
|
|
10
|
+
before_action :find_required_proxy, :only => [:import]
|
|
11
|
+
before_action :find_resource, :only => [:edit, :update, :destroy],
|
|
12
|
+
:if => proc { params[:id] }
|
|
13
|
+
|
|
14
|
+
def index
|
|
15
|
+
@ansible_variables = resource_base.search_for(params[:search],
|
|
16
|
+
:order => params[:order]).
|
|
17
|
+
paginate(:page => params[:page],
|
|
18
|
+
:per_page => params[:per_page])
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def import
|
|
22
|
+
import_roles = @importer_roles.import_role_names
|
|
23
|
+
import_roles[:new_roles] = import_roles[:new]
|
|
24
|
+
import_variables = @importer.import_variable_names(import_roles[:new_roles])
|
|
25
|
+
render 'ansible_variables/import',
|
|
26
|
+
:locals => { :changed => import_variables }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def confirm_import
|
|
30
|
+
results = @importer.finish_import(new_vars, old_vars)
|
|
31
|
+
info _(
|
|
32
|
+
"Import of variables successfully finished.\n"\
|
|
33
|
+
"Added: #{results[:added].join(', ')} \n "\
|
|
34
|
+
"Removed: #{results[:obsolete].join(', ')}"
|
|
35
|
+
)
|
|
36
|
+
redirect_to ansible_variables_path
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def default_order; end
|
|
42
|
+
|
|
43
|
+
def resource
|
|
44
|
+
@ansible_variable
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def resource_params
|
|
48
|
+
ansible_variable_params
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def new_vars
|
|
52
|
+
params[:changed] ? params[:changed][:new].as_json : {}
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def old_vars
|
|
56
|
+
params[:changed] ? params[:changed][:obsolete].as_json : {}
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def import_new_roles
|
|
60
|
+
return if new_vars.blank?
|
|
61
|
+
new_vars.each_key do |role_name|
|
|
62
|
+
::AnsibleRole.find_or_create_by(:name => role_name)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def create_importer
|
|
67
|
+
@importer = ForemanAnsible::VariablesImporter.new(@proxy)
|
|
68
|
+
@importer_roles = ForemanAnsible::UiRolesImporter.new(@proxy)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def find_required_proxy
|
|
72
|
+
id = params['proxy']
|
|
73
|
+
@smart_proxy = SmartProxy.authorized(:view_smart_proxies).find(id)
|
|
74
|
+
unless @smart_proxy&.has_feature?('Ansible')
|
|
75
|
+
not_found _('No proxy found to import variables from, ensure that the '\
|
|
76
|
+
'smart proxy has the Ansible feature enabled.')
|
|
77
|
+
end
|
|
78
|
+
@smart_proxy
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Api
|
|
4
|
+
module V2
|
|
5
|
+
# API controller for Ansible Variables
|
|
6
|
+
class AnsibleVariablesController < ::Api::V2::BaseController
|
|
7
|
+
include ::Api::Version2
|
|
8
|
+
|
|
9
|
+
resource_description do
|
|
10
|
+
api_version 'v2'
|
|
11
|
+
api_base_url '/ansible/api'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
before_action :find_resource, :only => [:show, :destroy]
|
|
15
|
+
before_action :find_proxy, :only => [:import, :obsolete]
|
|
16
|
+
before_action :create_importer, :only => [:import, :obsolete]
|
|
17
|
+
|
|
18
|
+
api :GET, '/ansible_variables/:id', N_('Show variable')
|
|
19
|
+
param :id, :identifier, :required => true
|
|
20
|
+
def show; end
|
|
21
|
+
|
|
22
|
+
api :GET, '/ansible_variables', N_('List Ansible variables')
|
|
23
|
+
param_group :search_and_pagination, ::Api::V2::BaseController
|
|
24
|
+
def index
|
|
25
|
+
@ansible_variables = resource_scope_for_index
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
api :DELETE, '/ansible_variables/:id', N_('Deletes Ansible variable')
|
|
29
|
+
param :id, :identifier, :required => true
|
|
30
|
+
def destroy
|
|
31
|
+
process_response @ansible_variable.destroy
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
api :PUT, '/ansible_variables/import',
|
|
35
|
+
N_('Import Ansible variables. This will only import variables '\
|
|
36
|
+
'for already existing roles, it will not import any new roles')
|
|
37
|
+
param :proxy_id, :identifier, N_('Smart Proxy to import from')
|
|
38
|
+
def import
|
|
39
|
+
new_variables = @importer.import_variable_names([])[:new]
|
|
40
|
+
new_variables.map(&:save)
|
|
41
|
+
@imported = new_variables
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
api :PUT, '/ansible_variables/obsolete',
|
|
45
|
+
N_('Obsolete Ansible variables. This will only obsolete variables '\
|
|
46
|
+
'for already existing roles, it will not delete any old roles')
|
|
47
|
+
param :proxy_id, :identifier, N_('Smart Proxy to import from')
|
|
48
|
+
def obsolete
|
|
49
|
+
old_variables = @importer.import_variable_names([])[:obsolete]
|
|
50
|
+
old_variables.map(&:destroy)
|
|
51
|
+
@obsoleted = old_variables
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
def find_proxy
|
|
57
|
+
return nil unless params[:proxy_id]
|
|
58
|
+
@proxy = SmartProxy.
|
|
59
|
+
authorized(:view_smart_proxies).
|
|
60
|
+
find(params[:proxy_id])
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def create_importer
|
|
64
|
+
@importer = ForemanAnsible::VariablesImporter.new(@proxy)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Foreman
|
|
4
|
+
module Controller
|
|
5
|
+
module Parameters
|
|
6
|
+
# Keys to allow as parameters in the AnsibleVariable controller
|
|
7
|
+
module AnsibleVariable
|
|
8
|
+
extend ActiveSupport::Concern
|
|
9
|
+
include Foreman::Controller::Parameters::LookupKey
|
|
10
|
+
|
|
11
|
+
class_methods do
|
|
12
|
+
def ansible_variable_params_filter
|
|
13
|
+
Foreman::ParameterFilter.new(::AnsibleVariable).tap do |filter|
|
|
14
|
+
filter.permit :ansible_roles => [], :ansible_role_ids => [],
|
|
15
|
+
:ansible_role_names => [],
|
|
16
|
+
:param_classes => [], :param_classes_ids => [],
|
|
17
|
+
:param_classes_names => []
|
|
18
|
+
filter.permit_by_context :required, :nested => true
|
|
19
|
+
filter.permit_by_context :id, :ui => false, :api => false,
|
|
20
|
+
:nested => true
|
|
21
|
+
|
|
22
|
+
add_lookup_key_params_filter(filter)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def ansible_variable_params
|
|
28
|
+
self.class.ansible_variable_params_filter.filter_params(
|
|
29
|
+
params,
|
|
30
|
+
parameter_filter_context
|
|
31
|
+
)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ForemanAnsible
|
|
4
|
+
module Concerns
|
|
5
|
+
# Helpers to select proxy and call ProxyAPI
|
|
6
|
+
module ImportControllerHelper
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
|
|
9
|
+
included do
|
|
10
|
+
# rubocop:disable Rails/LexicallyScopedActionFilter
|
|
11
|
+
before_action :find_resource, :only => [:destroy]
|
|
12
|
+
before_action :find_proxy, :only => [:import]
|
|
13
|
+
before_action :create_importer, :only => [:import, :confirm_import]
|
|
14
|
+
before_action :default_order, :only => [:index]
|
|
15
|
+
# rubocop:enable Rails/LexicallyScopedActionFilter
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def find_proxy
|
|
19
|
+
return nil unless params[:proxy]
|
|
20
|
+
@proxy = SmartProxy.authorized(:view_smart_proxies).find(params[:proxy])
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ForemanAnsible
|
|
2
4
|
# This module takes the config reports stored in Foreman for Ansible and
|
|
3
5
|
# modifies them to be properly presented in views
|
|
@@ -12,8 +14,8 @@ module ForemanAnsible
|
|
|
12
14
|
].freeze
|
|
13
15
|
|
|
14
16
|
def ansible_module_name(log)
|
|
15
|
-
source_value = log.source
|
|
16
|
-
name = source_value.split(':')[0].strip if source_value
|
|
17
|
+
source_value = log.source&.value
|
|
18
|
+
name = source_value.split(':')[0].strip if source_value&.include?(':')
|
|
17
19
|
name
|
|
18
20
|
end
|
|
19
21
|
|
|
@@ -88,8 +90,8 @@ module ForemanAnsible
|
|
|
88
90
|
def parsed_message_json(log)
|
|
89
91
|
JSON.parse(log.message.value)
|
|
90
92
|
rescue StandardError => e
|
|
91
|
-
|
|
92
|
-
|
|
93
|
+
Foreman::Logging.exception('Error while parsing ansible message json', e)
|
|
94
|
+
{}
|
|
93
95
|
end
|
|
94
96
|
end
|
|
95
97
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ProxyAPI
|
|
2
4
|
# ProxyAPI for Ansible
|
|
3
5
|
class Ansible < ::ProxyAPI::Resource
|
|
@@ -24,5 +26,19 @@ module ProxyAPI
|
|
|
24
26
|
rescue *PROXY_ERRORS => e
|
|
25
27
|
raise ProxyException.new(url, e, N_('Unable to get roles from Ansible'))
|
|
26
28
|
end
|
|
29
|
+
|
|
30
|
+
def all_variables
|
|
31
|
+
parse(get('roles/variables'))
|
|
32
|
+
rescue *PROXY_ERRORS => e
|
|
33
|
+
raise ProxyException.new(url, e,
|
|
34
|
+
N_('Unable to get roles/variables from Ansible'))
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def variables(role)
|
|
38
|
+
parse(get("roles/#{role}/variables"))
|
|
39
|
+
rescue *PROXY_ERRORS => e
|
|
40
|
+
raise ProxyException.new(url, e,
|
|
41
|
+
N_('Unable to get roles/variables from Ansible'))
|
|
42
|
+
end
|
|
27
43
|
end
|
|
28
44
|
end
|
data/app/models/ansible_role.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Simple model to store basic info about the Ansible role
|
|
2
4
|
class AnsibleRole < ApplicationRecord
|
|
3
5
|
audited
|
|
@@ -10,6 +12,9 @@ class AnsibleRole < ApplicationRecord
|
|
|
10
12
|
has_many :hostgroup_ansible_roles
|
|
11
13
|
has_many :hostgroups, :through => :hostgroup_ansible_roles,
|
|
12
14
|
:dependent => :destroy
|
|
15
|
+
has_many :ansible_variables, :inverse_of => :ansible_role,
|
|
16
|
+
:dependent => :destroy,
|
|
17
|
+
:class_name => 'AnsibleVariable'
|
|
13
18
|
|
|
14
19
|
scoped_search :on => :name, :complete_value => true
|
|
15
20
|
scoped_search :on => :updated_at
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Represents the variables used in Ansible to parameterize playbooks
|
|
4
|
+
class AnsibleVariable < LookupKey
|
|
5
|
+
belongs_to :ansible_role, :inverse_of => :ansible_variables
|
|
6
|
+
validates :ansible_role, :presence => true
|
|
7
|
+
scoped_search :on => :key, :aliases => [:name], :complete_value => true
|
|
8
|
+
scoped_search :relation => :ansible_role, :on => :name,
|
|
9
|
+
:complete_value => true, :rename => :ansible_role
|
|
10
|
+
|
|
11
|
+
def ansible?
|
|
12
|
+
true
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.humanize_class_name
|
|
16
|
+
'Ansible variable'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def editable_by_user?
|
|
20
|
+
AnsibleVariable.authorized(:edit_external_parameters).
|
|
21
|
+
where(:id => id).exists?
|
|
22
|
+
end
|
|
23
|
+
end
|