diff --git a/app/helpers/foreman_ansible/ansible_reports_helper.rb b/app/helpers/foreman_ansible/ansible_reports_helper.rb index 88cbdb601..b8a2722b0 100644 --- a/app/helpers/foreman_ansible/ansible_reports_helper.rb +++ b/app/helpers/foreman_ansible/ansible_reports_helper.rb @@ -27,6 +27,8 @@ def check_mode_log?(log) def ansible_module_message(log) msg_json = parsed_message_json(log) + return _("Execution error: #{msg_json['msg']}") if msg_json['failed'].present? + module_action = msg_json['module'] case module_action when 'package' @@ -67,6 +69,17 @@ def ansible_report?(log) false end + def show_full_error_message_value(message_value) + tag.div class: 'replace-hidden-value' do + link_to_function(icon_text('plus', '', class: 'small'), 'replace_value_control(this, "div")', + title: _('Show full value'), + class: 'replace-hidden-value pull-right') + + (tag.span class: 'full-value' do + message_value + end) + end + end + private def parsed_message_json(log) diff --git a/app/views/foreman_ansible/config_reports/_ansible.html.erb b/app/views/foreman_ansible/config_reports/_ansible.html.erb index c3c14c807..bc2b4706c 100644 --- a/app/views/foreman_ansible/config_reports/_ansible.html.erb +++ b/app/views/foreman_ansible/config_reports/_ansible.html.erb @@ -29,8 +29,12 @@ <% end %> <% else %> - <%= log_message %> - <% end %> + <% allowed_length = 150 %> +
+ <%= truncate(log_message, length: allowed_length) %> +
+ <%= show_full_error_message_value(log_message) if log_message.length > allowed_length %> + <% end %> <% end %> diff --git a/test/unit/helpers/ansible_reports_helper_test.rb b/test/unit/helpers/ansible_reports_helper_test.rb index 4b019afc6..28417904e 100644 --- a/test/unit/helpers/ansible_reports_helper_test.rb +++ b/test/unit/helpers/ansible_reports_helper_test.rb @@ -19,4 +19,18 @@ class AnsibleReportsHelperTest < ActiveSupport::TestCase ansible_module_message(log).to_s ) end + + test 'module message extraction with error' do + log_value = <<-ANSIBLELOG.strip_heredoc + {"msg": "AnsibleUndefinedVariable", "changed": false, "_ansible_no_log": false, "failed": true, "module": "template", "exception": "raise AnsibleUndefinedVariable"} +ANSIBLELOG + message = FactoryBot.build(:message, value: log_value) + log = FactoryBot.build(:log, message: message) + log.message = message + + assert_match( + 'Execution error: AnsibleUndefinedVariable', + ansible_module_message(log).to_s + ) + end end