Sha256: 38fbeb14393fb070c1955771f4b3419114d42c577be4ffcfc0026eaba7f2cf8c

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

module ForemanAnsible
  # Chained methods to extend the hosts menu with Ansible actions
  module HostsHelperExtensions
    extend ActiveSupport::Concern

    included do
      alias_method_chain(:host_title_actions, :run_ansible_roles)
      alias_method_chain(:multiple_actions, :run_ansible_roles)
    end

    def ansible_roles_present?(host)
      host.ansible_roles.present? ||
        host.inherited_ansible_roles.present?
    end

    def ansible_roles_button(host)
      link_to(
        _('Run Ansible roles'),
        play_roles_host_path(:id => host.id),
        :id => :ansible_roles_button,
        :class => 'btn btn-default',
        :'data-no-turbolink' => true
      )
    end

    def host_title_actions_with_run_ansible_roles(*args)
      host = args.first
      if ansible_roles_present?(host)
        button = ansible_roles_button(host)
        title_actions(button_group(button))
      end
      host_title_actions_without_run_ansible_roles(*args)
    end

    def multiple_actions_with_run_ansible_roles
      multiple_actions_without_run_ansible_roles +
        [[_('Play Ansible roles'),
          multiple_play_roles_hosts_path,
          false]]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
foreman_ansible-1.5.2 app/helpers/foreman_ansible/hosts_helper_extensions.rb
foreman_ansible-1.5.1 app/helpers/foreman_ansible/hosts_helper_extensions.rb
foreman_ansible-1.5.0 app/helpers/foreman_ansible/hosts_helper_extensions.rb
foreman_ansible-1.4.6 app/helpers/foreman_ansible/hosts_helper_extensions.rb