Sha256: db35c17ba5b839175317d92c0903dcfbd53586962266461790461885fe9ed84e

Contents?: true

Size: 1.31 KB

Versions: 62

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

module ForemanAnsible
  # imports Ansible roles through API
  class ApiRolesImporter < RolesImporter
    include ::ForemanAnsible::AnsibleRolesDataPreparations

    def import!(role_names)
      @roles_importer = ForemanAnsible::UiRolesImporter.new(@ansible_proxy)
      @variables_importer = ForemanAnsible::VariablesImporter.new(@ansible_proxy)
      params = { 'changed' => {} }
      roles = prepare_ansible_import_rows(@roles_importer.import!, @variables_importer, false)
      roles.each do |role|
        if role_names.include? role[:name]
          params['changed'][role[:kind]] ||= {}
          params['changed'][role[:kind]][role[:name]] = { 'id' => role[:id], 'name' => role[:name] }
        end
      end
      params
    end

    def confirm_import(params)
      @roles_importer.finish_import(params['changed'])
      @variables_importer.import_variables_roles(params['changed']) if params['changed']['new'] || params['changed']['old']
    end

    def confirm_sync(params)
      job = SyncRolesAndVariables.perform_later(params['changed'], @ansible_proxy)
      task = ForemanTasks::Task.find_by(external_id: job.provider_job_id)
      task
    end

    def obsolete!
      obsolete_roles = import_role_names[:obsolete]
      obsolete_roles.map(&:destroy)
      obsolete_roles
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
foreman_ansible-14.2.2 app/services/foreman_ansible/api_roles_importer.rb
foreman_ansible-14.2.1 app/services/foreman_ansible/api_roles_importer.rb
foreman_ansible-13.0.7 app/services/foreman_ansible/api_roles_importer.rb
foreman_ansible-14.2.0 app/services/foreman_ansible/api_roles_importer.rb
foreman_ansible-14.1.1 app/services/foreman_ansible/api_roles_importer.rb
foreman_ansible-14.1.0 app/services/foreman_ansible/api_roles_importer.rb
foreman_ansible-13.0.5 app/services/foreman_ansible/api_roles_importer.rb
foreman_ansible-14.0.0 app/services/foreman_ansible/api_roles_importer.rb
foreman_ansible-13.0.4 app/services/foreman_ansible/api_roles_importer.rb
foreman_ansible-13.0.3 app/services/foreman_ansible/api_roles_importer.rb
foreman_ansible-13.0.2 app/services/foreman_ansible/api_roles_importer.rb
foreman_ansible-13.0.1 app/services/foreman_ansible/api_roles_importer.rb
foreman_ansible-13.0.0 app/services/foreman_ansible/api_roles_importer.rb
foreman_ansible-12.0.7 app/services/foreman_ansible/api_roles_importer.rb
foreman_ansible-10.4.4 app/services/foreman_ansible/api_roles_importer.rb
foreman_ansible-7.1.8 app/services/foreman_ansible/api_roles_importer.rb
foreman_ansible-12.0.6 app/services/foreman_ansible/api_roles_importer.rb
foreman_ansible-12.0.5 app/services/foreman_ansible/api_roles_importer.rb
foreman_ansible-10.4.3 app/services/foreman_ansible/api_roles_importer.rb
foreman_ansible-12.0.4 app/services/foreman_ansible/api_roles_importer.rb