foreman_ansible 2.3.1 → 2.3.2

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.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/api/v2/ansible_override_values_controller.rb +2 -2
  3. data/app/controllers/foreman_ansible/api/v2/hostgroups_controller_extensions.rb +20 -3
  4. data/app/controllers/foreman_ansible/api/v2/hosts_controller_extensions.rb +20 -3
  5. data/app/controllers/foreman_ansible/concerns/api_common.rb +17 -0
  6. data/app/helpers/foreman_ansible/hosts_helper_extensions.rb +0 -20
  7. data/app/models/concerns/foreman_ansible/host_managed_extensions.rb +1 -16
  8. data/app/services/foreman_ansible/ansible_info.rb +18 -0
  9. data/app/services/foreman_ansible/insights_plan_runner.rb +2 -1
  10. data/app/services/foreman_ansible/inventory_creator.rb +6 -2
  11. data/app/services/foreman_ansible/operating_system_parser.rb +3 -7
  12. data/app/views/ansible_roles/index.html.erb +1 -1
  13. data/app/views/ansible_variables/_fields.erb +67 -0
  14. data/app/views/ansible_variables/edit.html.erb +1 -1
  15. data/app/views/ansible_variables/index.html.erb +5 -5
  16. data/config/routes.rb +9 -6
  17. data/db/seeds.d/90_notification_blueprints.rb +1 -1
  18. data/lib/foreman_ansible/register.rb +12 -2
  19. data/lib/foreman_ansible/remote_execution.rb +3 -2
  20. data/lib/foreman_ansible/version.rb +1 -1
  21. data/test/functional/api/v2/hostgroups_controller_test.rb +13 -0
  22. data/test/functional/api/v2/hosts_controller_test.rb +14 -0
  23. data/test/unit/services/fact_parser_test.rb +10 -4
  24. data/test/unit/services/inventory_creator_test.rb +1 -1
  25. metadata +5 -5
  26. data/app/overrides/ansible_variables_edit.rb +0 -15
  27. data/app/views/ansible_variables/_ansible_roles_list.html.erb +0 -15
  28. data/app/views/ansible_variables/_validator_text.html.erb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '08c99d39eecf64143f22351c6320d62cfb1f3314'
4
- data.tar.gz: 42133e0cf37fedd36eead1368ae2e05411cc9ab7
3
+ metadata.gz: 3dd4a02656d2b41202e38c91fda9cd2b5b7bfb08
4
+ data.tar.gz: a7f7f75580a6d389b09dd3a1bb47c4420b1ffab2
5
5
  SHA512:
6
- metadata.gz: c3d1e4d553a4621b0a40a19206369dcc3263cdbbb37ad81a23f2a65c36b2a3f06c7bb91d39f2e4f02051409b19be0323112b5949b2c3aeaa267304c5253e8090
7
- data.tar.gz: 58a3841d303c241512ee7a8ff947f851fd55ed34132b482919bbea8d6a256262dc15a3b4a774cdc4a63a4575acd1aa94d9849ec9b9b7600f2ea14f4420cfba25
6
+ metadata.gz: 52866dabe9b2a7bac15bc23920541c896cc337304a1bafcfbe057645ea73c85939cdbc989cec226c7f32f61b254891b345b7720bb1d771074f25ece5feea4d39
7
+ data.tar.gz: afdbf297b5fe851adb1a71352b7b821b109d203ad094b51ede3f0d7f3658ea0d358f84022040c056bccf8e12b0810e9b68e2c7db0ae3c15488a44825080bc29c
@@ -25,7 +25,7 @@ module Api
25
25
 
26
26
  def create
27
27
  @ansible_variable = AnsibleVariable.authorized(:edit_external_variables).
28
- find_by_id(params[:ansible_variable_id].to_i)
28
+ find_by(:id => params[:ansible_variable_id].to_i)
29
29
  @override_value = @ansible_variable.lookup_values.create!(lookup_value_params['override_value'])
30
30
  @ansible_variable.update_attribute(:override, true)
31
31
  render 'api/v2/ansible_override_values/show'
@@ -35,7 +35,7 @@ module Api
35
35
  param :id, :identifier, :required => true
36
36
 
37
37
  def destroy
38
- @override_value = LookupValue.find_by_id(params[:id])
38
+ @override_value = LookupValue.find_by(:id => params[:id])
39
39
  if @override_value
