On Thu, Apr 01, 2021 at 06:33:54PM +0800, Wang Chenglong wrote:
[Why] optimize the output of error_id standard format: @module_name:error_id
before: error.[message].Could-not-find-or-access-RedHat-20-yml-Searched-in-root-ansible-roles-ansible-role-postgresql-vars-RedHat-20-yml-root-ansible- roles-ansible-role-postgresql-RedHat-20-yml-root-ansible-roles-ansible-role-postgresql-tasks-vars-RedHat-20-yml-root-ansible-roles-ansible-role- postgresql-tasks-RedHat-20-yml-root-ansible-vars-RedHat-20-yml-root-ansible-RedHat-20-yml-on-the-Ansible-Controller-If-you-are-using-a-module- and-expect-the-file-to-exist-on-the-remote-see-the-remote_src-option: 1
after: @inculde_vars:Could-not-find-or-access-RedHat-20-yml: 1
Signed-off-by: Wang Chenglong 18509160991@163.com
stats/ansible_test | 101 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 85 insertions(+), 16 deletions(-)
diff --git a/stats/ansible_test b/stats/ansible_test index 3d3b0b0cb..d7f084027 100755 --- a/stats/ansible_test +++ b/stats/ansible_test @@ -1,40 +1,109 @@ #!/usr/bin/env ruby
require 'json' +require 'yaml'
-def output_error(error_msg, error_key)
- return if error_msg.nil?
+def output_error(error_msg) if error_msg.is_a? Array error_msg.each do |i| error_id = common_error_id i
puts "error.[#{error_key}].#{error_id}: 1"
puts "error.#{error_id}.message: #{@ansible_failed_info}"
puts "@#{@module_name['action']}:#{error_id}: 1"
end elsif error_msg.is_a? String error_id = common_error_id error_msgputs "@#{@module_name['action']}:#{error_id}.message: #{@ansible_failed_info}"
- puts "error.[#{error_key}].#{error_id}: 1"
- puts "error.#{error_id}.message: #{@ansible_failed_info}"
- puts "@#{@module_name['action']}:#{error_id}: 1"
- puts "@#{@module_name['action']}:#{error_id}.message: #{@ansible_failed_info}" end
end
def common_error_id(line)
- line.gsub!(/[^\w]/, '-')
- line.gsub!(/[^\w]/, '--')
- line.gsub!(/[0-9]{3,}/, '#') line.gsub!(/-+/, '-') # Replace multiple consecutive '-' with a single one line.gsub!(/^-|-$/, '') line
end
+def parse_msg(ansible_failed_json)
- case ansible_failed_json['msg']
- when /package (.*64)/
- output_error "cannot install the #{$1} for the job"
- when /(The error appears to be in .*')/
- output_error $1
- when /(Failed to import the required Python library .*python3.)/
- output_error $1
- # when /(An unhandled exception occurred while running the lookup plugin .*'.)/
- when /original message: (.*)/
- output_error $1
- when /(Unable to start service (\w{1,}):)/
- output_error $1
- when /(Failed to download metadata for repo .*'):/
- output_error $1
- when /(Failed to download packages: (.*):)/
- output_error $2
- when /(Failed to find required .* in paths):/
- output_error $1
- when /(Failure downloading .*),/
- output_error $1
- when /(Could not find or access.*)'/
- output_error $1
- when /(Could not find .*):/
- output_error $1
- when /(Unsupported parameters) for/
- output_error $1
- when /aajdhch/
- output_error $1
- when /non-zero return code|Failed to install some of the specified packages/
- return
- else
- output_error ansible_failed_json['msg']
- end
+end
+def parse_stderr(ansible_failed_json)
- case ansible_failed_json['stderr']
- when /^$/
- return
- else
- ansible_failed_json['stderr_lines'].each do |i|
output_error i
- end
- end
return if ansible_failed_json['stderr'].empty ansible_failed_json['stderr_lines'].each do |i| ...
+end
+def parse_message(ansible_failed_json)
- case ansible_failed_json['message']
- when /(Could not find or access.*)'/
- output_error $1
- else
- output_error ansible_failed_json['message']
- end
+end
+def parse_failures(ansible_failed_json)
- ansible_failed_json['failures'].each do |i|
- case i
- when /(.*)/
output_error $1
- end
just use: output_error i if i
- end
+end
while (line = STDIN.gets)
- next unless line =~ /(FAILED!|failed:).*=>(.*)/
- case line
- when /({'action'.*})/
- @module_name = YAML.load($1)
- when /(FAILED!|failed:).*=>(.*)/
- @ansible_failed_info = $2
- next if @ansible_failed_info.empty?
- @ansible_failed_info = $2
- next if @ansible_failed_info.empty?
- ansible_failed_json = JSON.parse @ansible_failed_info
- ansible_failed_json = JSON.parse @ansible_failed_info
- output_error ansible_failed_json['msg'],'msg'
- output_error ansible_failed_json['message'],'message'
- output_error ansible_failed_json['cmd'],'cmd'
- output_error ansible_failed_json['failures'],'failures'
- parse_msg ansible_failed_json unless ansible_failed_json['msg'].nil?
- parse_stderr ansible_failed_json unless ansible_failed_json['stderr'].nil?
- parse_message ansible_failed_json unless ansible_failed_json['message'].nil?
- parse_failures ansible_failed_json unless ansible_failed_json['failures'].nil?
- end
end
2.23.0