foreman_ansible 2.2.4 → 2.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/concerns/foreman_ansible/host_managed_extensions.rb +11 -6
- data/app/models/concerns/foreman_ansible/hostgroup_extensions.rb +7 -1
- data/lib/foreman_ansible/version.rb +1 -1
- data/test/unit/concerns/host_managed_extensions_test.rb +1 -0
- data/test/unit/concerns/hostgroup_extensions_test.rb +17 -3
- metadata +2 -3
- data/app/models/concerns/foreman_ansible/has_many_ansible_roles.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e462c3b9312bf42cb1f7a267edbe619aae3849dc
|
4
|
+
data.tar.gz: 1cd77d5a1ab0047c0b25108a995c73790f92e774
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e77318b028e35757faa9bc78b523edfba003bf15c4a687f1592c6d16e0191d1d2fa913da461e757f95118bc6bf0132a78f58381c1c10bcf9c2bd9ab94ee65da3
|
7
|
+
data.tar.gz: d381adc5b3aaa880a0e71da579bb2f7f063bd76e8542500de92ed53ccb06443974e168e31a5588cb51f351c96416805f47146c17c406c75d0f249996ea327d71
|
@@ -15,12 +15,11 @@ module ForemanAnsible
|
|
15
15
|
:only_explicit => true
|
16
16
|
|
17
17
|
before_provision :play_ansible_roles
|
18
|
-
include ForemanAnsible::HasManyAnsibleRoles
|
19
18
|
audit_associations :ansible_roles
|
20
19
|
|
21
20
|
def inherited_ansible_roles
|
22
21
|
return [] unless hostgroup
|
23
|
-
hostgroup.
|
22
|
+
hostgroup.inherited_and_own_ansible_roles
|
24
23
|
end
|
25
24
|
|
26
25
|
# This one should be fixed, disabled for the moment as we're
|
@@ -43,14 +42,20 @@ module ForemanAnsible
|
|
43
42
|
"#{e.message}")
|
44
43
|
end
|
45
44
|
# rubocop:enable Metrics/AbcSize
|
45
|
+
|
46
|
+
def all_ansible_roles
|
47
|
+
(ansible_roles + inherited_ansible_roles).uniq
|
48
|
+
end
|
46
49
|
end
|
47
50
|
# rubocop:enable Metrics/BlockLength
|
48
51
|
# Class methods we may need to override or add
|
49
52
|
module ClassMethods
|
50
|
-
def import_host(
|
51
|
-
host = super(
|
52
|
-
|
53
|
-
|
53
|
+
def import_host(*args)
|
54
|
+
host = super(*args)
|
55
|
+
hostname = args[0]
|
56
|
+
if IPAddress.valid?(hostname) &&
|
57
|
+
(host_nic = Nic::Interface.find_by(:ip => hostname))
|
58
|
+
host = host_nic.host
|
54
59
|
end
|
55
60
|
host
|
56
61
|
end
|
@@ -7,7 +7,6 @@ module ForemanAnsible
|
|
7
7
|
has_many :hostgroup_ansible_roles, :foreign_key => :hostgroup_id
|
8
8
|
has_many :ansible_roles, :through => :hostgroup_ansible_roles,
|
9
9
|
:dependent => :destroy
|
10
|
-
include ForemanAnsible::HasManyAnsibleRoles
|
11
10
|
audit_associations :ansible_roles
|
12
11
|
|
13
12
|
def inherited_ansible_roles
|
@@ -25,6 +24,13 @@ module ForemanAnsible
|
|
25
24
|
def host_ansible_roles
|
26
25
|
hosts.all.includes(:ansible_roles).flat_map(&:ansible_roles)
|
27
26
|
end
|
27
|
+
|
28
|
+
# includes also roles of all assigned hosts, useful to determine if
|
29
|
+
# at least one host in this hostgroup has some ansible role assigned
|
30
|
+
# either directly or through hostgroup
|
31
|
+
def all_ansible_roles
|
32
|
+
(ansible_roles + inherited_ansible_roles + host_ansible_roles).uniq
|
33
|
+
end
|
28
34
|
end
|
29
35
|
end
|
30
36
|
end
|
@@ -11,6 +11,7 @@ class HostManagedExtensionsTest < ActiveSupport::TestCase
|
|
11
11
|
:ansible_roles => [@role2])
|
12
12
|
@hostgroup = FactoryBot.create(:hostgroup, :parent => @hostgroup_parent)
|
13
13
|
@host = FactoryBot.build_stubbed(:host, :ansible_roles => [@role1])
|
14
|
+
@another_host = FactoryBot.build_stubbed(:host, :ansible_roles => [@role3])
|
14
15
|
end
|
15
16
|
|
16
17
|
describe '#all_ansible_roles' do
|
@@ -10,16 +10,19 @@ class HostgroupExtensionsTest < ActiveSupport::TestCase
|
|
10
10
|
@hostgroup_parent = FactoryBot.create(:hostgroup,
|
11
11
|
:ansible_roles => [@role2])
|
12
12
|
@hostgroup = FactoryBot.create(:hostgroup, :ansible_roles => [@role1])
|
13
|
+
@host = FactoryBot.create(:host,
|
14
|
+
:ansible_roles => [@role3],
|
15
|
+
:hostgroup => @hostgroup)
|
13
16
|
end
|
14
17
|
|
15
18
|
describe '#all_ansible_roles' do
|
16
19
|
test 'returns assigned roles without any parent hostgroup' do
|
17
|
-
@hostgroup.all_ansible_roles.must_equal [@role1]
|
20
|
+
@hostgroup.all_ansible_roles.must_equal [@role1, @role3]
|
18
21
|
end
|
19
22
|
|
20
|
-
test 'returns assigned and inherited roles with
|
23
|
+
test 'returns assigned and inherited roles with from parent hostgroup' do
|
21
24
|
@hostgroup.parent = @hostgroup_parent
|
22
|
-
@hostgroup.all_ansible_roles.must_equal [@role1, @role2]
|
25
|
+
@hostgroup.all_ansible_roles.must_equal [@role1, @role2, @role3]
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
@@ -33,4 +36,15 @@ class HostgroupExtensionsTest < ActiveSupport::TestCase
|
|
33
36
|
@hostgroup.inherited_ansible_roles.must_equal [@role2]
|
34
37
|
end
|
35
38
|
end
|
39
|
+
|
40
|
+
describe '#inherited_and_own_ansible_roles' do
|
41
|
+
test 'returns only hostgroup roles' do
|
42
|
+
@hostgroup_parent.inherited_and_own_ansible_roles.must_equal [@role2]
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'returns only hostgroup roles including inheritance' do
|
46
|
+
@hostgroup.parent = @hostgroup_parent
|
47
|
+
@hostgroup.inherited_and_own_ansible_roles.must_equal [@role2, @role1]
|
48
|
+
end
|
49
|
+
end
|
36
50
|
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.2.
|
4
|
+
version: 2.2.5
|
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: 2018-07-
|
11
|
+
date: 2018-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -135,7 +135,6 @@ files:
|
|
135
135
|
- app/lib/actions/foreman_ansible/helpers/play_roles_description.rb
|
136
136
|
- app/lib/proxy_api/ansible.rb
|
137
137
|
- app/models/ansible_role.rb
|
138
|
-
- app/models/concerns/foreman_ansible/has_many_ansible_roles.rb
|
139
138
|
- app/models/concerns/foreman_ansible/host_managed_extensions.rb
|
140
139
|
- app/models/concerns/foreman_ansible/hostgroup_extensions.rb
|
141
140
|
- app/models/foreman_ansible/ansible_provider.rb
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module ForemanAnsible
|
2
|
-
# Define common behaviors between models that have many Ansible roles,
|
3
|
-
# currently Host and Hostgroup. Takes care of inheritance, etc...
|
4
|
-
module HasManyAnsibleRoles
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
included do
|
8
|
-
def all_ansible_roles
|
9
|
-
result = (ansible_roles + inherited_ansible_roles).uniq
|
10
|
-
result += host_ansible_roles if is_a? Hostgroup
|
11
|
-
result
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|