40
40
  @ansible_variable = AnsibleVariable.where(:id => @override_value.lookup_key_id)
41
41
  @override_value.destroy
@@ -8,11 +8,14 @@ module ForemanAnsible
8
8
  extend ActiveSupport::Concern
9
9
  include ForemanTasks::Triggers
10
10
  include ::ForemanAnsible::Concerns::JobInvocationHelper
11
+ include ::ForemanAnsible::Concerns::ApiCommon
11
12
 
12
13
  # Included blocks shouldn't be bound by length, as otherwise concerns
13
14
  # cannot extend the method properly.
14
- # rubocop:disable BlockLength
15
+ # rubocop:disable BlockLength, Rails/LexicallyScopedActionFilter
15
16
  included do
17
+ before_action :find_ansible_roles, :only => [:assign_ansible_roles]
18
+
16
19
  api :POST, '/hostgroups/:id/play_roles',
17
20
  N_('Plays Ansible roles on a hostgroup')
18
21
  param :id, :identifier, :required => true
@@ -42,10 +45,23 @@ module ForemanAnsible
42
45
  def ansible_roles
43
46
  find_resource
44
47
  return unless @hostgroup
48
+
45
49
  @ansible_roles = @hostgroup.all_ansible_roles
46
50
  end
51
+
52
+ api :POST, '/hostgroups/:id/assign_ansible_roles',
53
+ N_('Assigns Ansible roles to a hostgroup')
54
+ param :id, :identifier, :required => true
55
+ param :ansible_role_ids, Array,
56
+ N_('Ansible roles to assign to a hostgroup'),
57
+ :required => true
58
+
59
+ def assign_ansible_roles
60
+ find_resource
61
+ process_response @hostgroup.update(:ansible_roles => @ansible_roles)
62
+ end
47
63
  end
48
- # rubocop:enable BlockLength
64
+ # rubocop:enable BlockLength, Rails/LexicallyScopedActionFilter
49
65
 
50
66
  private
51
67
 
@@ -64,7 +80,8 @@ module ForemanAnsible
64
80
 
65
81
  def action_permission
66
82
  case params[:action]
67
- when 'play_roles', 'multiple_play_roles', 'ansible_roles'
83
+ when 'play_roles', 'multiple_play_roles', 'ansible_roles',
84
+ 'assign_ansible_roles'
68
85
  :view
69
86
  else
70
87
  super
@@ -8,13 +8,17 @@ module ForemanAnsible
8
8
  extend ActiveSupport::Concern
9
9
  include ForemanTasks::Triggers
10
10
  include ::ForemanAnsible::Concerns::JobInvocationHelper
11
+ include ::ForemanAnsible::Concerns::ApiCommon
11
12
 
12
13
  # Included blocks shouldn't be bound by length, as otherwise concerns
13
14
  # cannot extend the method properly.
14
- # rubocop:disable BlockLength
15
+ # rubocop:disable BlockLength, Rails/LexicallyScopedActionFilter
15
16
  included do
17
+ before_action :find_ansible_roles, :only => [:assign_ansible_roles]
18
+
16
19
  def find_resource
17
20
  return true if params[:action] == 'multiple_play_roles'
21
+
18
22
  super
19
23
  end
20
24
 
@@ -44,16 +48,29 @@ module ForemanAnsible
44
48
 
45
49
  def ansible_roles
46
50
  return unless @host
51
+
47
52
  @ansible_roles = @host.all_ansible_roles
48
53
  end
54
+
55
+ api :POST, '/hosts/:id/assign_ansible_roles',
56
+ N_('Assigns Ansible roles to a host')
57
+ param :id, :identifier, :required => true
58
+ param :ansible_role_ids, Array,
59
+ N_('Ansible roles to assign to a host'),
60
+ :required => true
61
+
62
+ def assign_ansible_roles
63
+ process_response @host.update(:ansible_roles => @ansible_roles)
64
+ end
49
65
  end
50
- # rubocop:enable BlockLength
66
+ # rubocop:enable BlockLength, Rails/LexicallyScopedActionFilter
51
67
 
52
68
  private
53
69
 
54
70
  def action_permission
55
71
  case params[:action]
56
- when 'play_roles', 'multiple_play_roles', 'ansible_roles'
72
+ when 'play_roles', 'multiple_play_roles', 'ansible_roles',
73
+ 'assign_ansible_roles'
57
74
  :view
