Sha256: 4da249741d5db59f738ee626350371e6027d90abaed696ef5710566bb563bfeb

Contents?: true

Size: 1.17 KB

Versions: 12

Compression:

Stored size: 1.17 KB

Contents

module ForemanAnsible
  module Api
    module V2
      # Extends the hosts controller to support playing ansible roles
      module HostsControllerExtensions
        extend ActiveSupport::Concern
        include ForemanTasks::Triggers
        include ::ForemanAnsible::Concerns::JobInvocationHelper

        included do
          api :POST, '/hosts/:id/play_roles',
              N_('Plays Ansible roles on a host')
          param :id, String, :required => true

          def play_roles
            composer = job_composer(:ansible_run_host, @host)
            process_response composer.trigger!, composer.job_invocation
          end

          api :POST, '/hosts/play_roles', N_('Plays Ansible roles on hosts')
          param :id, Array, :required => true

          def multiple_play_roles
            composer = job_composer(:ansible_run_host, @host.pluck(:id))
            process_response composer.trigger!, composer.job_invocation
          end
        end

        private

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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
foreman_ansible-2.2.9 app/controllers/foreman_ansible/api/v2/hosts_controller_extensions.rb
foreman_ansible-2.2.8 app/controllers/foreman_ansible/api/v2/hosts_controller_extensions.rb
foreman_ansible-2.2.7 app/controllers/foreman_ansible/api/v2/hosts_controller_extensions.rb
foreman_ansible-2.2.6 app/controllers/foreman_ansible/api/v2/hosts_controller_extensions.rb
foreman_ansible-2.2.5 app/controllers/foreman_ansible/api/v2/hosts_controller_extensions.rb
foreman_ansible-2.2.4 app/controllers/foreman_ansible/api/v2/hosts_controller_extensions.rb
foreman_ansible-2.2.3 app/controllers/foreman_ansible/api/v2/hosts_controller_extensions.rb
foreman_ansible-2.2.2 app/controllers/foreman_ansible/api/v2/hosts_controller_extensions.rb
foreman_ansible-2.2.1 app/controllers/foreman_ansible/api/v2/hosts_controller_extensions.rb
foreman_ansible-2.2.0 app/controllers/foreman_ansible/api/v2/hosts_controller_extensions.rb
foreman_ansible-2.1.2 app/controllers/foreman_ansible/api/v2/hosts_controller_extensions.rb
foreman_ansible-2.1.1 app/controllers/foreman_ansible/api/v2/hosts_controller_extensions.rb