foreman_ansible 11.2.0 → 11.2.1
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/register.rb +2 -2
- 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 +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98bb40689075e650d183fa18b3ca8d17efc0853118e25cb8336776ea7b232316
|
4
|
+
data.tar.gz: '082247e41adcf83e7bd7a4f4190550e05e01fe3d9c96cefd7d3cd03284a9e37b'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3416cfa163fd8cca335bf8bd35b5ad49ab68f2fccfc18286593bd9fbb9e93dad23aa2503eeb0226ea4275977ec5ebeea0dcef66a4f1aa94862a35349f35f3ae
|
7
|
+
data.tar.gz: 5814abb5d63b7a9e702b1f899e7b54626dabc0da4da9d7b2b16bc54aed88cad7853c8653b6137a6188a5f783a7dcd11120e9fd29d68ea3b18241299f03adcf7a
|
@@ -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
|
@@ -151,10 +151,10 @@ Foreman::Plugin.register :foreman_ansible do
|
|
151
151
|
:'api/v2/ansible_inventories' => [:hostgroups] },
|
152
152
|
:resource_type => 'Hostgroup'
|
153
153
|
permission :edit_hosts,
|
154
|
-
{ :'api/v2/hosts' => [:assign_ansible_roles] },
|
154
|
+
{ :'api/v2/hosts' => [:assign_ansible_roles, :add_ansible_role, :remove_ansible_role] },
|
155
155
|
:resource_type => 'Host'
|
156
156
|
permission :edit_hostgroups,
|
157
|
-
{ :'api/v2/hostgroups' => [:assign_ansible_roles] },
|
157
|
+
{ :'api/v2/hostgroups' => [:assign_ansible_roles, :add_ansible_role, :remove_ansible_role] },
|
158
158
|
:resource_type => 'Hostgroup'
|
159
159
|
permission :generate_ansible_inventory,
|
160
160
|
{ :'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: 11.2.
|
4
|
+
version: 11.2.1
|
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-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: acts_as_list
|
@@ -489,9 +489,9 @@ test_files:
|
|
489
489
|
- test/functional/api/v2/ansible_playbooks_controller_test.rb
|
490
490
|
- test/functional/api/v2/ansible_roles_controller_test.rb
|
491
491
|
- test/functional/api/v2/ansible_variables_controller_test.rb
|
492
|
+
- test/functional/api/v2/ansible_inventories_controller_test.rb
|
492
493
|
- test/functional/api/v2/hostgroups_controller_test.rb
|
493
494
|
- test/functional/api/v2/hosts_controller_test.rb
|
494
|
-
- test/functional/api/v2/ansible_inventories_controller_test.rb
|
495
495
|
- test/functional/hosts_controller_test.rb
|
496
496
|
- test/functional/ui_ansible_roles_controller_test.rb
|
497
497
|
- test/graphql/mutations/hosts/assign_ansible_roles_mutation_test.rb
|