58
75
  else
59
76
  super
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForemanAnsible
4
+ module Concerns
5
+ # Shared task methods between api controllers
6
+ module ApiCommon
7
+ extend ActiveSupport::Concern
8
+
9
+ def find_ansible_roles
10
+ ids = params.fetch(:ansible_role_ids, []) || []
11
+ @ansible_roles = AnsibleRole.authorized(:view_ansible_roles).find(ids)
12
+ rescue ActiveRecord::RecordNotFound => e
13
+ not_found(e.message)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -6,16 +6,6 @@ module ForemanAnsible
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  module Overrides
9
- def host_title_actions(*args)
10
- host = args.first
11
- if ansible_roles_present?(host) &&
12
- User.current.can?(:create_job_invocations)
13
- button = ansible_roles_button(host)
14
- title_actions(button_group(button))
15
- end
16
- super(*args)
17
- end
18
-
19
9
  def multiple_actions
20
10
  actions = super
21
11
  if User.current.can?(:create_job_invocations) &&
@@ -36,15 +26,5 @@ module ForemanAnsible
36
26
  host.ansible_roles.present? ||
37
27
  host.inherited_ansible_roles.present?
38
28
  end
39
-
40
- def ansible_roles_button(host)
41
- display_link_if_authorized(
42
- _('Run Ansible roles'),
43
- hash_for_play_roles_host_path(:id => host.id),
44
- :id => :ansible_roles_button,
45
- :class => 'btn btn-default',
46
- :'data-no-turbolink' => true
47
- )
48
- end
49
29
  end
50
30
  end
@@ -13,7 +13,7 @@ module ForemanAnsible
13
13
  has_many :ansible_roles, :through => :host_ansible_roles,
14
14
  :dependent => :destroy
15
15
  scoped_search :relation => :ansible_roles, :on => :name,
16
- :complete_value => true, :rename => :role,
16
+ :complete_value => true, :rename => :ansible_role,
17
17
  :only_explicit => true
18
18
 
19
19
  before_provision :play_ansible_roles
@@ -53,21 +53,6 @@ module ForemanAnsible
53
53
  (ansible_roles + inherited_ansible_roles).uniq
54
54
  end
55
55
 
56
- def host_params_hash
57
- values = AnsibleVariable.where(:ansible_role_id => all_ansible_roles.pluck(:id)).
58
- values_hash(self).raw.values
59
- transformed = values.each_with_object({}) do |item, memo|
60
- item.map do |name, hash|
61
- variable = AnsibleVariable.find_by :key => name
62
- safe_value = variable.hidden_value? ? variable.safe_value : hash[:value]
63
- memo[name] = { :value => hash[:value], :safe_value => safe_value, :source => 'global' }
64
- end
65
- memo
66
- end
67
-
68
- super.merge transformed
69
- end
70
-
71
56
  # rubocop:enable Metrics/BlockLength
72
57
  # Class methods we may need to override or add
73
58
  module ClassMethods
@@ -0,0 +1,18 @@
1
+ module ForemanAnsible
2
+ class AnsibleInfo < ::HostInfo::Provider
3
+ def host_info
4
+ { 'parameters' => ansible_params }
5
+ end
6
+
7
+ def ansible_params
8
+ variables = AnsibleVariable.where(:ansible_role_id => host.all_ansible_roles.pluck(:id), :override => true)
9
+ values = variables.values_hash(host)
10
+
11
+ variables.each_with_object({}) do |var, memo|
12
+ value = values[var]
13
+ memo[var.key] = value if value
14
+ memo
15
+ end
16
+ end
17
+ end
18
+ end
@@ -32,7 +32,8 @@ if defined?(RedhatAccess)
32
32
  resource = RestClient::Resource.new(
33
33
  "#{insights_api_host}/r/insights/"\
34
34
  "v3/maintenance/#{@plan_id}/playbook",
35
- get_ssl_options_for_org(@organization, nil)
35
+ get_ssl_options_for_org(@organization, nil).\
36
+ merge(:proxy => get_portal_http_proxy)
36
37
  )
37
38
  @raw_playbook = resource.get.body
38
39
  YAML.safe_load(@raw_playbook)
@@ -22,7 +22,7 @@ module ForemanAnsible
22
22
  hosts = @hosts.map(&:name)
23
23
 
