foreman_ansible 2.2.14 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +2 -0
  3. data/app/controllers/ansible_roles_controller.rb +4 -11
  4. data/app/controllers/ansible_variables_controller.rb +80 -0
  5. data/app/controllers/api/v2/ansible_roles_controller.rb +2 -0
  6. data/app/controllers/api/v2/ansible_variables_controller.rb +68 -0
  7. data/app/controllers/concerns/foreman/controller/parameters/ansible_variable.rb +36 -0
  8. data/app/controllers/foreman_ansible/api/v2/hostgroups_controller_extensions.rb +2 -0
  9. data/app/controllers/foreman_ansible/api/v2/hostgroups_param_group_extensions.rb +2 -0
  10. data/app/controllers/foreman_ansible/api/v2/hosts_controller_extensions.rb +2 -0
  11. data/app/controllers/foreman_ansible/api/v2/hosts_param_group_extensions.rb +2 -0
  12. data/app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb +2 -0
  13. data/app/controllers/foreman_ansible/concerns/hosts_controller_extensions.rb +2 -0
  14. data/app/controllers/foreman_ansible/concerns/import_controller_helper.rb +24 -0
  15. data/app/controllers/foreman_ansible/concerns/job_invocation_helper.rb +2 -0
  16. data/app/helpers/foreman_ansible/ansible_plugin_helper.rb +2 -0
  17. data/app/helpers/foreman_ansible/ansible_reports_helper.rb +6 -4
  18. data/app/helpers/foreman_ansible/ansible_roles_helper.rb +2 -0
  19. data/app/helpers/foreman_ansible/hosts_helper_extensions.rb +2 -0
  20. data/app/lib/actions/foreman_ansible/helpers/host_common.rb +2 -0
  21. data/app/lib/actions/foreman_ansible/helpers/play_roles_description.rb +2 -0
  22. data/app/lib/proxy_api/ansible.rb +16 -0
  23. data/app/models/ansible_role.rb +5 -0
  24. data/app/models/ansible_variable.rb +23 -0
  25. data/app/models/concerns/foreman_ansible/host_managed_extensions.rb +3 -1
  26. data/app/models/concerns/foreman_ansible/hostgroup_extensions.rb +2 -0
  27. data/app/models/foreman_ansible/ansible_provider.rb +2 -0
  28. data/app/models/foreman_ansible/fact_name.rb +2 -0
  29. data/app/models/host_ansible_role.rb +2 -0
  30. data/app/models/hostgroup_ansible_role.rb +2 -0
  31. data/app/models/setting/ansible.rb +7 -5
  32. data/app/overrides/ansible_roles_tab.rb +2 -0
  33. data/app/overrides/ansible_variables_edit.rb +15 -0
  34. data/app/overrides/hostgroup_ansible_roles_tab.rb +2 -0
  35. data/app/overrides/hostgroup_play_roles.rb +2 -0
  36. data/app/overrides/report_output.rb +2 -0
  37. data/app/services/foreman_ansible/ansible_report_importer.rb +15 -0
  38. data/app/services/foreman_ansible/ansible_report_scanner.rb +2 -0
  39. data/app/services/foreman_ansible/api_roles_importer.rb +2 -0
  40. data/app/services/foreman_ansible/fact_importer.rb +2 -0
  41. data/app/services/foreman_ansible/fact_parser.rb +13 -1
  42. data/app/services/foreman_ansible/fact_sparser.rb +2 -0
  43. data/app/services/foreman_ansible/insights_notification_builder.rb +2 -0
  44. data/app/services/foreman_ansible/insights_plan_runner.rb +3 -2
  45. data/app/services/foreman_ansible/inventory_creator.rb +0 -6
  46. data/app/services/foreman_ansible/operating_system_parser.rb +3 -1
  47. data/app/services/foreman_ansible/playbook_creator.rb +2 -0
  48. data/app/services/foreman_ansible/proxy_api.rb +24 -0
  49. data/app/services/foreman_ansible/renderer_methods.rb +2 -0
  50. data/app/services/foreman_ansible/roles_importer.rb +4 -17
  51. data/app/services/foreman_ansible/structured_fact_importer.rb +2 -0
  52. data/app/services/foreman_ansible/ui_roles_importer.rb +2 -0
  53. data/app/services/foreman_ansible/variables_importer.rb +100 -0
  54. data/app/views/ansible_roles/index.html.erb +13 -3
  55. data/app/views/ansible_variables/_ansible_roles_list.html.erb +15 -0
  56. data/app/views/ansible_variables/_validator_text.html.erb +5 -0
  57. data/app/views/ansible_variables/edit.html.erb +17 -0
  58. data/app/views/ansible_variables/import.html.erb +53 -0
  59. data/app/views/ansible_variables/index.html.erb +46 -0
  60. data/app/views/api/v2/ansible_roles/import.json.rabl +2 -0
  61. data/app/views/api/v2/ansible_roles/index.json.rabl +2 -0
  62. data/app/views/api/v2/ansible_roles/obsolete.json.rabl +2 -0
  63. data/app/views/api/v2/ansible_roles/show.json.rabl +2 -0
  64. data/app/views/api/v2/ansible_variables/import.json.rabl +3 -0
  65. data/app/views/api/v2/ansible_variables/index.json.rabl +3 -0
  66. data/app/views/api/v2/ansible_variables/obsolete.json.rabl +3 -0
  67. data/app/views/api/v2/ansible_variables/show.json.rabl +20 -0
  68. data/app/views/foreman_ansible/api/v2/ansible_roles/import.json.rabl +2 -0
  69. data/app/views/foreman_ansible/api/v2/ansible_roles/index.json.rabl +2 -0
  70. data/app/views/foreman_ansible/api/v2/ansible_roles/obsolete.json.rabl +2 -0
  71. data/app/views/foreman_ansible/api/v2/ansible_roles/show.json.rabl +2 -0
  72. data/config/routes.rb +17 -0
  73. data/db/migrate/20160705082036_create_ansible_role.rb +2 -0
  74. data/db/migrate/20160706074540_create_join_table_hosts_ansible_roles.rb +2 -0
  75. data/db/migrate/20160707195442_create_host_ansible_roles.rb +2 -0
  76. data/db/migrate/20160729094457_add_columns_to_ansible_role.rb +2 -0
  77. data/db/migrate/20160802153302_create_join_table_hostgroup_ansible_roles.rb +2 -0
  78. data/db/migrate/20160805094233_add_primary_key_hostgroup_ansible_roles.rb +2 -0
  79. data/db/migrate/20161122154057_automatically_set_role_timestamps.rb +2 -0
  80. data/db/migrate/20180410125416_rename_ansible_job_categories.rb +6 -3
  81. data/db/migrate/20180628125416_add_ansible_role_id_to_lookup_keys.rb +14 -0
  82. data/db/seeds.d/62_ansible_proxy_feature.rb +2 -0
  83. data/db/seeds.d/75_job_templates.rb +3 -1
  84. data/db/seeds.d/90_notification_blueprints.rb +2 -0
  85. data/lib/foreman_ansible.rb +2 -0
  86. data/lib/foreman_ansible/engine.rb +2 -0
  87. data/lib/foreman_ansible/register.rb +28 -1
  88. data/lib/foreman_ansible/remote_execution.rb +2 -0
  89. data/lib/foreman_ansible/version.rb +3 -1
  90. data/locale/action_names.rb +2 -2
  91. data/locale/de/LC_MESSAGES/foreman_ansible.mo +0 -0
  92. data/locale/de/foreman_ansible.edit.po +444 -0
  93. data/locale/de/foreman_ansible.po +56 -17
  94. data/locale/de/foreman_ansible.po.time_stamp +0 -0
  95. data/locale/en/LC_MESSAGES/foreman_ansible.mo +0 -0
  96. data/locale/en/foreman_ansible.edit.po +442 -0
  97. data/locale/en/foreman_ansible.po +56 -17
  98. data/locale/en/foreman_ansible.po.time_stamp +0 -0
  99. data/locale/es/LC_MESSAGES/foreman_ansible.mo +0 -0
  100. data/locale/es/foreman_ansible.edit.po +444 -0
  101. data/locale/es/foreman_ansible.po +56 -17
  102. data/locale/es/foreman_ansible.po.time_stamp +0 -0
  103. data/locale/foreman_ansible.pot +174 -93
  104. data/locale/fr/LC_MESSAGES/foreman_ansible.mo +0 -0
  105. data/locale/fr/foreman_ansible.edit.po +444 -0
  106. data/locale/fr/foreman_ansible.po +56 -17
  107. data/locale/fr/foreman_ansible.po.time_stamp +0 -0
  108. data/locale/it/LC_MESSAGES/foreman_ansible.mo +0 -0
  109. data/locale/it/foreman_ansible.edit.po +444 -0
  110. data/locale/it/foreman_ansible.po +56 -17
  111. data/locale/it/foreman_ansible.po.time_stamp +0 -0
  112. data/locale/ja/LC_MESSAGES/foreman_ansible.mo +0 -0
  113. data/locale/ja/foreman_ansible.edit.po +444 -0
  114. data/locale/ja/foreman_ansible.po +56 -17
  115. data/locale/ja/foreman_ansible.po.time_stamp +0 -0
  116. data/locale/ko/LC_MESSAGES/foreman_ansible.mo +0 -0
  117. data/locale/ko/foreman_ansible.edit.po +444 -0
  118. data/locale/ko/foreman_ansible.po +56 -17
  119. data/locale/ko/foreman_ansible.po.time_stamp +0 -0
  120. data/locale/pt_BR/LC_MESSAGES/foreman_ansible.mo +0 -0
  121. data/locale/pt_BR/foreman_ansible.edit.po +444 -0
  122. data/locale/pt_BR/foreman_ansible.po +56 -17
  123. data/locale/pt_BR/foreman_ansible.po.time_stamp +0 -0
  124. data/locale/ru/LC_MESSAGES/foreman_ansible.mo +0 -0
  125. data/locale/ru/foreman_ansible.edit.po +445 -0
  126. data/locale/ru/foreman_ansible.po +56 -17
  127. data/locale/ru/foreman_ansible.po.time_stamp +0 -0
  128. data/locale/zh_CN/LC_MESSAGES/foreman_ansible.mo +0 -0
  129. data/locale/zh_CN/foreman_ansible.edit.po +444 -0
  130. data/locale/zh_CN/foreman_ansible.po +56 -17
  131. data/locale/zh_CN/foreman_ansible.po.time_stamp +0 -0
  132. data/locale/zh_TW/LC_MESSAGES/foreman_ansible.mo +0 -0
  133. data/locale/zh_TW/foreman_ansible.edit.po +444 -0
  134. data/locale/zh_TW/foreman_ansible.po +56 -17
  135. data/locale/zh_TW/foreman_ansible.po.time_stamp +0 -0
  136. data/test/factories/ansible_proxy.rb +2 -0
  137. data/test/factories/ansible_roles.rb +2 -0
  138. data/test/factories/ansible_variables.rb +8 -0
  139. data/test/functional/ansible_roles_controller_test.rb +2 -0
  140. data/test/functional/ansible_variables_controller_test.rb +36 -0
  141. data/test/functional/api/v2/ansible_roles_controller_test.rb +21 -9
  142. data/test/functional/api/v2/ansible_variables_controller_test.rb +41 -0
  143. data/test/functional/api/v2/hostgroups_controller_test.rb +2 -0
  144. data/test/functional/api/v2/hosts_controller_test.rb +2 -0
  145. data/test/functional/hosts_controller_test.rb +2 -0
  146. data/test/test_plugin_helper.rb +2 -0
  147. data/test/unit/ansible_provider_test.rb +2 -0
  148. data/test/unit/ansible_role_test.rb +5 -9
  149. data/test/unit/ansible_variable_test.rb +14 -0
  150. data/test/unit/concerns/config_reports_extensions_test.rb +2 -0
  151. data/test/unit/concerns/host_managed_extensions_test.rb +2 -0
  152. data/test/unit/concerns/hostgroup_extensions_test.rb +2 -0
  153. data/test/unit/helpers/ansible_reports_helper_test.rb +2 -0
  154. data/test/unit/host_ansible_role_test.rb +2 -0
  155. data/test/unit/hostgroup_ansible_role_test.rb +2 -0
  156. data/test/unit/lib/foreman_ansible_core/command_creator_test.rb +2 -0
  157. data/test/unit/lib/foreman_ansible_core/playbook_runner_test.rb +2 -0
  158. data/test/unit/lib/proxy_api/ansible_test.rb +2 -0
  159. data/test/unit/services/ansible_report_importer_test.rb +15 -0
  160. data/test/unit/services/ansible_variables_importer_test.rb +39 -0
  161. data/test/unit/services/api_roles_importer_test.rb +2 -0
  162. data/test/unit/services/fact_importer_test.rb +2 -0
  163. data/test/unit/services/fact_parser_test.rb +47 -0
  164. data/test/unit/services/fact_sparser_test.rb +2 -0
  165. data/test/unit/services/insights_plan_runner_test.rb +2 -0
  166. data/test/unit/services/inventory_creator_test.rb +1 -13
  167. data/test/unit/services/roles_importer_test.rb +2 -0
  168. data/test/unit/services/structured_fact_importer_test.rb +2 -0
  169. data/test/unit/services/ui_roles_importer_test.rb +2 -0
  170. metadata +101 -42
  171. 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: 9fe5dcbfcc552d6c416de77ef25a716f4f88c873
