Windows custom fact as a batch file

30 views
Skip to first unread message

comport3

unread,
Jul 11, 2019, 1:30:35 AM7/11/19
to Puppet Users
Is there anything else that is needed to have a custom facter fact as a batch file?

cat lib/facter/ssh_hostkey.bat 
```
@ECHO OFF
for /f "tokens=2" %%a in ('type C:\ProgramData\ssh\ssh_host_ecdsa_key.pub') do (set hostkey=%%a)
Echo ssh_hostkey=%hostkey%
```

Executes fine on the Windows host and returns the expected value, but doesn't show up at all using 'facter -p', 'puppet facts' or 'facter ssh_hostkey'.

What am I missing?

The same command works in PowerShell if that's easier to implement ?
```
get-content C:\ProgramData\ssh\ssh_host_ecdsa_key.pub| ForEach-Object{$_.Split(" ")[1]}
```

Glenn Sarti

unread,
Jul 11, 2019, 1:45:40 AM7/11/19
to Puppet Users
Hi.  What you've listed this is an External Fact (https://puppet.com/docs/puppet/6.2/external_facts.html#executable-facts-on-windows)  So it should be in the directory "facts.d" inside your module.

That directory (lib/facter) is for Custom Facts (https://puppet.com/docs/puppet/6.2/fact_overview.html) which is Ruby code only, not batch or PowerShell.

If you know some ruby, you can convert that batch file into a ruby script.  I wrote a blog which may help.

Dirk Heinrichs

unread,
Jul 11, 2019, 2:01:48 AM7/11/19
to puppet...@googlegroups.com
Am Mittwoch, den 10.07.2019, 22:30 -0700 schrieb comport3:

C:\ProgramData\ssh\ssh_host_ecdsa_key.pub

On Linux, SSH host keys are already contained in facts. Maybe you can extract that code from a Linux agent and adapt it to your needs...

Puppet developers: If you read this, please take it as a change request ;-) If the Microsoft OpenSSH feature is installed (above directory exists and contains host keys), the host keys should appear in facts, just like it is on Linux.

Bye...

Dirk
-- 
Dirk Heinrichs
Senior Systems Engineer, Delivery Pipeline
OpenText ™ Discovery | Recommind
Recommind GmbH, Von-Liebig-Straße 1, 53359 Rheinbach
Vertretungsberechtigte Geschäftsführer Gordon Davies, Madhu Ranganathan, Christian Waida, Registergericht Amtsgericht Bonn, Registernummer HRB 10646
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden
Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail sind nicht gestattet.

Glenn Sarti

unread,
Jul 11, 2019, 2:10:05 AM7/11/19
to Puppet Users

Dirk Heinrichs

unread,
Jul 11, 2019, 2:14:11 AM7/11/19
to puppet...@googlegroups.com
Am Mittwoch, den 10.07.2019, 23:10 -0700 schrieb Glenn Sarti:

Change Request raised - https://tickets.puppetlabs.com/browse/FACT-1934

Great! Thanks a lot.
Reply all
Reply to author
Forward
0 new messages