24
24
  { 'all' => { 'hosts' => hosts,
25
- 'vars' => template_inputs(@template_invocation) },
25
+ 'vars' => template_inputs(@template_invocation) },
26
26
  '_meta' => { 'hostvars' => hosts_vars } }
27
27
  end
28
28
 
@@ -43,7 +43,7 @@ module ForemanAnsible
43
43
  if Setting['top_level_ansible_vars']
44
44
  result = result.merge(host_params(host))
45
45
  end
46
- result
46
+ result.merge(ansible_params(host))
47
47
  end
48
48
 
49
49
  def connection_params(host)
@@ -68,6 +68,10 @@ module ForemanAnsible
68
68
  render_rabl(host, 'api/v2/hosts/main')
69
69
  end
70
70
 
71
+ def ansible_params(host)
72
+ ForemanAnsible::AnsibleInfo.new(host).ansible_params
73
+ end
74
+
71
75
  def host_params(host)
72
76
  host.host_params
73
77
  end
@@ -5,7 +5,7 @@ module ForemanAnsible
5
5
  module OperatingSystemParser
6
6
  def operatingsystem
7
7
  args = { :name => os_name, :major => os_major, :minor => os_minor }
8
- args[:release_name] = os_release_name if os_name == 'Debian'
8
+ args[:release_name] = os_release_name if os_name == 'Debian' || os_name == 'Ubuntu'
9
9
  return @local_os if local_os(args).present?
10
10
  return @new_os if new_os(args).present?
11
11
  logger.debug do
@@ -40,13 +40,9 @@ module ForemanAnsible
40
40
  end
41
41
  end
42
42
 
43
- def deb_release_map
44
- { '7' => 'wheezy', '8' => 'jessie', '9' => 'stretch', '10' => 'buster' }
45
- end
46
-
47
43
  def os_release_name
48
- return '' unless os_name == 'Debian'
49
- deb_release_map[debian_os_major_sid]
44
+ return '' if os_name != 'Debian' && os_name != 'Ubuntu'
45
+ facts[:ansible_distribution_release]
50
46
  end
51
47
 
52
48
  # rubocop:disable AbcSize, CyclomaticComplexity, PerceivedComplexity
@@ -18,7 +18,7 @@
18
18
  <tr>
19
19
  <td class="ellipsis"><%= role.name %></td>
20
20
  <td class="ellipsis"><%= role.hostgroups.count %></td>
21
- <td class="ellipsis"><%= link_to role.hosts.count, hosts_path(:search => "role = #{role.name}")%></td>
21
+ <td class="ellipsis"><%= link_to role.hosts.count, hosts_path(:search => "ansible_role = #{role.name}")%></td>
22
22
  <td class="ellipsis"><%= import_time role %></td>
23
23
  <td>
24
24
  <%
