Sha256: 25359891e376bf6b6a4f812f0915daa455f34a2edbf55c583bec704d245b257c

Contents?: true

Size: 1023 Bytes

Versions: 105

Compression:

Stored size: 1023 Bytes

Contents

# frozen_string_literal: true

module ForemanAnsible
  module Concerns
    # Extra methods to enforce Ansible roles on a host or multiple hosts
    module HostgroupsControllerExtensions
      extend ActiveSupport::Concern
      include ForemanTasks::Triggers
      include ::ForemanAnsible::Concerns::JobInvocationHelper

      def play_roles
        find_resource
        check_hostgroup
        composer = job_composer(:ansible_run_host, @hostgroup.hosts)
        composer.trigger
        redirect_to job_invocation_path(composer.job_invocation)
      rescue Foreman::Exception => e
        error e.message
        redirect_to hostgroups_path
      end

      private

      def check_hostgroup
        return unless @hostgroup.hosts.empty?
        raise ::Foreman::Exception.new(
          N_('Host group has no associated hosts')
        )
      end

      def action_permission
        case params[:action]
        when 'play_roles'
          :view
        else
          super
        end
      end
    end
  end
end

Version data entries

105 entries across 105 versions & 1 rubygems

Version Path
foreman_ansible-5.0.1 app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb
foreman_ansible-4.0.5 app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb
foreman_ansible-4.0.3.1 app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb
foreman_ansible-4.0.4 app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb
foreman_ansible-5.0.0 app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb
foreman_ansible-4.0.3 app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb
foreman_ansible-4.0.2 app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb
foreman_ansible-4.0.0 app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb
foreman_ansible-3.0.9 app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb
foreman_ansible-3.0.8 app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb
foreman_ansible-3.0.7 app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb
foreman_ansible-3.0.6 app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb
foreman_ansible-3.0.5 app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb
foreman_ansible-3.0.4 app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb
foreman_ansible-3.0.3 app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb
foreman_ansible-2.3.6 app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb
foreman_ansible-2.3.5 app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb
foreman_ansible-2.3.4 app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb
foreman_ansible-3.0.2 app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb
foreman_ansible-3.0.1 app/controllers/foreman_ansible/concerns/hostgroups_controller_extensions.rb