Issues with foreman_hooks plugin

Problem: When running a deployment from a discovered host using the foreman_hook scripts i receive the below error in the production.local;

ForemanHooks::Error: Hook failure running `/usr/share/foreman/config/hooks/host/managed/after_build/02-dump-hook-variables.sh after_build rhspesxoc01.domain.com`:

Further error information appears in the after_build.log file that gets created.

Script is simple;

> #/bin/bash
> 
> . $(dirname $0)/hook_functions.sh
> 
> # event name (create, before_destroy etc.)
> # orchestration hooks must obey this to support rollbacks (create/update/destroy)
> event=${HOOK_EVENT}
> 
> # to_s representation of the object, e.g. host's fqdn
> object=${HOOK_OBJECT}
> 
> exec >> /tmp/${event}.log
> exec 2>&1
> 
> system_name=$(hook_data host.host.name)
> system_mac=$(hook_data host.host.mac)
> system_pxe_loader=$(hook_data host.host.pxe_loader)
> system_operatingsystem_name=$(hook_data host.host.operatingsystem_name)
> 
> echo "$(date): received ${event} on ${object}"
> echo "${system_name} ${system_mac} ${system_operatingsystem_name} ${system_pxe_loader}"
> 
> echo "system mac: ${system_mac//:/-}"
> echo "system_name: ${system_name}"
> echo "system_pxe_loader: ${system_pxe_loader}"
> echo "system_operatingsystem_name: ${system_operatingsystem_name}"

Expected outcome: Log file is written with the above details.

Foreman and Proxy versions:

Foreman 1.19

foreman_tasks 0.13.2
foreman_ansible 2.2.6
foreman_discovery 13.0.1
foreman_hooks 0.3.14
foreman_remote_execution 1.5.5

Other relevant data:

> /var/lib/gems/2.3.0/gems/jgrep-1.5.0/bin/jgrep:135:in `rescue in <top (required)>': undefined method `status' for n
>         from /var/lib/gems/2.3.0/gems/jgrep-1.5.0/bin/jgrep:99:in `<top (required)>'
>         from /usr/local/bin/jgrep:23:in `load'
>         from /usr/local/bin/jgrep:23:in `<main>'
> /var/lib/gems/2.3.0/gems/jgrep-1.5.0/bin/jgrep:135:in `rescue in <top (required)>': undefined method `status' for n
>         from /var/lib/gems/2.3.0/gems/jgrep-1.5.0/bin/jgrep:99:in `<top (required)>'
>         from /usr/local/bin/jgrep:23:in `load'
>         from /usr/local/bin/jgrep:23:in `<main>'
> /var/lib/gems/2.3.0/gems/jgrep-1.5.0/bin/jgrep:135:in `rescue in <top (required)>': undefined method `status' for n
>         from /var/lib/gems/2.3.0/gems/jgrep-1.5.0/bin/jgrep:99:in `<top (required)>'
>         from /usr/local/bin/jgrep:23:in `load'
>         from /usr/local/bin/jgrep:23:in `<main>'
> /var/lib/gems/2.3.0/gems/jgrep-1.5.0/bin/jgrep:135:in `rescue in <top (required)>': undefined method `status' for n
>         from /var/lib/gems/2.3.0/gems/jgrep-1.5.0/bin/jgrep:99:in `<top (required)>'
>         from /usr/local/bin/jgrep:23:in `load'
>         from /usr/local/bin/jgrep:23:in `<main>'
> Sat Sep 15 18:31:15 AWST 2018: received after_build on rhspesxoc01.domain.com

Downgrading version of jquery to version jgrep (1.3.3) removed the errors listed under “other relevant data”, however the below still remains and the hook does not run.

/usr/share/foreman/config/hooks/host/managed/after_build/02-dump-hook-variables.sh: 23: /usr/share/foreman/config/hooks/host/managed/after_build/02-dump-hook-variables.sh: Bad substitution

Any assistance is greatly appreciated.

I’ve corrected your pastebins a bit, you were using wrong buttons.

Jgrep is a known issue, you need to make sure it does not get upgraded.

The remaining error looks like a bug in your script, I guess you need to debug this. Capture the JSON and then test your script without Foreman.

Thanks lzap, i ended up just giving up on jgrep and ended up using jq in a shell script to parse the JSON which is working great without any errors.

Thanks for your comment.

Feel free to submit examples into foreman_hooks github repo, jgrep has been problematic due to SCL so something more stable would be great.

1 Like

:+1: for using jq in the examples.