@@ -0,0 +1,67 @@
1
+ <div id='<%= f.object.to_param %>' class='tab-pane fields'>
2
+ <fieldset>
3
+ <h2><%= _("Ansible Variable Details") %></h2>
4
+ <%= text_f f, :key, :disabled => true, :size => "col-md-8" %>
5
+ <%= f.hidden_field :key %>
6
+ <%= textarea_f f, :description, :rows => :auto, :size => "col-md-8", :class => "no-stretch" %>
7
+ <%= select_f f, :ansible_role_id, [f.object.ansible_role], :id, :to_label, {}, :label => _("Ansible Role"), :disabled => true %>
8
+ </fieldset>
9
+ <fieldset>
10
+ <h2><%= _("Default Behavior") %></h2>
11
+ <h6><%= _("Override the default value of the Ansible variable.") %></h6>
12
+ <%= checkbox_f(f, :override, :onchange => 'toggleOverrideValue(this)', :size => "col-md-8",
13
+ :label_help => _('Mark the variable to be managed by Foreman. When the Ansible role of this variable is assigned to a host, the default value will be added to Ansible inventory as a host variable. Specify matchers to set a different value for such variable.')
14
+ ) %>
15
+ <%= param_type_selector(f, false, :onchange => 'keyTypeChange(this)', :disabled => !f.object.override) %>
16
+ <%= textarea_f f, :default_value, :value => f.object.default_value_before_type_cast, :size => "col-md-8",
17
+ :disabled => (!f.object.override || f.object.omit),
18
+ :input_group_btn => fullscreen_input,
19
+ :rows => 1,
20
+ :label_help => _("Value to use when there is no match."),
21
+ :class => "no-stretch #{'masked-input' if f.object.hidden_value?}" %>
22
+ <div class="form-group">
23
+ <%= checkbox_f(f, :hidden_value, :label => _('Hidden Value'),
24
+ :class => 'hidden_value_textarea_switch', :onchange => 'toggle_lookupkey_hidden(this)',
25
+ :checked => f.object.hidden_value?,
26
+ :label_help => _("Hide all values for this parameter."),
27
+ :size => "col-md-1", :label_size => "col-md-2", :table_field => true,
28
+ :disabled => !f.object.override) %>
29
+ </div>
30
+ </fieldset>
31
+ <fieldset>
32
+ <%= collapsing_header _("Optional Input Validator"), "#optional_input_validators_#{f.object.id}", "collapsed" %>
33
+ <div id="optional_input_validators_<%= f.object.id %>" class="collapse out">
34
+ <h6><%= _('Before including these variables on your playbooks, Foreman will validate that your variables comply with the validation.') %></h6>
35
+
36
+ <%= checkbox_f(f, :required, :size => "col-md-8", :disabled => !f.object.override,
37
+ :label_help => _("If checked, will raise an error if there is no default value and no matcher provide a value.")
38
+ ) %>
39
+ <%= validator_type_selector f %>
40
+ <%= text_f f, :validator_rule, :size => "col-md-8", :disabled => f.object.validator_type.blank?, :class => "no-stretch" %>
41
+ </div>
42
+ </fieldset>
43
+ </br>
44
+ <div class="matcher-parent" <%= "id=#{f.object.key.to_s.gsub(' ', '_')}_lookup_key_override_value" %> style=<%= "display:none;" if !f.object.override %>>
45
+ <fieldset>
46
+ <h2><%= _("Prioritize Attribute Order") %></h2>
47
+ <h6><%= _("Set the order in which values are resolved.") %></h6>
48
+ <%= textarea_f f, :path, :rows => :auto, :label => _("Order"), :id => 'order', :size => "col-md-8", :onchange => 'fill_in_matchers()', :value => f.object.path, :class => "no-stretch",
49
+ :label_help => _("The order in which matchers keys are processed, first match wins.<br> You may use multiple attributes as a matcher key, for example, an order of <code>host group, environment</code> would expect a matcher such as <code>hostgroup = \"web servers\", environment = production</code>").html_safe %>
50
+ <%= checkbox_f(f, :merge_overrides, :onchange => 'mergeOverridesChanged(this)', :table_field => true,
51
+ :disabled => !f.object.supports_merge?, :size => "col-md-1", :label_size => "col-md-2",
52
+ :label_help => _("Continue to look for matches after first find (only array/hash type)? Note: merging overrides ignores all matchers that are omitted.")) %>
53
+ <%= checkbox_f(f, :merge_default, :disabled => !f.object.merge_overrides, :size => "col-md-1", :table_field => true,
54
+ :label_size => "col-md-2", :label_help => _("Include default value when merging all matching values.")) %>
55
+ <%= checkbox_f(f, :avoid_duplicates, :disabled => (!f.object.supports_uniq? || !f.object.merge_overrides),
56
+ :size => "col-md-1", :label_size => "col-md-2", :table_field => true,
57
+ :label_help => _("Avoid duplicate values when merging them (only array type)?")) %>
58
+ </fieldset>
59
+ </br>
60
+ <fieldset>
61
+ <h2><%= _("Specify Matchers") %> <%= documentation_button('4.2.6SmartMatchers') %></h2>
62
+ <div class="children_fields lookup_values">
63
+ <%= render 'lookup_keys/values', :f => f, :is_param => false %>
64
+ </div>
65
+ </fieldset>
66
+ </div>
67
+ </div>
@@ -12,6 +12,6 @@
12
12
  ) %>
13
13
  <% title(_('Edit Ansible Variable')) %>
14
14
  <%= form_for(@ansible_variable) do |f| %>
15
- <%= render 'lookup_keys/fields', :f => f %>
15
+ <%= render 'fields', :f => f %>
16
16
  <%= submit_or_cancel f %>
17
17
  <% end %>
@@ -16,11 +16,11 @@
16
16
  <% @ansible_variables.each do |variable| %>
17
17
  <tr>
