foreman_ansible 4.0.3.5 → 4.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (25) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/api/v2/ansible_roles_controller.rb +2 -2
  3. data/app/controllers/api/v2/ansible_variables_controller.rb +1 -2
  4. data/app/controllers/foreman_ansible/api/v2/hostgroups_controller_extensions.rb +2 -2
  5. data/app/controllers/foreman_ansible/api/v2/hosts_controller_extensions.rb +2 -2
  6. data/app/models/concerns/foreman_ansible/host_managed_extensions.rb +0 -4
  7. data/app/models/setting/ansible.rb +0 -4
  8. data/app/services/foreman_ansible/insights_notification_builder.rb +0 -2
  9. data/app/services/foreman_ansible/operating_system_parser.rb +0 -4
  10. data/app/services/foreman_ansible/variables_importer.rb +1 -0
  11. data/app/views/foreman_ansible/job_templates/ansible_roles_-_ansible_default.erb +4 -7
  12. data/config/routes.rb +0 -2
  13. data/db/migrate/20160802153302_create_join_table_hostgroup_ansible_roles.rb +0 -2
  14. data/lib/foreman_ansible/engine.rb +0 -2
  15. data/lib/foreman_ansible/register.rb +0 -2
  16. data/lib/foreman_ansible/version.rb +1 -1
  17. data/test/functional/api/v2/ansible_inventories_controller_test.rb +3 -3
  18. data/test/functional/api/v2/ansible_variables_controller_test.rb +12 -0
  19. data/test/unit/services/inventory_creator_test.rb +0 -2
  20. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.js +1 -0
  21. data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.js +5 -1
  22. data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.test.js +8 -1
  23. data/webpack/components/AnsibleRolesSwitcher/index.js +1 -4
  24. metadata +2 -23
  25. data/app/views/foreman_ansible/job_templates/configure_cloud_connector_-_ansible_default.erb +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f5cb37ac21d410601d1f871a73f125511574ae218f6a488c865c45e64761c88
4
- data.tar.gz: 4bbb6f29895b798715e7d5915d2370e56feefc3ba0ad67365bb03af40ca2dc93
3
+ metadata.gz: 1181793843192c0b3ef0d48427a3e948a570dc707e7232271fb62e21e7dcce81
4
+ data.tar.gz: 63406a1b2450e56ede90163216eec5faffe06018ced278c489b99409822c443c
5
5
  SHA512:
6
- metadata.gz: ea3fd4b934442a52ae46cf71ec2931f67159da7df6906ffc99a7c4616e074d25ab3349021deddeef60258f781969979743ea1aa6eb97e0d575b1a9d912e41663
7
- data.tar.gz: 39861b01ad80bac36159c3b6b3b243084f71f4567caa18dc35e9e02e87d92ca53ec27ec31ec467900c8b1aca7979ac0623314c90604bcae370caf3be92148eb6
6
+ metadata.gz: 6b582b46130075e8f0ab202f7c80c6a8fccba95cebc8a94fb377e35a50c880d20f5e5bf4a5baf77779bc94b9e8d219de5da5f6184ba1afce56a2c5ce0d95d73d
7
+ data.tar.gz: b6fa2dce6812d569bbec5f60737269ddab3307b7a4f4b0f3bc0013351784a3a5fa2fe1032f40d25f333916ce13fedfa04e94e0af24061c4b3fd1c96180de9ee6
@@ -67,7 +67,7 @@ module Api
67
67
  params.fetch(:role_names, [])
68
68
  end
69
69
 
70
- # rubocop:disable DotPosition
70
+ # rubocop:disable Layout/DotPosition
71
71
  def find_proxy
72
72
  unless params[:proxy_id]
73
73
  msg = _('Smart proxy id is required')
@@ -76,7 +76,7 @@ module Api
76
76
  @proxy = SmartProxy.authorized(:view_smart_proxies)
77
77
  .find(params[:proxy_id])
78
78
  end
79
- # rubocop:enable DotPosition
79
+ # rubocop:enable Layout/DotPosition
80
80
 
81
81
  def create_importer
82
82
  @importer = ForemanAnsible::ApiRolesImporter.new(@proxy)
@@ -5,7 +5,6 @@ module Api
5
5
  # API controller for Ansible Variables
