Class: ForemanAnsible::AnsibleReportScanner

Inherits:
Object
  • Object
show all
Defined in:
app/services/foreman_ansible/ansible_report_scanner.rb

Overview

Scans ConfigReports after import for indicators of an Ansible report and sets the origin of the report to ‘Ansible’

Class Method Summary collapse

Class Method Details

.add_reporter_data(_report, raw) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/services/foreman_ansible/ansible_report_scanner.rb', line 8

def add_reporter_data(_report, raw)
  check_mode_message = raw['check_mode'] ? 'check_mode_enabled' : 'check_mode_disabled'
  check_mode_log = {
    'log': {
      'sources': {
        'source': 'check_mode'
      },
      'messages': {
        'message': check_mode_message
      },
      'level': 'info'
    }
  }
  raw['logs'].insert(0, check_mode_log.deep_stringify_keys)
end

.ansible_legacy_report?(logs) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'app/services/foreman_ansible/ansible_report_scanner.rb', line 32

def ansible_legacy_report?(logs)
  return false if logs.blank?
  logs.any? do |log|
    log['log'].fetch('messages', {}).
      fetch('message', '') =~ /"_ansible_parsed"/
  end
end

.ansible_report?(raw) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'app/services/foreman_ansible/ansible_report_scanner.rb', line 28

def ansible_report?(raw)
  raw['reporter'] == 'ansible' || ansible_legacy_report?(raw['logs'])
end

.identify_origin(raw) ⇒ Object



24
25
26
# File 'app/services/foreman_ansible/ansible_report_scanner.rb', line 24

def identify_origin(raw)
  'Ansible' if ansible_report?(raw)
end