Module: ForemanAnsible::AnsibleHostgroupsHelper

Defined in:
app/helpers/foreman_ansible/ansible_hostgroups_helper.rb

Instance Method Summary collapse

Instance Method Details

#ansible_hostgroups_actions(hostgroup) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/foreman_ansible/ansible_hostgroups_helper.rb', line 5

def ansible_hostgroups_actions(hostgroup)
  actions = []
  is_hostgroup_empty = hostgroup.all_ansible_roles.empty? || hostgroup.hosts_count.zero?

  if User.current.can?(:create_job_invocations)
    actions << {
      action: if is_hostgroup_empty
                disabled_action_link(_('Run all Ansible roles'))
              else
                display_link_if_authorized(_('Run all Ansible roles'), hash_for_play_roles_hostgroup_path(id: hostgroup), 'data-no-turbolink': true, title: _('Run all Ansible roles on hosts belonging to this host group'))
              end,
      priority: 31
    }
  end

  if User.current.can?(:view_job_invocations) && User.current.can?(:view_recurring_logics)
    actions << {
      action: if is_hostgroup_empty
                disabled_action_link(_('Configure Ansible Job'))
              else
                link_to(_('Configure Ansible Job'), "/ansible/hostgroups/#{hostgroup.id}", class: 'la')
              end,
      priority: 32
    }
  end

  actions
end


34
35
36
37
38
39
# File 'app/helpers/foreman_ansible/ansible_hostgroups_helper.rb', line 34

def disabled_action_link(text)
  {
    content: link_to(text, 'javascript:void(0);', disabled: true, title: _('No roles/hosts assigned'), class: 'disabled'),
    options: { class: 'disabled' }
  }
end