Module: ForemanAnsible::AnsibleReportsHelper

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

Overview

This module takes the config reports stored in Foreman for Ansible and modifies them to be properly presented in views

Instance Method Summary collapse

Instance Method Details

#ansible_module_message(log) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/helpers/foreman_ansible/ansible_reports_helper.rb', line 28

def ansible_module_message(log)
  msg_json = parsed_message_json(log)
  module_action = msg_json['module']
  case module_action
  when 'package'
    msg_json['results'].empty? ? msg_json['msg'] : msg_json['results']
  when 'template'
    module_args = msg_json['invocation']['module_args']
    _("Rendered template #{module_args['_original_basename']} to #{msg_json['dest']}")
  when 'service'
    _("Service #{msg_json['name']} #{msg_json['state']} (enabled: #{msg_json['enabled']})")
  when 'group'
    _("User group #{msg_json['name']} #{msg_json['state']}, gid: #{msg_json['gid']}")
  when 'user'
    _("User #{msg_json['name']} #{msg_json['state']}, uid: #{msg_json['uid']}")
  when 'cron'
    module_args = msg_json['invocation']['module_args']
    _("Cron job: #{module_args['minute']} #{module_args['hour']} #{module_args['day']} #{module_args['month']} #{module_args['weekday']} #{module_args['job']} (disabled: #{module_args['disabled']})")
  when 'copy'
    module_args = msg_json['invocation']['module_args']
    _("Copy #{module_args['_original_basename']} to #{msg_json['dest']}")
  when 'command', 'shell'
    msg_json['stdout_lines']
  else
    no_data_message
  end
end

#ansible_module_name(log) ⇒ Object



7
8
9
10
11
# File 'app/helpers/foreman_ansible/ansible_reports_helper.rb', line 7

def ansible_module_name(log)
  source_value = log.source&.value
  name = source_value.split(':')[0].strip if source_value&.include?(':')
  name
end

#ansible_report?(log) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
71
72
# File 'app/helpers/foreman_ansible/ansible_reports_helper.rb', line 68

def ansible_report?(log)
  module_name(log).present?
rescue StandardError
  false
end

#ansible_report_origin_iconObject



60
61
62
# File 'app/helpers/foreman_ansible/ansible_reports_helper.rb', line 60

def ansible_report_origin_icon
  'foreman_ansible/Ansible.png'
end

#ansible_report_origin_partialObject



64
65
66
# File 'app/helpers/foreman_ansible/ansible_reports_helper.rb', line 64

def ansible_report_origin_partial
  'foreman_ansible/config_reports/ansible'
end

#ansible_run_in_check_mode?(log) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'app/helpers/foreman_ansible/ansible_reports_helper.rb', line 20

def ansible_run_in_check_mode?(log)
  log.message&.value == 'check_mode_enabled' if check_mode_log?(log)
end

#ansible_task_name(log) ⇒ Object



13
14
15
16
17
18
# File 'app/helpers/foreman_ansible/ansible_reports_helper.rb', line 13

def ansible_task_name(log)
  source_value = log.source&.value
  return source_value || no_data_message unless source_value.include? ':'
  name = source_value.split(':')[1].strip if source_value.include?(':')
  name || no_data_message
end

#check_mode_log?(log) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/helpers/foreman_ansible/ansible_reports_helper.rb', line 24

def check_mode_log?(log)
  log.source&.value == 'check_mode'
end

#no_data_messageObject



56
57
58
# File 'app/helpers/foreman_ansible/ansible_reports_helper.rb', line 56

def no_data_message
  _('No additional data')
end