Class: ForemanAnsible::UIRolesImporter

Inherits:
RolesImporter show all
Defined in:
app/services/foreman_ansible/ui_roles_importer.rb

Overview

imports ansible roles through UI

Instance Method Summary collapse

Methods inherited from RolesImporter

#detect_changes, #fetch_role_names, #import_role_names, #import_roles, #initialize

Constructor Details

This class inherits a constructor from ForemanAnsible::RolesImporter

Instance Method Details

#create_new_roles(changes) ⇒ Object



16
17
18
19
20
# File 'app/services/foreman_ansible/ui_roles_importer.rb', line 16

def create_new_roles(changes)
  changes.each_pair do |_, new_role|
    ::AnsibleRole.create(new_role)
  end
end

#delete_old_roles(changes) ⇒ Object



22
23
24
25
26
# File 'app/services/foreman_ansible/ui_roles_importer.rb', line 22

def delete_old_roles(changes)
  changes.each_pair do |_, old_role|
    ::AnsibleRole.find(old_role['id']).destroy
  end
end

#finish_import(changes) ⇒ Object



10
11
12
13
14
# File 'app/services/foreman_ansible/ui_roles_importer.rb', line 10

def finish_import(changes)
  return if changes.blank?
  create_new_roles changes['new'] if changes['new']
  delete_old_roles changes['obsolete'] if changes['obsolete']
end

#import!Object



6
7
8
# File 'app/services/foreman_ansible/ui_roles_importer.rb', line 6

def import!
  import_role_names
end