Foreman hooks

Hello,

I'm trying to use hooks with the dedicated foreman plugin.

The shell script located in "
~foreman/config/hooks/parameters/host_parameter/after_create/01_my_script.sh"
and it is working perfectly when I test it with this command :

echo '{"host":{"name":"win-sm5srn3pkc9"}}' | ~foreman/config/hooks/
parameters/host_parameter/create/01_create_client_propertie.sh create win-
sm5srn3pkc9

The new parameter is created and I can verify it on the web interface.

My question is: "How can I configure the hook to be executed when a new
Host is added/created with Puppet?"

I don't understand the meaning about the events (create, update,
after_create, etc.)…

Somebody can help me please?

Best regards

Hi n4rk0o,

> up

Please don't 'up' threads, people respond when they have the time/have a
solution.
>
> >
> > Hello,
> >
> > I'm trying to use hooks with the dedicated foreman plugin.
> >
> > The shell script located in "
> > ~foreman/config/hooks/parameters/host_parameter/after_create/01_my_script.sh"
> > and it is working perfectly when I test it with this command :
> >
> > echo '{"host":{"name":"win-sm5srn3pkc9"}}' | ~foreman/config/hooks/
> > parameters/host_parameter/create/01_create_client_propertie.sh create win-
> > sm5srn3pkc9
> >
> > The new parameter is created and I can verify it on the web interface.
> >
> > My question is: "How can I configure the hook to be executed when a new
> > Host is added/created with Puppet?"
> >
> > I don't understand the meaning about the events (create, update,
> > after_create, etc.)…

The events are standard Rails hooks, you can see a small list here

I think you want to run this script after a host is created after
submitting the facts? In that case, 'after_create' should work. It will
run after the creation of any host, so if you want to restrict it to
Puppet-enabled hosts you'll have to do that in the script.
> >
> > Somebody can help me please?
> >
> > Best regards
> >

Hope that helps,

··· On 05/26, n4rk0o wrote: > Le lundi 25 mai 2015 12:56:31 UTC+2, n4rk0o a écrit : > > -- > You received this message because you are subscribed to the Google Groups "Foreman users" group. > To unsubscribe from this group and stop receiving emails from it, send an email to foreman-users+unsubscribe@googlegroups.com. > To post to this group, send email to foreman-users@googlegroups.com. > Visit this group at http://groups.google.com/group/foreman-users. > For more options, visit https://groups.google.com/d/optout.


Daniel Lobato Garcia

@eLobatoss

GPG: http://keys.gnupg.net/pks/lookup?op=get&search=0x7A92D6DD38D6DE30
Keybase: elobato (Daniel Lobato Garcia) | Keybase

The path should be:
~foreman/config/hooks/host/managed/after_create/01_create_client_propertie.sh

The parameters/host_parameter/ stuff isn't really valid, it should be in
host/managed/ to hook regular host creation.

I don't think that "create" will work when a host is created through a
fact upload, but after_create should.

··· On 25/05/15 10:21, n4rk0o wrote: > Hello, > > I'm trying to use hooks with the dedicated foreman plugin. > > The shell script located in > "*~foreman/config/hooks/parameters/host_parameter/after_create/01_my_script.sh*" > and it is working perfectly when I test it with this command : > > > > echo > '{"host":{"name":"win-sm5srn3pkc9"}}'|~foreman/config/hooks/parameters/host_parameter/create/01_create_client_propertie.sh > create win-sm5srn3pkc9 > > > > The new parameter is created and I can verify it on the web interface. > > My question is: "How can I configure the hook to be executed when a new > Host is added/created with Puppet?"


Dominic Cleal
Red Hat Engineering

Hello,

Following your instructions, I tried to copy the script in
"~foreman/config/hooks/host/managed/after_create/01_create_client_propertie.sh".

After a foreman restart, unfortunately, nothing happened and I have nothing
new in production.log.
I tried to delete the host an add it again but nothing.

I don't know what can I do :confused:

Thank you for your help.

··· Le mercredi 27 mai 2015 13:57:40 UTC+2, Dominic Cleal a écrit : > > On 25/05/15 10:21, n4rk0o wrote: > > Hello, > > > > I'm trying to use hooks with the dedicated foreman plugin. > > > > The shell script located in > > > "*~foreman/config/hooks/parameters/host_parameter/after_create/01_my_script.sh*" > > > and it is working perfectly when I test it with this command : > > > > > > > echo > > > '{"host":{"name":"win-sm5srn3pkc9"}}'|~foreman/config/hooks/parameters/host_parameter/create/01_create_client_propertie.sh > > > create win-sm5srn3pkc9 > > > > > > > The new parameter is created and I can verify it on the web interface. > > > > My question is: "How can I configure the hook to be executed when a new > > Host is added/created with Puppet?" > > The path should be: > ~foreman/config/hooks/host/managed/after_create/01_create_client_propertie.sh > > > The parameters/host_parameter/ stuff isn't really valid, it should be in > host/managed/ to hook regular host creation. > > I don't think that "create" will work when a host is created through a > fact upload, but after_create should. > > -- > Dominic Cleal > Red Hat Engineering >

One more question, I set the log_level to "debug" but I don't see any hooks
find by Foreman. Is it normal?

Just for the record, we sorted this on IRC today. Ensure you restart
httpd or apache2 rather than "foreman" (since that's the standalone
service we don't use in a default install), and that the hook is
executable (chmod +x).

··· On 28/05/15 16:42, n4rk0o wrote: > One more question, I set the log_level to "debug" but I don't see any > hooks find by Foreman. Is it normal?


Dominic Cleal
Red Hat Engineering