Class: ForemanAnsible::RolesImporter
- Inherits:
-
Object
- Object
- ForemanAnsible::RolesImporter
- Defined in:
- app/services/foreman_ansible/roles_importer.rb
Overview
imports roles from smart proxy
Direct Known Subclasses
Instance Attribute Summary collapse
-
#ansible_proxy ⇒ Object
readonly
Returns the value of attribute ansible_proxy.
Instance Method Summary collapse
- #detect_changes(imported) ⇒ Object
- #import_role_names ⇒ Object
- #import_roles(roles) ⇒ Object
-
#initialize(proxy = nil) ⇒ RolesImporter
constructor
A new instance of RolesImporter.
Constructor Details
#initialize(proxy = nil) ⇒ RolesImporter
Returns a new instance of RolesImporter.
6 7 8 |
# File 'app/services/foreman_ansible/roles_importer.rb', line 6 def initialize(proxy = nil) @ansible_proxy = proxy end |
Instance Attribute Details
#ansible_proxy ⇒ Object (readonly)
Returns the value of attribute ansible_proxy.
4 5 6 |
# File 'app/services/foreman_ansible/roles_importer.rb', line 4 def ansible_proxy @ansible_proxy end |
Instance Method Details
#detect_changes(imported) ⇒ Object
22 23 24 25 26 27 |
# File 'app/services/foreman_ansible/roles_importer.rb', line 22 def detect_changes(imported) changes = {}.with_indifferent_access old, changes[:new] = imported.partition { |role| role.id.present? } changes[:obsolete] = ::AnsibleRole.where.not(:id => old.map(&:id)) changes end |
#import_role_names ⇒ Object
10 11 12 13 |
# File 'app/services/foreman_ansible/roles_importer.rb', line 10 def import_role_names return import_roles remote_roles if ansible_proxy import_roles local_roles end |
#import_roles(roles) ⇒ Object
15 16 17 18 19 20 |
# File 'app/services/foreman_ansible/roles_importer.rb', line 15 def import_roles(roles) imported = roles.map do |role_name| ::AnsibleRole.find_or_initialize_by(:name => role_name) end detect_changes imported end |