Foreman Discovery Facts

Got a couple of questions around discovery.

First, I extended the image and added new fact. This fact exposes LLDP (so
I can tell where the server is cabled).

If I SSH into the discovery image and run facter I see those facts being
set, so the assumption is the extension worked great.

However through the Discovered Hosts page in Foreman I do not see these
facts under Misc. In addition, after you provision the machine all the
facts are cleared. I was hoping to use these facts in a hook (after_build)
to drive some other logic.

Hoping there is a way I can get access to these uploaded facts such that I
can build logic around them.

Thanks

Lukas:

I was able to find all the facts. I just wanted looking in the right place.

However I have run into another issue, hooks.

According to the following discussion:

https://groups.google.com/forum/#!topic/foreman-users/SJyVhOcnqT4

Discovery plugin should support rails events.

I have created ~config/hooks/host/discovered/after_[create|commit] but they
don't fire. As app/models/host/discovered.rb exists my assumption is that
is the Rails event to trigger on. My hooks are pretty simple to start, just
touch a file so I can verify they run.

··· On Friday, May 20, 2016 at 1:31:28 PM UTC-7, Matthew Ceroni wrote: > > Got a couple of questions around discovery. > > First, I extended the image and added new fact. This fact exposes LLDP (so > I can tell where the server is cabled). > > If I SSH into the discovery image and run facter I see those facts being > set, so the assumption is the extension worked great. > > However through the Discovered Hosts page in Foreman I do not see these > facts under Misc. In addition, after you provision the machine all the > facts are cleared. I was hoping to use these facts in a hook (after_build) > to drive some other logic. > > Hoping there is a way I can get access to these uploaded facts such that I > can build logic around them. > > Thanks >

Hello,

> If I SSH into the discovery image and run facter I see those facts being
> set, so the assumption is the extension worked great.

which file have you put the facter extension in?

> However through the Discovered Hosts page in Foreman I do not see these
> facts under Misc. In addition, after you provision the machine all the
> facts are cleared. I was hoping to use these facts in a hook (after_build)
> to drive some other logic.

Do you see the fact when you restart foreman-proxy service on the
running node and then click on Refresh Facts?

If so, looks like a bug - foreman-proxy must be started after all
extensions were executed. Please confirm it here then and I can fix this
for you:

http://projects.theforeman.org/issues/15139

Workaround: Restart proxy service manually in your extension after you
drop the facter source file.

> Hoping there is a way I can get access to these uploaded facts such that I
> can build logic around them.

Regarding to deletion of facts, all facts which starts with "discovery_"
survives provisioning and are kept, until the initial fact upload (from
provisioned system). So these can be used in templates etc. Just rename
the fact and you should be fine.

··· -- Later, Lukas #lzap Zapletal

> I was able to find all the facts. I just wanted looking in the right place.

How have you solved it? Can you reply to my previous mail please?

> I have created ~config/hooks/host/discovered/after_[create|commit] but they

The correct path is

hooks/discovered_host/after_xyz

LZ

··· -- Later, Lukas #lzap Zapletal

>
> > I was able to find all the facts. I just wanted looking in the right
> place.
>
> How have you solved it? Can you reply to my previous mail please?
>

I was looking for the facts on the detail page. But I ended up finding them
all through the discovery API /api/v2/discovery/:host_id. That just lists
all the facts and the ones I was interested in were there.

However once I go to provision I don't see any facts associated with that
host. So the discovered_ are not present. (API call to
/api/v2/hosts/:host_id/facts returns 0 facts).

>
> > I have created ~config/hooks/host/discovered/after_[create|commit] but
> they
>
> The correct path is
>
> hooks/discovered_host/after_xyz
>

I created the following files (after_create and after_commit) in the
location you listed above but they don't fire. I am assuming they should
fire when discovery completes and uploads all info to Foreman (thus the
host shows up under discovered hosts).

··· On Tuesday, May 24, 2016 at 5:18:15 AM UTC-7, Lukas Zapletal wrote:

LZ


Later,
Lukas #lzap Zapletal

> I created the following files (after_create and after_commit) in the
> location you listed above but they don't fire. I am assuming they should
> fire when discovery completes and uploads all info to Foreman (thus the
> host shows up under discovered hosts).

Check permissions and SELinux. Also, check if you have the latest
foreman-bootdisk plugin it is quite new hook.

··· -- Later, Lukas #lzap Zapletal

Still nothing.

SELinux is set to permissive (other hooks work so I don't think SELinux
would be an issue here).

In addition I didn't have the bootdisk plugin installed. I am assuming you
meant to say discovery plugin. Either way I installed the latest (for 1.11)
bootdisk plugin. I also ensured that for 1.11 I have the latest
foremn_discovery plugin, which is 5.0.2.

Thanks

··· On Thursday, May 26, 2016 at 2:02:07 AM UTC-7, Lukas Zapletal wrote: > > > I created the following files (after_create and after_commit) in the > > location you listed above but they don't fire. I am assuming they should > > fire when discovery completes and uploads all info to Foreman (thus the > > host shows up under discovered hosts). > > Check permissions and SELinux. Also, check if you have the latest > foreman-bootdisk plugin it is quite new hook. > > -- > Later, > Lukas #lzap Zapletal >