18
18
  <td class="ellipsis"><%= link_to_if_authorized(
19
- variable.key,
20
- hash_for_edit_ansible_variable_path(:id => variable).
21
- merge(:auth_object => variable,
22
- :permission => 'edit_external_parameters',
23
- :authorizer => authorizer)
19
+ icon_text((variable.override ? "flag": ""), variable.key.to_s, :kind => 'fa', :title => _('Overriden')),
20
+ hash_for_edit_ansible_variable_path(:id => variable).
21
+ merge(:auth_object => variable,
22
+ :permission => 'edit_external_parameters',
23
+ :authorizer => authorizer)
24
24
  ) %></td>
25
25
  <td class="ellipsis"><%= link_to_if_authorized(
26
26
  variable.ansible_role.name,
data/config/routes.rb CHANGED
@@ -4,9 +4,9 @@
4
4
  Rails.application.routes.draw do
5
5
  namespace :api do
6
6
  scope '(:apiv)',
7
- :module => :v2,
8
- :defaults => { :apiv => 'v2' },
9
- :apiv => /v1|v2/,
7
+ :module => :v2,
8
+ :defaults => { :apiv => 'v2' },
9
+ :apiv => /v1|v2/,
10
10
  :constraints => ApiConstraints.new(:version => 2) do
11
11
 
12
12
  constraints(:id => %r{[^\/]+}) do
@@ -14,6 +14,7 @@ Rails.application.routes.draw do
14
14
  member do
15
15
  post :play_roles
16
16
  get :ansible_roles
17
+ post :assign_ansible_roles
17
18
  end
18
19
  collection do
19
20
  post :multiple_play_roles
@@ -23,6 +24,7 @@ Rails.application.routes.draw do
23
24
  member do
24
25
  post :play_roles
25
26
  get :ansible_roles
27
+ post :assign_ansible_roles
26
28
  end
27
29
  collection do
28
30
  post :multiple_play_roles
@@ -52,6 +54,7 @@ Rails.application.routes.draw do
52
54
  collection do
53
55
  get :import
54
56
  post :confirm_import
57
+ get 'auto_complete_search'
55
58
  end
56
59
  end
57
60
 
@@ -66,9 +69,9 @@ Rails.application.routes.draw do
66
69
 
67
70
  namespace :api do
68
71
  scope '(:apiv)',
69
- :module => :v2,
70
- :defaults => { :apiv => 'v2' },
71
- :apiv => /v1|v2/,
72
+ :module => :v2,
73
+ :defaults => { :apiv => 'v2' },
74
+ :apiv => /v1|v2/,
72
75
  :constraints => ApiConstraints.new(:version => 2) do
73
76
 
74
77
  resources :ansible_roles, :only => [:show, :index, :destroy] do
@@ -7,7 +7,7 @@ blueprints = [
7
7
  :message => N_('Insights remediation on %{hosts_count}' \
8
8
  ' host(s) has finished successfully'),
9
9
  :level => 'success',
10
- :actions => {
10
+ :actions => {
11
11
  :links => [
12
12
  :path_method => :job_invocation_path,
13
13
  :title => N_('Job Details')
@@ -16,7 +16,7 @@ Foreman::Plugin.register :foreman_ansible do
16
16
  :multiple_play_roles] },
17
17
  :resource_type => 'Hostgroup'
18
18
  permission :view_ansible_roles,
19
- { :ansible_roles => [:index],
19
+ { :ansible_roles => [:index, :auto_complete_search],
20
20
  :'api/v2/ansible_roles' => [:index, :show, :fetch] },
21
21
  :resource_type => 'AnsibleRole'
22
22
  permission :destroy_ansible_roles,
@@ -34,7 +34,9 @@ Foreman::Plugin.register :foreman_ansible do
34
34
  },
35
35
  :resource_type => 'AnsibleVariable'
36
36
  permission :edit_ansible_variables,
37
- { :ansible_variables => [:edit, :update] },
37
+ { :ansible_variables => [:edit, :update],
38
+ :'api/v2/ansible_variables' => [:update],
39
+ :'api/v2/ansible_override_values' => [:create, :destroy] },
38
40
  :resource_type => 'AnsibleVariable'
39
41
  permission :destroy_ansible_variables,
40
42
  {
@@ -54,6 +56,12 @@ Foreman::Plugin.register :foreman_ansible do
54
56
  permission :view_hostgroups,
55
57
  { :'api/v2/hostgroups' => [:ansible_roles] },
56
58
  :resource_type => 'Hostgroup'
59
+ permission :edit_hosts,
60
+ { :'api/v2/hosts' => [:assign_ansible_roles] },
61
+ :resource_type => 'Host'
62
+ permission :edit_hostgroups,
63
+ { :'api/v2/hostgroups' => [:assign_ansible_roles] },
64
+ :resource_type => 'Hostgroup'
57
65
  end
58
66
 
59
67
  role 'Ansible Roles Manager',
@@ -84,6 +92,8 @@ Foreman::Plugin.register :foreman_ansible do
84
92
  "#{ForemanAnsible::Engine.root}/app/controllers/api/v2/*.rb"
85
93
  ]
86
94
 
95
+ register_info_provider ForemanAnsible::AnsibleInfo
96
+
87
97
  # For backwards compatiblity with 1.17
88
98
  if respond_to?(:register_report_scanner)
89
99
  register_report_scanner ForemanAnsible::AnsibleReportScanner
@@ -17,9 +17,10 @@ module ForemanAnsible
17
17
  def self.register_rex_feature
18
18
  RemoteExecutionFeature.register(
19
19
  :ansible_run_host,
20
- N_('Ansible: Run host roles'),
20
+ N_('Run Ansible roles'),
21
21
  :description => N_('Runs an Ansible playbook which contains all'\
22
- ' the roles defined for a host')
22
+ ' the roles defined for a host'),
23
+ :host_action_button => true
23
24
  )
24
25
  RemoteExecutionFeature.register(
25
26
  :ansible_run_insights_plan,
@@ -4,5 +4,5 @@
4
4
  # This way other parts of Foreman can just call ForemanAnsible::VERSION
5
5
  # and detect what version the plugin is running.
6
6
  module ForemanAnsible
7
- VERSION = '2.3.1'
7
+ VERSION = '2.3.2'
8
8
  end
@@ -49,6 +49,19 @@ module Api
49
49
  response = JSON.parse(@response.body)
50
50
  assert_equal @ansible_role1.id, response.first['id']
51
51
  end
52
+
53
+ test 'should assign a role to a hostgroup' do
54
+ hostgroup = FactoryBot.create(:hostgroup,
55
+ :ansible_role_ids => [])
56
+ post :assign_ansible_roles,
57
+ :params => {
58
+ :id => hostgroup.id,
59
+ :ansible_role_ids => [@ansible_role1.id]
60
+ },
61
+ :session => set_session_user
62
+ assert_response :success
63
+ assert assigns('hostgroup').ansible_roles, [@ansible_role1]
64
+ end
52
65
  end
53
66
  end
54
67
  end
@@ -72,6 +72,20 @@ module Api
72
72
  response = JSON.parse(@response.body)
73
73
  assert_equal @ansible_role1.id, response.first['id']
74
74
  end
75
+
76
+ test 'should assign a role to a host' do
77
+ host = FactoryBot.create(:host,
78
+ :managed => false,
79
+ :ansible_role_ids => [])
80
+ post :assign_ansible_roles,
81
+ :params => {
82
+ :id => host.id,
83
+ :ansible_role_ids => [@ansible_role1.id]
84
+ },
85
+ :session => set_session_user
86
+ assert_response :success
87
+ assert assigns('host').ansible_roles, [@ansible_role1]
88
+ end
75
89
  end
76
90
  end
77
91
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'test_plugin_helper'
3
4
 
4
5
  module ForemanAnsible
@@ -115,18 +116,23 @@ module ForemanAnsible
115
116
  '_timestamp' => '2015-10-29 20:01:51 +0100',
116
117
  'ansible_facts' =>
117
118
  {
118
- 'ansible_distribution_major_version' => 'buster/sid',
119
- 'ansible_distribution' => 'Debian'
119
+ "ansible_distribution" => "Debian",
120
+ "ansible_distribution_file_parsed" => true,
121
+ "ansible_distribution_file_path" => "/etc/os-release",
122
+ "ansible_distribution_file_variety" => "Debian",
123
+ "ansible_distribution_major_version" => "8",
124
+ "ansible_distribution_release" => "jessie",
125
+ "ansible_distribution_version" => "8.7"
120
126
  }
121
127
  )
122
128
  )
123
129
  end
124
130
 
125
- test 'Parses debian unstable aka sid correctly' do
131
+ test 'Parses debian jessie correctly' do
126
132
  as_admin do
127
133
  os = @facts_parser.operatingsystem
128
134
 
129
- assert_equal '10', os.major
135
+ assert_equal '8', os.major
130
136
  assert_equal 'Debian', os.name
131
137
  end
132
138
  end
@@ -11,7 +11,7 @@ module ForemanAnsible
11
11
  @host = FactoryBot.build(:host)
12
12
  @template_invocation = OpenStruct.new(
13
13
  :job_invocation => OpenStruct.new(:password => 'foobar',
14
- :sudo_password => 'foobar'),
14
+ :sudo_password => 'foobar'),
15
15
  :effective_user => 'foobar'
16
16
  )