6
6
  class AnsibleVariablesController < ::Api::V2::BaseController
7
7
  include ::Api::Version2
8
- include Foreman::Controller::Parameters::VariableLookupKey
9
8
  include Foreman::Controller::Parameters::AnsibleVariable
10
9
 
11
10
  resource_description do
@@ -65,7 +64,7 @@ module Api
65
64
  param_group :ansible_variable, :as => :update
66
65
 
67
66
  def update
68
- @ansible_variable.update!(variable_lookup_key_params)
67
+ @ansible_variable.update!(ansible_variable_params)
69
68
  render 'api/v2/ansible_variables/show'
70
69
  end
71
70
 
@@ -12,7 +12,7 @@ module ForemanAnsible
12
12
 
13
13
  # Included blocks shouldn't be bound by length, as otherwise concerns
14
14
  # cannot extend the method properly.
15
- # rubocop:disable BlockLength, Rails/LexicallyScopedActionFilter
15
+ # rubocop:disable Rails/LexicallyScopedActionFilter
16
16
  included do
17
17
  before_action :find_ansible_roles, :only => [:assign_ansible_roles]
18
18
 
@@ -61,7 +61,7 @@ module ForemanAnsible
61
61
  process_response @hostgroup.update(:ansible_roles => @ansible_roles)
62
62
  end
63
63
  end
64
- # rubocop:enable BlockLength, Rails/LexicallyScopedActionFilter
64
+ # rubocop:enable Rails/LexicallyScopedActionFilter
65
65
 
66
66
  private
67
67
 
@@ -12,7 +12,7 @@ module ForemanAnsible
12
12
 
13
13
  # Included blocks shouldn't be bound by length, as otherwise concerns
14
14
  # cannot extend the method properly.
15
- # rubocop:disable BlockLength, Rails/LexicallyScopedActionFilter
15
+ # rubocop:disable Rails/LexicallyScopedActionFilter
16
16
  included do
17
17
  before_action :find_ansible_roles, :only => [:assign_ansible_roles]
18
18
 
@@ -63,7 +63,7 @@ module ForemanAnsible
63
63
  process_response @host.update(:ansible_roles => @ansible_roles)
64
64
  end
65
65
  end
66
- # rubocop:enable BlockLength, Rails/LexicallyScopedActionFilter
66
+ # rubocop:enable Rails/LexicallyScopedActionFilter
67
67
 
68
68
  private
69
69
 
@@ -4,7 +4,6 @@ require 'ipaddress'
4
4
  module ForemanAnsible
5
5
  # Relations to make Host::Managed 'have' ansible roles
6
6
  module HostManagedExtensions
7
- # rubocop:disable Metrics/BlockLength
8
7
  def self.prepended(base)
9
8
  base.instance_eval do
10
9
  include ::ForemanAnsible::Concerns::JobInvocationHelper
@@ -30,7 +29,6 @@ module ForemanAnsible
30
29
 
31
30
  # This one should be fixed, disabled for the moment as we're
32
31
  # in a rush to get the release out
33
- # rubocop:disable Metrics/AbcSize
34
32
  def play_ansible_roles
35
33
  return true unless ansible_roles.present? ||
36
34
  inherited_ansible_roles.present?
@@ -47,13 +45,11 @@ module ForemanAnsible
47
45
  logger.info("Error running Ansible roles on #{self} before_provision: "\
48
46
  "#{e.message}")
49
47
  end
50
- # rubocop:enable Metrics/AbcSize
51
48
 
52
49
  def all_ansible_roles
53
50
  (ansible_roles + inherited_ansible_roles).uniq
54
51
  end
55
52
 
56
- # rubocop:enable Metrics/BlockLength
57
53
  # Class methods we may need to override or add
58
54
  module ClassMethods
59
55
  def import_host(*args)
@@ -7,8 +7,6 @@ class Setting
7
7
  # It would be more disadvantages than advantages to split up
8
8
  # default_settings into multiple methods, this way it's already very
9
9
  # manageable.
10
- # rubocop:disable AbcSize
11
- # rubocop:disable MethodLength
12
10
  def default_settings
13
11
  [
14
12
  set(
@@ -85,8 +83,6 @@ class Setting
85
83
  )
86
84
  ]
87
85
  end
88
- # rubocop:enable AbcSize
89
- # rubocop:enable MethodLength
90
86
 