4
- data.tar.gz: abc7f71191be7c080ffcd5a95c5a4fc7c4d6f700
3
+ metadata.gz: 0dc5e5a7b0474fef241b4607911073f5e3b94bbc
4
+ data.tar.gz: 0e57147506ec6cac87ca5107e832bfe80d594ecb
5
5
  SHA512:
6
- metadata.gz: 3bcaf1df6a76b741140c3cb550c3e2c0b7e606dafc20d76d4638d89ce921f22696923b5e1fe90cf8fa8730606e5ac6e7a9c2219c145bb8f3f396662ab2da27cb
7
- data.tar.gz: '09e53ac570633a62e5a7c2aff18c9712aa702020fd532c9202d335ccf636030a9596b8fbc244f3efe9185e49172ef899fc8893278b5a1c80533375dbb885d6d7'
6
+ metadata.gz: aca0209523ab2b7eac8ad76877ef2946a1a7fa9ce04c860cb972dcee73296f8d9c7afeac575170265a0a946084e5f5d2d0393628deeaf624a5d18784809bcae2
7
+ data.tar.gz: 44db93653e958c13d72d80e68f8c7b188c59059078b942397d25664cbda18ec1756b0a709e3e15c75ba4aee319622f31a77f615894b4210f0a155f9fcca5634d
data/Rakefile CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env rake
2
+ # frozen_string_literal: true
3
+
2
4
  begin