17
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_ansible
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Lobato Garcia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-25 00:00:00.000000000 Z
11
+ date: 2019-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -129,6 +129,7 @@ files:
129
129
  - app/controllers/foreman_ansible/api/v2/hostgroups_param_group_extensions.rb
130
130
  - app/controllers/foreman_ansible/api/v2/hosts_controller_extensions.rb
131
131
  - app/controllers/foreman_ansible/api/v2/hosts_param_group_extensions.rb
132
+ - app/controllers/foreman_ansible/concerns/api_common.rb
132
133
  - app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb
133
134
  - app/controllers/foreman_ansible/concerns/hosts_controller_extensions.rb
134
135
  - app/controllers/foreman_ansible/concerns/import_controller_helper.rb
@@ -150,10 +151,10 @@ files:
150
151
  - app/models/hostgroup_ansible_role.rb
151
152
  - app/models/setting/ansible.rb
152
153
  - app/overrides/ansible_roles_tab.rb
153
- - app/overrides/ansible_variables_edit.rb
154
154
  - app/overrides/hostgroup_ansible_roles_tab.rb
155
155
  - app/overrides/hostgroup_play_roles.rb
156
156
  - app/overrides/report_output.rb
157
+ - app/services/foreman_ansible/ansible_info.rb
157
158
  - app/services/foreman_ansible/ansible_report_importer.rb
