Class: ForemanAnsible::RolesImporter
- Inherits:
-
Object
- Object
- ForemanAnsible::RolesImporter
show all
- Includes:
- ProxyAPI
- Defined in:
- app/services/foreman_ansible/roles_importer.rb
Overview
Imports roles from smart proxy
Instance Method Summary
collapse
Constructor Details
#initialize(proxy = nil) ⇒ RolesImporter
Returns a new instance of RolesImporter.
8
9
10
11
|
# File 'app/services/foreman_ansible/roles_importer.rb', line 8
def initialize(proxy = nil)
@ansible_proxy = proxy
@variables_importer = ForemanAnsible::VariablesImporter.new(@ansible_proxy)
end
|
Instance Method Details
#detect_changes(imported) ⇒ Object
28
29
30
31
32
33
|
# File 'app/services/foreman_ansible/roles_importer.rb', line 28
def detect_changes(imported)
changes = {}.with_indifferent_access
changes[:old], changes[:new] = imported.partition { |role| role.id.present? }
changes[:obsolete] = ::AnsibleRole.where.not(:id => changes[:old].map(&:id))
changes
end
|
#fetch_role_names ⇒ Object
17
18
19
|
# File 'app/services/foreman_ansible/roles_importer.rb', line 17
def fetch_role_names
remote_roles if ansible_proxy
end
|
#import_role_names ⇒ Object
13
14
15
|
# File 'app/services/foreman_ansible/roles_importer.rb', line 13
def import_role_names
import_roles remote_roles if @ansible_proxy.present?
end
|
#import_roles(roles) ⇒ Object
21
22
23
24
25
26
|
# File 'app/services/foreman_ansible/roles_importer.rb', line 21
def import_roles(roles)
imported = roles.map do |role_name|
::AnsibleRole.find_or_initialize_by(:name => role_name)
end
detect_changes imported
end
|