3
5
  require 'bundler/setup'
4
6
  rescue LoadError
@@ -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].to_unsafe_h)
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Api
2
4
  module V2
3
5
  # API controller for Ansible Roles
@@ -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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanAnsible
2
4
  module Api
3
5
  module V2
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanAnsible
2
4
  module Api
3
5
  module V2
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanAnsible
2
4
  module Api
3
5
  module V2
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanAnsible
2
4
  module Api
3
5
  module V2
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanAnsible
2
4
  module Concerns
3
5
  # Extra methods to enforce Ansible roles on a host or multiple hosts
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanAnsible
2
4
  module Concerns
3
5
  # Extra methods to enforce Ansible roles on a host or multiple hosts
@@ -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
  module Concerns
3
5
  # Helpers to compose the JobInvocation in other controllers
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "#{ForemanAnsible::Engine.root}/lib/foreman_ansible/version"
2
4
 
3
5
  module ForemanAnsible
@@ -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.value
16
- name = source_value.split(':')[0].strip if source_value.include?(':')
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
- logger.error e
92
- false
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 ForemanAnsible
2
4
  # Small convenience to list all roles in the UI
3
5
  module AnsibleRolesHelper
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanAnsible
2
4
  # Chained methods to extend the hosts menu with Ansible actions
3
5
  module HostsHelperExtensions
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Actions
2
4
  module ForemanAnsible
3
5
  module Helpers
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Actions
2
4
  module ForemanAnsible
3
5
  module Helpers
@@ -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
@@ -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