158
159
  - app/services/foreman_ansible/ansible_report_scanner.rb
159
160
  - app/services/foreman_ansible/api_roles_importer.rb
@@ -174,8 +175,7 @@ files:
174
175
  - app/views/ansible_roles/import.html.erb
175
176
  - app/views/ansible_roles/index.html.erb
176
177
  - app/views/ansible_roles/welcome.html.erb
177
- - app/views/ansible_variables/_ansible_roles_list.html.erb
178
- - app/views/ansible_variables/_validator_text.html.erb
178
+ - app/views/ansible_variables/_fields.erb
179
179
  - app/views/ansible_variables/edit.html.erb
180
180
  - app/views/ansible_variables/import.html.erb
181
181
  - app/views/ansible_variables/index.html.erb
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- Deface::Override.new(
4
- :virtual_path => 'lookup_keys/_fields',
5
- :name => 'ansible_variables_edit',
6
- :replace => "erb[loud]:contains('show_puppet_class')",
7
- :partial => 'ansible_variables/ansible_roles_list'
8
- )
9
-
10
- Deface::Override.new(
11
- :virtual_path => 'lookup_keys/_fields',
12
- :name => 'ansible_variables_validator_text',
13
- :replace => '.out.collapse > h6',
14
- :partial => 'ansible_variables/validator_text'
15
- )
@@ -1,15 +0,0 @@
1
- <% if f.object.is_a? ::AnsibleVariable %>
2
- <%=
3
- select_f(
4
- f,
5
- :ansible_role_id,
6
- [f.object.ansible_role],
7
- :id,
8
- :to_label,
9
- {},
10
- { :label => _("Ansible Role"), :disabled => true }
11
- )
12
- %>
13
- <% else %>
14
- <%= show_puppet_class(f) %>
15
- <% end %>
@@ -1,5 +0,0 @@
1
- <% if f.object.is_a? ::AnsibleVariable %>
2
- <h6><%= _('Before including these variables on your playbooks, Foreman will validate that your variables comply with the validation.') %></h6>
3
- <% else %>
4
- <h6><%= _('If ERB is used in a parameter value, the validation of the value will happen during the ENC request. If the value is invalid, the ENC request will fail.') %></h6>
5
- <% end %>