Skip to content

Commit

Permalink
(puppetlabs#732) puppet_agent::run: mark failed puppet runs as failed…
Browse files Browse the repository at this point in the history
… task

without this change:

```
Started on localhost...
Finished on localhost:
  Info: Refreshing CA certificate
  Info: CA certificate is unmodified, using existing CA certificate
  Info: Using environment 'production'
  Info: Retrieving pluginfacts
  Info: Retrieving plugin
  Info: Loading facts
  Notice: Requesting catalog from puppet.bastel:8140 (127.0.0.1)
  Notice: Catalog compiled by puppet.local
  Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Failed when searching for node puppet.bastel: Exception while executing '/etc/puppetlabs/puppet/node.rb': Cannot run program "/etc/puppetlabs/puppet/node.rb" (in directory "."): error=0, Failed to exec spawn helper: pid: 2133925, exit value: 1
  Warning: Not using cache on failed catalog
  Error: Could not retrieve catalog; skipping run
  {
 *long json*
    },
    "exitcode": 1
  }
Successful on 1 target: localhost
Ran on 1 target in 11.19 sec
```

With this change:

```
Started on localhost...
Failed on localhost:
  Puppet agent run failed: Info: Refreshing CA certificate
  Info: CA certificate is unmodified, using existing CA certificate
  Info: Using environment 'production'
  Info: Retrieving pluginfacts
  Info: Retrieving plugin
  Info: Loading facts
  Notice: Requesting catalog from puppet.bastel:8140 (127.0.0.1)
  Notice: Catalog compiled by puppet.local
  Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Failed when searching for node puppet.bastel: Exception while executing '/etc/puppetlabs/puppet/node.rb': Cannot run program "/etc/puppetlabs/puppet/node.rb" (in directory "."): error=0, Failed to exec spawn helper: pid: 2133837, exit value: 1
  Warning: Not using cache on failed catalog
  Error: Could not retrieve catalog; skipping run
Failed on 1 target: localhost
Ran on 1 target in 11.35 sec
```

The task is now properly marked as failed, when the puppet agent run
failed itself.
  • Loading branch information
bastelfreak committed Nov 21, 2024
1 parent b233bcd commit 079d3c2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tasks/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ def get_result_from_report(last_run_report, run_result, start_time)
obj.tag = nil if obj.respond_to?(:tag=)
end

# check if the run is marked as failed
if report.to_ruby['status'] == 'failed'
return error_result(
'puppet_agent/agent-run-error',
"Puppet agent run failed: #{run_result}",
)
end
{
'report' => report.to_ruby,
'exitcode' => run_result.exitstatus,
Expand Down

0 comments on commit 079d3c2

Please sign in to comment.