91
87
  def load_defaults
92
88
  Setting::BLANK_ATTRS.push('ansible_ssh_private_key_file')
@@ -3,9 +3,7 @@
3
3
  module ForemanAnsible
4
4
  # A class that builds custom notificaton for REX job if it's insights
5
5
  # remediation feature
6
- # rubocop:disable LineLength
7
6
  class InsightsNotificationBuilder < ::UINotifications::RemoteExecutionJobs::BaseJobFinish
8
- # rubocop:enable LineLength
9
7
  def deliver!
10
8
  ::Notification.create!(
11
9
  :audience => Notification::AUDIENCE_USER,
@@ -45,7 +45,6 @@ module ForemanAnsible
45
45
  facts[:ansible_distribution_release]
46
46
  end
47
47
 
48
- # rubocop:disable AbcSize, CyclomaticComplexity, PerceivedComplexity
49
48
  def os_major
50
49
  if os_name == 'Debian' &&
51
50
  facts[:ansible_distribution_major_version][%r{\/sid}i]
@@ -56,14 +55,12 @@ module ForemanAnsible
56
55
  (facts[:version].split('R')[0] if os_name == 'junos')
57
56
  end
58
57
  end
59
- # rubocop:enable AbcSize, CyclomaticComplexity, PerceivedComplexity
60
58
 
61
59
  def os_release
62
60
  facts[:ansible_distribution_version] ||
63
61
  facts[:ansible_lsb] && facts[:ansible_lsb]['release']
64
62
  end
65
63
 
66
- # rubocop:disable AbcSize
67
64
  def os_minor
68
65
  _, minor = (os_release&.split('.', 2)) ||
69
66
  (facts[:version].split('R') if os_name == 'junos')
@@ -87,7 +84,6 @@ module ForemanAnsible
87
84
  facts[:ansible_lsb] && facts[:ansible_lsb]['id']
88
85
  end
89
86
  end
90
- # rubocop:enable AbcSize
91
87
 
92
88
  def os_description
93
89
  if facts[:ansible_os_family] == 'Windows'
@@ -29,6 +29,7 @@ module ForemanAnsible
29
29
  def import_variables(role_variables, new_roles)
30
30
  detect_changes(
31
31
  role_variables.map do |role_name, variables|
32
+ next if variables.blank?
32
33
  role = import_new_role(role_name, new_roles)
33
34
  next if role.blank?
34
35
  initialize_variables(variables, role)
@@ -15,10 +15,7 @@ model: JobTemplate
15
15
  - name: Display all parameters known for the Foreman host
16
16
  debug:
17
17
  var: foreman
18
- tasks:
19
- - name: Apply roles
20
- include_role:
21
- name: "{{ role }}"
22
- loop: "{{ foreman_ansible_roles }}"
23
- loop_control:
24
- loop_var: role
18
+ roles:
19
+ <%- if @host.all_ansible_roles.present? -%>
20
+ <%= @host.all_ansible_roles.map { |role| " - #{role.name.strip}" }.join("\n") %>
21
+ <%- end -%>
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable BlockLength
4
3
  Rails.application.routes.draw do
5
4
  namespace :api do
6
5
  scope '(:apiv)',
@@ -104,4 +103,3 @@ Rails.application.routes.draw do
104
103
  end
105
104
  end
106
105
  end
107
- # rubocop:enable BlockLength
@@ -1,13 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Defines the relation between Hostgroup and AnsibleRole
4
- # rubocop:disable Metrics/LineLength
5
4
  class CreateJoinTableHostgroupAnsibleRoles < ActiveRecord::Migration[4.2]
6
5
  def change
7
6
  create_join_table :hostgroup, :ansible_roles, :table_name => 'hostgroup_ansible_roles' do |t|
8
7
  t.index [:hostgroup_id, :ansible_role_id], :name => 'index_ansible_roles_hostgroup_on_hostgroup_id_and_role_id'
9
8
  t.index [:ansible_role_id, :hostgroup_id], :name => 'index_ansible_roles_hostgroup_on_role_id_and_hostgroup_id'
10
- # rubocop:enable Metrics/LineLength
11
9
  end
12
10
  end
13
11
  end
@@ -70,7 +70,6 @@ module ForemanAnsible
70
70
  Apipie.configuration.checksum_path += ['/foreman_ansible/api/']
71
71
  end
72
72
 
73
- # rubocop:disable BlockLength
74
73
  config.to_prepare do
75
74
  begin
76
75
  foreman_version = ::Foreman::Version.new
@@ -99,7 +98,6 @@ module ForemanAnsible
99
98
  Rails.logger.warn "Foreman Ansible: skipping engine hook (#{e})"
100
99
  end
101
100
  end
102
- # rubocop:enable BlockLength
103
101
 
104
102
  rake_tasks do
105
103
  Rake::Task['db:seed'].enhance do
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable BlockLength
4
3
  Foreman::Plugin.register :foreman_ansible do
5
4
  requires_foreman '>= 1.24'
6
5
 
@@ -119,4 +118,3 @@ Foreman::Plugin.register :foreman_ansible do
119
118
  register_report_origin 'Ansible', 'ConfigReport'
120
119
  end
121
120
  end
122
- # rubocop:enable BlockLength
@@ -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 = '4.0.3.5'
7
+ VERSION = '4.0.4'
8
8
  end
@@ -34,10 +34,10 @@ module Api
34
34
 
35
35
  test 'schedule inventory by user' do
36
36
  report = FactoryBot.create(:report_template)
37
- setting = Setting::Ansible.create! :name => 'ansible_inventory_template', :value => report.name,
38
- :default => report.name, :description => 'inventory'
37
+ Setting::Ansible.create! :name => 'ansible_inventory_template', :value => report.name,
38
+ :default => report.name, :description => 'inventory'
39
39
  user = FactoryBot.create(:user)
40
- user.roles << Role.find_by_name('Ansible Tower Inventory Reader')
40
+ user.roles << Role.find_by(:name => 'Ansible Tower Inventory Reader')
41
41
  post :schedule, { :session => set_session_user(user) }
42
42
  assert_response :success
43
43
  end
@@ -46,6 +46,18 @@ module Api
46
46
  res = JSON.parse(@response.body)
47
47
  refute res['imported']
48
48
  end
49
+
50
+ test 'should update' do
51
+ variable = FactoryBot.create(:ansible_variable, :default_value => 'my default value')
52
+ new_value = 'changed default value'
53
+ post :update,
54
+ :params => { :id => variable.id, :default_value => new_value },
55
+ :session => set_session_user
56
+
57
+ assert_response :success
58
+ res = JSON.parse(@response.body)
59
+ assert_equal new_value, res['default_value']
60
+ end
49
61
  end
50
62
  end
51
63
  end
@@ -5,7 +5,6 @@ require 'test_plugin_helper'
5
5
  module ForemanAnsible
6
6
  # Test how the inventory creator service transforms host params into
7
7
  # inventory variables and connection options
8
- # rubocop:disable ClassLength
9
8
  class InventoryCreatorTest < ActiveSupport::TestCase
10
9
  setup do
11
10
  @host = FactoryBot.build(:host)
@@ -204,5 +203,4 @@ module ForemanAnsible
204
203
  assert_equal org.name, inventory['_meta']['hostvars'][host.name]['foreman']['organization']
205
204
  end
206
205
  end
207
- # rubocop:enable ClassLength
208
206
  end
@@ -89,6 +89,7 @@ class AnsibleRolesSwitcher extends React.Component {
89
89
  </div>
90
90
  <AssignedRolesList
91
91
  assignedRoles={assignedRoles}
92
+ allAssignedRoles={allAssignedRoles}
92
93
  pagination={assignedPagination}
93
94
  itemCount={assignedRolesCount}
94
95
  onPaginationChange={changeAssignedPage}
@@ -8,13 +8,16 @@ import AnsibleRole from './AnsibleRole';
8
8
 
9
9
  const AssignedRolesList = ({
10
10
  assignedRoles,
11
+ allAssignedRoles,
11
12
  pagination,
12
13
  itemCount,
13
14
  onPaginationChange,
14
15
  onRemoveRole,
15
16
  resourceName,
16
17
  }) => {
17
- const directlyAssignedRoles = assignedRoles.filter(role => !role.inherited);
18
+ const directlyAssignedRoles = allAssignedRoles.filter(
19
+ role => !role.inherited
20
+ );
18
21
 
19
22
  return (
20
23
  <div>
@@ -62,6 +65,7 @@ const AssignedRolesList = ({
62
65
 
63
66
  AssignedRolesList.propTypes = {
64
67
  assignedRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
68
+ allAssignedRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
65
69
  pagination: PropTypes.shape({
66
70
  page: PropTypes.number,
67
71
  perPage: PropTypes.number,
@@ -6,7 +6,14 @@ const noop = () => {};
6
6
 
7
7
  const fixtures = {
8
8
  'should render': {
9
- assignedRoles: [{ id: 1, name: 'fake.role' }, { id: 2, name: 'test.role' }],
9
+ allAssignedRoles: [
10
+ { id: 1, name: 'fake.role' },
11
+ { id: 2, name: 'test.role' },
12
+ ],
13
+ assignedRoles: [
14
+ { id: 1, name: 'fake.role' },
15
+ { id: 2, name: 'test.role' },
16
+ ],
10
17
  pagination: { page: 1, perPage: 25 },
11
18
  itemCount: 2,
12
19
  onPaginationChange: noop,
@@ -35,10 +35,7 @@ const mapDispatchToProps = dispatch =>
35
35
  bindActionCreators(AnsibleRolesSwitcherActions, dispatch);
36
36
 
37
37
  export default withProtectedView(
38
- connect(
39
- mapStateToProps,
40
- mapDispatchToProps
41
- )(AnsibleRolesSwitcher),
38
+ connect(mapStateToProps, mapDispatchToProps)(AnsibleRolesSwitcher),
42
39
  AnsiblePermissionDenied,
43
40
  props => props.data && props.data.canView
44
41
  );
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: 4.0.3.5
4
+ version: 4.0.4
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: 2020-04-03 00:00:00.000000000 Z
11
+ date: 2020-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "<"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.0'
55
- - !ruby/object:Gem::Dependency
56
- name: foreman-tasks
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '0.8'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '0.8'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: foreman_remote_execution
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -73,9 +59,6 @@ dependencies:
73
59
  - - ">="
74
60
  - !ruby/object:Gem::Version
75
61
  version: 2.0.0
76
- - - "<"
77
- - !ruby/object:Gem::Version
78
- version: '3.0'
79
62
  type: :runtime
80
63
  prerelease: false
81
64
  version_requirements: !ruby/object:Gem::Requirement
@@ -83,9 +66,6 @@ dependencies:
83
66
  - - ">="
84
67
  - !ruby/object:Gem::Version
85
68
  version: 2.0.0
86
- - - "<"
87
- - !ruby/object:Gem::Version
88
- version: '3.0'
89
69
  - !ruby/object:Gem::Dependency
90
70
  name: ipaddress
91
71
  requirement: !ruby/object:Gem::Requirement
@@ -206,7 +186,6 @@ files:
206
186
  - app/views/foreman_ansible/job_templates/ansible_roles_-_ansible_default.erb
207
187
  - app/views/foreman_ansible/job_templates/ansible_roles_-_install_from_galaxy.erb
208
188
  - app/views/foreman_ansible/job_templates/ansible_roles_-_install_from_git.erb
209
- - app/views/foreman_ansible/job_templates/configure_cloud_connector_-_ansible_default.erb
210
189
  - app/views/foreman_ansible/job_templates/maintenance_plan.erb
211
190
  - app/views/foreman_ansible/job_templates/module_action_-_ansible_default.erb
212
191
  - app/views/foreman_ansible/job_templates/package_action_-_ansible_default.erb
@@ -1,29 +0,0 @@
1
- <%#
2
- name: Configure Cloud Connector
3
- snippet: false
4
- template_inputs:
5
- - name: satellite_user
6
- required: true
7
- input_type: user
8
- advanced: false
9
- value_type: plain
10
- hidden_value: false
11
- - name: satellite_password
12
- required: true
13
- input_type: user
14
- advanced: false
15
- value_type: plain
16
- hidden_value: true
17
- model: JobTemplate
18
- job_category: Ansible Playbook
19
- description_format: "%{template_name}"
20
- provider_type: Ansible
21
- kind: job_template
22
- %>
23
-
24
- ---
25
- - hosts: all
26
- vars:
27
- satellite_url: "<%= foreman_server_url %>"
28
- roles:
29
- - project-receptor.satellite_receptor_installer