foreman_ansible 11.2.0 → 12.0.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/app/controllers/foreman_ansible/api/v2/hostgroups_controller_extensions.rb +27 -0
- data/app/controllers/foreman_ansible/api/v2/hosts_controller_extensions.rb +28 -0
- data/app/controllers/foreman_ansible/concerns/api_common.rb +20 -0
- data/config/routes.rb +4 -0
- data/lib/foreman_ansible/engine.rb +0 -8
- data/lib/foreman_ansible/register.rb +4 -3
- data/lib/foreman_ansible/version.rb +1 -1
- data/test/functional/api/v2/hostgroups_controller_test.rb +26 -0
- data/test/functional/api/v2/hosts_controller_test.rb +29 -0
- metadata +12 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9998a5428db095cc8f666b6676cf81f44bb1cb1f474c7d4dbcf566d659d6b855
|
4
|
+
data.tar.gz: e74626fb664cc93264f2723c3d888378f1ecb03e7efd85f0e5c9de2262a1578b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56a7e18a191e10a9b038a4a3d9dcd7938768fd92917ef34751c9a3c81bfe31ca26e018597e3ca0b2b16eb41ee28a0dbb0f7ca0b206f071d27cba19ca897c5b7e
|
7
|
+
data.tar.gz: 3449228e4b4f6c7b475b407f4b0a4521296ad21780a5eed62d709172ed1f49beaf3b85ea516db5a36cfa9190a9bfd0ed19fe350b0fff2d6626538489806e27ca
|
@@ -15,6 +15,7 @@ module ForemanAnsible
|
|
15
15
|
# rubocop:disable Rails/LexicallyScopedActionFilter
|
16
16
|
included do
|
17
17
|
before_action :find_ansible_roles, :only => [:assign_ansible_roles]
|
18
|
+
before_action :find_hostgroup_ansible_role, :only => [:add_ansible_role, :remove_ansible_role]
|
18
19
|
|
19
20
|
api :POST, '/hostgroups/:id/play_roles',
|
20
21
|
N_('Runs all Ansible roles on a hostgroup')
|
@@ -64,6 +65,30 @@ module ForemanAnsible
|
|
64
65
|
find_resource
|
65
66
|
process_response @hostgroup.update(:ansible_roles => @ansible_roles)
|
66
67
|
end
|
68
|
+
|
69
|
+
api :PUT, '/hostgroups/:id/ansible_roles',
|
70
|
+
N_('Directly add an Ansible role to a hostgroup')
|
71
|
+
param :id, :identifier, :required => true
|
72
|
+
param :ansible_role_id, :identifier,
|
73
|
+
N_('Ansible role to add to a hostgroup'),
|
74
|
+
:required => true
|
75
|
+
|
76
|
+
def add_ansible_role
|
77
|
+
process_response @hostgroup.ansible_roles << @ansible_role
|
78
|
+
rescue ActiveRecord::RecordInvalid => e
|
79
|
+
render_exception(e, :status => :unprocessable_entity)
|
80
|
+
end
|
81
|
+
|
82
|
+
api :DELETE, '/hostgroups/:id/ansible_roles/:ansible_role_id',
|
83
|
+
N_('Remove directly assigned Ansible role from a hostgroup')
|
84
|
+
param :id, :identifier, :required => true
|
85
|
+
param :ansible_role_id, :identifier,
|
86
|
+
N_('Ansible role to remove from a hostgroup'),
|
87
|
+
:required => true
|
88
|
+
|
89
|
+
def remove_ansible_role
|
90
|
+
process_response @hostgroup.ansible_roles.delete(@ansible_role)
|
91
|
+
end
|
67
92
|
end
|
68
93
|
# rubocop:enable Rails/LexicallyScopedActionFilter
|
69
94
|
|
@@ -87,6 +112,8 @@ module ForemanAnsible
|
|
87
112
|
when 'play_roles', 'multiple_play_roles', 'ansible_roles',
|
88
113
|
'assign_ansible_roles'
|
89
114
|
:view
|
115
|
+
when 'add_ansible_role', 'remove_ansible_role'
|
116
|
+
:edit
|
90
117
|
else
|
91
118
|
super
|
92
119
|
end
|
@@ -14,7 +14,9 @@ module ForemanAnsible
|
|
14
14
|
# cannot extend the method properly.
|
15
15
|
# rubocop:disable Rails/LexicallyScopedActionFilter
|
16
16
|
included do
|
17
|
+
skip_before_action :find_resource, :only => [:add_ansible_role, :remove_ansible_role]
|
17
18
|
before_action :find_ansible_roles, :only => [:assign_ansible_roles]
|
19
|
+
before_action :find_host_ansible_role, :only => [:add_ansible_role, :remove_ansible_role]
|
18
20
|
|
19
21
|
def find_resource
|
20
22
|
return true if params[:action] == 'multiple_play_roles'
|
@@ -64,6 +66,30 @@ module ForemanAnsible
|
|
64
66
|
def assign_ansible_roles
|
65
67
|
process_response @host.update(:ansible_roles => @ansible_roles)
|
66
68
|
end
|
69
|
+
|
70
|
+
api :PUT, '/hosts/:id/ansible_roles',
|
71
|
+
N_('Directly add an Ansible role to a host')
|
72
|
+
param :id, :identifier, :required => true
|
73
|
+
param :ansible_role_id, :identifier,
|
74
|
+
N_('Ansible role to add to a host'),
|
75
|
+
:required => true
|
76
|
+
|
77
|
+
def add_ansible_role
|
78
|
+
process_response @host.ansible_roles << @ansible_role
|
79
|
+
rescue ActiveRecord::RecordInvalid => e
|
80
|
+
render_exception(e, :status => :unprocessable_entity)
|
81
|
+
end
|
82
|
+
|
83
|
+
api :DELETE, '/hosts/:id/ansible_roles/:ansible_role_id',
|
84
|
+
N_('Remove directly assigned Ansible role from a host')
|
85
|
+
param :id, :identifier, :required => true
|
86
|
+
param :ansible_role_id, :identifier,
|
87
|
+
N_('Ansible role to remove from a host'),
|
88
|
+
:required => true
|
89
|
+
|
90
|
+
def remove_ansible_role
|
91
|
+
process_response @host.ansible_roles.delete(@ansible_role)
|
92
|
+
end
|
67
93
|
end
|
68
94
|
# rubocop:enable Rails/LexicallyScopedActionFilter
|
69
95
|
|
@@ -74,6 +100,8 @@ module ForemanAnsible
|
|
74
100
|
when 'play_roles', 'multiple_play_roles', 'ansible_roles',
|
75
101
|
'assign_ansible_roles'
|
76
102
|
:view
|
103
|
+
when 'add_ansible_role', 'remove_ansible_role'
|
104
|
+
:edit
|
77
105
|
else
|
78
106
|
super
|
79
107
|
end
|
@@ -12,6 +12,26 @@ module ForemanAnsible
|
|
12
12
|
rescue ActiveRecord::RecordNotFound => e
|
13
13
|
not_found(e.message)
|
14
14
|
end
|
15
|
+
|
16
|
+
def find_ansible_role
|
17
|
+
@ansible_role = AnsibleRole.authorized(:view_ansible_roles).find(params[:ansible_role_id])
|
18
|
+
rescue ActiveRecord::RecordNotFound => e
|
19
|
+
not_found(e.message)
|
20
|
+
end
|
21
|
+
|
22
|
+
def find_host_ansible_role
|
23
|
+
find_ansible_role
|
24
|
+
@host = Host.authorized(:view_hosts).find(params[:id])
|
25
|
+
rescue ActiveRecord::RecordNotFound => e
|
26
|
+
not_found(e.message)
|
27
|
+
end
|
28
|
+
|
29
|
+
def find_hostgroup_ansible_role
|
30
|
+
find_ansible_role
|
31
|
+
@hostgroup = Hostgroup.authorized(:view_hostgroups).find(params[:id])
|
32
|
+
rescue ActiveRecord::RecordNotFound => e
|
33
|
+
not_found(e.message)
|
34
|
+
end
|
15
35
|
end
|
16
36
|
end
|
17
37
|
end
|
data/config/routes.rb
CHANGED
@@ -13,6 +13,8 @@ Rails.application.routes.draw do
|
|
13
13
|
post :play_roles
|
14
14
|
get :ansible_roles
|
15
15
|
post :assign_ansible_roles
|
16
|
+
put :ansible_roles, :to => 'hosts#add_ansible_role'
|
17
|
+
delete 'ansible_roles/:ansible_role_id', :to => 'hosts#remove_ansible_role', :constraints => { id: %r{[^\/]+} }
|
16
18
|
end
|
17
19
|
collection do
|
18
20
|
post :multiple_play_roles
|
@@ -23,6 +25,8 @@ Rails.application.routes.draw do
|
|
23
25
|
post :play_roles
|
24
26
|
get :ansible_roles
|
25
27
|
post :assign_ansible_roles
|
28
|
+
put :ansible_roles, :to => 'hostgroups#add_ansible_role'
|
29
|
+
delete 'ansible_roles/:ansible_role_id', :to => 'hostgroups#remove_ansible_role', :constraints => { id: %r{[^\/]+} }
|
26
30
|
end
|
27
31
|
collection do
|
28
32
|
post :multiple_play_roles
|
@@ -19,14 +19,6 @@ module ForemanAnsible
|
|
19
19
|
config.autoload_paths += Dir["#{config.root}/app/views"]
|
20
20
|
config.autoload_paths += Dir["#{config.root}/app/lib"]
|
21
21
|
|
22
|
-
initializer 'foreman_ansible.register_gettext',
|
23
|
-
:after => :load_config_initializers do
|
24
|
-
locale_dir = File.join(File.expand_path('../..', __dir__), 'locale')
|
25
|
-
locale_domain = 'foreman_ansible'
|
26
|
-
|
27
|
-
Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
|
28
|
-
end
|
29
|
-
|
30
22
|
initializer 'foreman_ansible.register_plugin', :before => :finisher_hook do
|
31
23
|
require 'foreman_ansible/register'
|
32
24
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Foreman::Plugin.register :foreman_ansible do
|
4
|
-
requires_foreman '>= 3.
|
4
|
+
requires_foreman '>= 3.7'
|
5
|
+
register_gettext
|
5
6
|
|
6
7
|
settings do
|
7
8
|
category :ansible, N_('Ansible') do
|
@@ -151,10 +152,10 @@ Foreman::Plugin.register :foreman_ansible do
|
|
151
152
|
:'api/v2/ansible_inventories' => [:hostgroups] },
|
152
153
|
:resource_type => 'Hostgroup'
|
153
154
|
permission :edit_hosts,
|
154
|
-
{ :'api/v2/hosts' => [:assign_ansible_roles] },
|
155
|
+
{ :'api/v2/hosts' => [:assign_ansible_roles, :add_ansible_role, :remove_ansible_role] },
|
155
156
|
:resource_type => 'Host'
|
156
157
|
permission :edit_hostgroups,
|
157
|
-
{ :'api/v2/hostgroups' => [:assign_ansible_roles] },
|
158
|
+
{ :'api/v2/hostgroups' => [:assign_ansible_roles, :add_ansible_role, :remove_ansible_role] },
|
158
159
|
:resource_type => 'Hostgroup'
|
159
160
|
permission :generate_ansible_inventory,
|
160
161
|
{ :'api/v2/ansible_inventories' => [:schedule] }
|
@@ -63,6 +63,32 @@ module Api
|
|
63
63
|
assert_response :success
|
64
64
|
assert_equal assigns('hostgroup').ansible_roles, [@ansible_role2, @ansible_role1]
|
65
65
|
end
|
66
|
+
|
67
|
+
test 'should append a role to a hostgroup with a correct ordering' do
|
68
|
+
hostgroup = FactoryBot.create(:hostgroup,
|
69
|
+
:ansible_role_ids => [@ansible_role1.id])
|
70
|
+
post :add_ansible_role,
|
71
|
+
:params => {
|
72
|
+
:id => hostgroup.id,
|
73
|
+
:ansible_role_id => [@ansible_role2.id]
|
74
|
+
},
|
75
|
+
:session => set_session_user
|
76
|
+
assert_response 201
|
77
|
+
assert_equal assigns('hostgroup').ansible_roles, [@ansible_role1, @ansible_role2]
|
78
|
+
end
|
79
|
+
|
80
|
+
test 'should remove only specified roles from a hostgroup' do
|
81
|
+
hostgroup = FactoryBot.create(:hostgroup,
|
82
|
+
:ansible_role_ids => [@ansible_role2.id, @ansible_role1.id])
|
83
|
+
delete :remove_ansible_role,
|
84
|
+
:params => {
|
85
|
+
:id => hostgroup.id,
|
86
|
+
:ansible_role_id => [@ansible_role2.id]
|
87
|
+
},
|
88
|
+
:session => set_session_user
|
89
|
+
assert_response :success
|
90
|
+
assert_equal assigns('hostgroup').ansible_roles, [@ansible_role1]
|
91
|
+
end
|
66
92
|
end
|
67
93
|
end
|
68
94
|
end
|
@@ -9,6 +9,7 @@ module Api
|
|
9
9
|
setup do
|
10
10
|
@ansible_role1 = FactoryBot.create(:ansible_role)
|
11
11
|
@ansible_role2 = FactoryBot.create(:ansible_role)
|
12
|
+
@ansible_role3 = FactoryBot.create(:ansible_role)
|
12
13
|
@host1 = FactoryBot.create(:host)
|
13
14
|
@host2 = FactoryBot.create(:host)
|
14
15
|
@host3 = FactoryBot.create(:host)
|
@@ -87,6 +88,34 @@ module Api
|
|
87
88
|
assert_response :success
|
88
89
|
assert_equal assigns('host').ansible_roles, [@ansible_role2, @ansible_role1]
|
89
90
|
end
|
91
|
+
|
92
|
+
test 'should append a role to a host with a correct ordering' do
|
93
|
+
host = FactoryBot.create(:host,
|
94
|
+
:managed => false,
|
95
|
+
:ansible_role_ids => [@ansible_role3.id])
|
96
|
+
post :add_ansible_role,
|
97
|
+
:params => {
|
98
|
+
:id => host.id,
|
99
|
+
:ansible_role_id => @ansible_role2.id
|
100
|
+
},
|
101
|
+
:session => set_session_user
|
102
|
+
assert_response 201
|
103
|
+
assert_equal assigns('host').ansible_roles, [@ansible_role3, @ansible_role2]
|
104
|
+
end
|
105
|
+
|
106
|
+
test 'should remove only specified roles from a host' do
|
107
|
+
host = FactoryBot.create(:host,
|
108
|
+
:managed => false,
|
109
|
+
:ansible_role_ids => [@ansible_role3.id, @ansible_role2.id, @ansible_role1.id])
|
110
|
+
delete :remove_ansible_role,
|
111
|
+
:params => {
|
112
|
+
:id => host.id,
|
113
|
+
:ansible_role_id => [@ansible_role2.id]
|
114
|
+
},
|
115
|
+
:session => set_session_user
|
116
|
+
assert_response :success
|
117
|
+
assert_equal assigns('host').ansible_roles, [@ansible_role3, @ansible_role1]
|
118
|
+
end
|
90
119
|
end
|
91
120
|
end
|
92
121
|
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:
|
4
|
+
version: 12.0.0
|
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: 2023-
|
11
|
+
date: 2023-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: acts_as_list
|
@@ -56,16 +56,22 @@ dependencies:
|
|
56
56
|
name: foreman-tasks
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '7.0'
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '9'
|
62
65
|
type: :runtime
|
63
66
|
prerelease: false
|
64
67
|
version_requirements: !ruby/object:Gem::Requirement
|
65
68
|
requirements:
|
66
|
-
- - "
|
69
|
+
- - ">="
|
67
70
|
- !ruby/object:Gem::Version
|
68
71
|
version: '7.0'
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '9'
|
69
75
|
description: Ansible integration with Foreman
|
70
76
|
email:
|
71
77
|
- elobatocs@gmail.com
|
@@ -489,9 +495,9 @@ test_files:
|
|
489
495
|
- test/functional/api/v2/ansible_playbooks_controller_test.rb
|
490
496
|
- test/functional/api/v2/ansible_roles_controller_test.rb
|
491
497
|
- test/functional/api/v2/ansible_variables_controller_test.rb
|
498
|
+
- test/functional/api/v2/ansible_inventories_controller_test.rb
|
492
499
|
- test/functional/api/v2/hostgroups_controller_test.rb
|
493
500
|
- test/functional/api/v2/hosts_controller_test.rb
|
494
|
-
- test/functional/api/v2/ansible_inventories_controller_test.rb
|
495
501
|
- test/functional/hosts_controller_test.rb
|
496
502
|
- test/functional/ui_ansible_roles_controller_test.rb
|
497
503
|
- test/graphql/mutations/hosts/assign_ansible_roles_mutation_test.rb
|
@@ -500,9 +506,9 @@ test_files:
|
|
500
506
|
- test/test_plugin_helper.rb
|
501
507
|
- test/unit/ansible_role_test.rb
|
502
508
|
- test/unit/ansible_variable_test.rb
|
503
|
-
- test/unit/concerns/config_reports_extensions_test.rb
|
504
509
|
- test/unit/concerns/host_managed_extensions_test.rb
|
505
510
|
- test/unit/concerns/hostgroup_extensions_test.rb
|
511
|
+
- test/unit/concerns/config_reports_extensions_test.rb
|
506
512
|
- test/unit/helpers/ansible_reports_helper_test.rb
|
507
513
|
- test/unit/host_ansible_role_test.rb
|
508
514
|
- test/unit/hostgroup_ansible_role_test.rb
|