Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions lib/smart_proxy_ansible/runner/ansible_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def hostname_for_event(event)

def handle_host_event(hostname, event)
log_event("for host: #{hostname.inspect}", event)
publish_data_for(hostname, event['stdout'] + "\n", 'stdout') if event['stdout']
publish_data_for(hostname, event['stdout'] + "\n", 'stdout', id: event['uuid'], timestamp: parse_timestamp(event['created'])) if event['stdout']
case event['event']
when 'runner_on_ok'
publish_exit_status_for(hostname, 0) if @exit_statuses[hostname].nil?
Expand All @@ -156,19 +156,19 @@ def handle_broadcast_data(event)
host = inventory_hosts.find { |host| row =~ /#{host}/ }
line = row + "\n"
unless host
broadcast_data(line, 'stdout')
broadcast_data(line, 'stdout', id: event['uuid'], timestamp: parse_timestamp(event['created']))
next
end

publish_data_for(host, line, 'stdout')
publish_data_for(host, line, 'stdout', id: event['uuid'], timestamp: parse_timestamp(event['created']))

# If the task has been rescued, it won't consider a failure
if @exit_statuses[host].to_i != 0 && failures[host].to_i <= 0 && unreachable[host].to_i <= 0 && rescued[host].to_i > 0
publish_exit_status_for(host, 0)
end
end
else
broadcast_data(event['stdout'] + "\n", 'stdout')
broadcast_data(event['stdout'] + "\n", 'stdout', id: event['uuid'], timestamp: parse_timestamp(event['created']))
end

# If the run ends early due to an error - fail all other tasks
Expand Down Expand Up @@ -383,6 +383,13 @@ def extract_ports(host_data)
host_data["ansible_port"]
].compact.uniq
end

def parse_timestamp(ts)
Time.iso8601(ts)
rescue ArgumentError
logger.warn("Failed to parse '#{ts}' (#{ts.class}) as iso8601 timestamp, defaulting to current timestamp")
Time.now.getlocal
end
end
end
end
2 changes: 1 addition & 1 deletion smart_proxy_ansible.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ Gem::Specification.new do |gem|
gem.required_ruby_version = '>= 3.0'

gem.add_development_dependency 'rake', '~> 13.0'
gem.add_runtime_dependency('smart_proxy_dynflow', '~> 0.8')
gem.add_runtime_dependency('smart_proxy_dynflow', '>= 0.9.4', '< 1.0.0')
gem.add_runtime_dependency('smart_proxy_remote_execution_ssh', '>= 0.5.0', '< 2.0.0')
end