Bug #10625
open
host.ip not available in after_destroy or destroy in foreman_hooks
Added by El Joppa over 9 years ago.
Updated over 6 years ago.
Description
Cant get host.ip for host in after_destroy or destroy and looks like DNS is done before both so i cant lookup the DNS locally either
- Category set to Orchestration
Regarding the destroy orchestration action, whether the DNS has been removed already will depend on the priority of your hook. DNS is removed with a priority of 1, so you'd probably have to call the hook "0_foo".
root@foreman01:/usr/share/foreman/config/hooks/host/managed# find . -name '0_log.sh'
./after_destroy/0_log.sh
./destroy/0_log.sh
content of 0_log.sh:
#!/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}
# Example of using hook_data to query the JSON representation of the object
# passed by foreman_hooks. `cat $HOOK_OBJECT_FILE` to see the contents.
hostname=$(hook_data host.name)
ip=$(hook_data host.ip)
hostname2='www.redhat.com'
ipdns=`dig +short $hostname @foremandns`
ipdns2=`dig +short $hostname2 @8.8.8.8`
echo "$(date): received ${event} on ${object} on them hostname $hostname and ip $ip and ipdns $ipdns and ipdns2 $ipdns2" >> /tmp/hook.log
# exit code is important on orchestration tasks
exit 0
After deleting host the content of /tmp/hook.log shows:
Wed Mar 2 10:53:18 CET 2016: received after_destroy on tezt-hezt8.X.no on them hostname tezt-hezt8.X.no and ip and ipdns and ipdns2 ds-www.redhat.com.edgekey.net.
ds-www.redhat.com.edgekey.net.globalredir.akadns.net.
e3396.dscx.akamaiedge.net.
23.53.35.183
Wed Mar 2 10:53:22 CET 2016: received destroy on tezt-hezt8.X.no on them hostname tezt-hezt8.X.no and ip and ipdns and ipdns2 ds-www.redhat.com.edgekey.net.
ds-www.redhat.com.edgekey.net.globalredir.akadns.net.
e3396.dscx.akamaiedge.net.
23.53.35.183
Looks like dns records are deleted before 0_ ?
Also available in: Atom
PDF