Sha256: 57d98b08ac2e16d8fbfce5f94c9457f1a5ac0dbfc1f0c667c48a6ebde691ebfe

Contents?: true

Size: 989 Bytes

Versions: 65

Compression:

Stored size: 989 Bytes

Contents

# frozen_string_literal: true

module ForemanAnsible
  # Imports roles from smart proxy
  class RolesImporter
    include ::ForemanAnsible::ProxyAPI

    def initialize(proxy = nil)
      @ansible_proxy = proxy
      @variables_importer = ForemanAnsible::VariablesImporter.new(@ansible_proxy)
    end

    def import_role_names
      import_roles remote_roles if @ansible_proxy.present?
    end

    def fetch_role_names
      remote_roles if ansible_proxy
    end

    def import_roles(roles)
      imported = roles.map do |role_name|
        ::AnsibleRole.find_or_initialize_by(:name => role_name)
      end
      detect_changes imported
    end

    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

    private

    def remote_roles
      proxy_api.roles
    end
  end
end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
foreman_ansible-15.0.2 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-15.0.1 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-15.0.0 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-14.2.2 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-14.2.1 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-13.0.7 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-14.2.0 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-14.1.1 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-14.1.0 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-13.0.5 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-14.0.0 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-13.0.4 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-13.0.3 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-13.0.2 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-13.0.1 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-13.0.0 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-12.0.7 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-10.4.4 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-7.1.8 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-12.0.6 app/services/foreman_ansible/roles_importer.rb