Ask Your Question

Revision history [back]

Hi, maybe it's a little bit late but recently i struggled with the same problem
I wanted to have a structured external custom fact , that enumerates my samba shares
I want to provide a fully documented example and hopefully someone will find it useful
Foresightly, i want to mention , that the documented standard paths for custom facts are wrong
I ended up outputting the structed data to directory: /opt/puppetlabs/facter/facts.d/
OS: Debian or Ubuntu (any os which provides these perl libs will work !!)
Packages you'll need:
libconfig-std-perl
libjson-perl
Puppet: Puppet PE 2016.1.2

The simple script:

#!/usr/bin/perl

use warnings;
use strict;

use Config::Std;
use Data::Dumper;
use JSON;
my $config = {};
my $coder = JSON->new;
my $retval = {};
my $outfile = '/opt/puppetlabs/facter/facts.d/samba_share.json';

read_config '/etc/samba/smb.conf' =>  %{$config};


foreach my $key (keys %{$config}) {
        if ($key !~ /^global/i ) {
                $retval->{samba_share}->{$key} = $config->{$key};
        }
}

my $json = $coder->canonical->pretty->encode($retval);
open(FILE, ">$outfile") or die "Cannot open file $outfile";
printf (FILE "%s",$json);
close (FILE);

Create a cronjob on the node (10m), dontt knox how to get the facter TTL, so 10m should be sufficient

Local node:
Command: facter samba_share
Output:

{
  example-share => {
    browsable => "yes",
    comment => "Example Share",
    force group => "citycom",
    force user => "citycom",
    guest ok => "no",
    guest only => "no",
    inherit permissions => "yes",
    path => "/var/shares/test",
    read only => "no",
    writable => "yes"
  },
  homes => {
    browseable => "no",
    comment => "Home Directories",
    create mask => "0700",
    directory mask => "0700",
    read only => "yes",
    valid users => "%S"
  },
  print$ => {
    browseable => "yes",
    comment => "Printer Drivers",
    guest ok => "no",
    path => "/var/lib/samba/printers",
    read only => "yes"
  },
  printers => {
    browseable => "no",
    comment => "All Printers",
    create mask => "0700",
    guest ok => "no",
    path => "/var/spool/samba",
    printable => "yes",
    read only => "yes"
  }
}

Via MCO (using username peadmin and the mco binary !!!):
Command: mco rpc rpcutil -j -I [certname] getfact fact=sambashare
Output:

[
  {
    "agent": "rpcutil",
    "action": "get_fact",
    "sender": "testnode.example.com",
    "statuscode": 0,
    "statusmsg": "OK",
    "data": {
      "fact": "samba_share",
      "value": {
        "example-share": {
          "browsable": "yes",
          "comment": "Example Share",
          "force group": "test",
          "force user": "test",
          "guest ok": "no",
          "guest only": "no",
          "inherit permissions": "yes",
          "path": "/var/shares/test",
          "read only": "no",
          "writable": "yes"
        },
        "homes": {
          "browseable": "no",
          "comment": "Home Directories",
          "create mask": "0700",
          "directory mask": "0700",
          "read only": "yes",
          "valid users": "%S"
        },
        "print$": {
          "browseable": "yes",
          "comment": "Printer Drivers",
          "guest ok": "no",
          "path": "/var/lib/samba/printers",
          "read only": "yes"
        },
        "printers": {
          "browseable": "no",
          "comment": "All Printers",
          "create mask": "0700",
          "guest ok": "no",
          "path": "/var/spool/samba",
          "printable": "yes",
          "read only": "yes"
        }
      }
    }
  }

Conclusion, you don't have to use ruby to get structural data into facter.
It's a great feature though !!!
Hope anyone will find it useful.

Rgds. Franz

Hi, maybe it's a little bit late but recently i struggled with the same problem
I wanted to have a structured external custom fact , that enumerates my samba shares
I want to provide a fully documented example and hopefully someone will find it useful
Foresightly, i want to mention , that the documented standard paths for custom facts are wrong
I ended up outputting the structed data to directory: /opt/puppetlabs/facter/facts.d/
OS: Debian or Ubuntu (any os which provides these perl libs will work !!)
Packages you'll need:
libconfig-std-perl
libjson-perl
Puppet: Puppet PE 2016.1.2

The simple script:

#!/usr/bin/perl

use warnings;
use strict;

use Config::Std;
use Data::Dumper;
use JSON;
my $config = {};
my $coder = JSON->new;
my $retval = {};
my $outfile = '/opt/puppetlabs/facter/facts.d/samba_share.json';

read_config '/etc/samba/smb.conf' =>  %{$config};


foreach my $key (keys %{$config}) {
        if ($key !~ /^global/i ) {
                $retval->{samba_share}->{$key} = $config->{$key};
        }
}

my $json = $coder->canonical->pretty->encode($retval);
open(FILE, ">$outfile") or die "Cannot open file $outfile";
printf (FILE "%s",$json);
close (FILE);

Create a cronjob on the node (10m), dontt knox how to get the facter TTL, so 10m should be sufficient

Local node:
Command: facter samba_share
Output:

{
  example-share => {
    browsable => "yes",
    comment => "Example Share",
    force group => "citycom",
test",
    force user => "citycom",
"test",
    guest ok => "no",
    guest only => "no",
    inherit permissions => "yes",
    path => "/var/shares/test",
    read only => "no",
    writable => "yes"
  },
  homes => {
    browseable => "no",
    comment => "Home Directories",
    create mask => "0700",
    directory mask => "0700",
    read only => "yes",
    valid users => "%S"
  },
  print$ => {
    browseable => "yes",
    comment => "Printer Drivers",
    guest ok => "no",
    path => "/var/lib/samba/printers",
    read only => "yes"
  },
  printers => {
    browseable => "no",
    comment => "All Printers",
    create mask => "0700",
    guest ok => "no",
    path => "/var/spool/samba",
    printable => "yes",
    read only => "yes"
  }
}

Via MCO (using username peadmin and the mco binary !!!):
Command: mco rpc rpcutil -j -I [certname] getfact fact=sambashare
Output:

[
  {
    "agent": "rpcutil",
    "action": "get_fact",
    "sender": "testnode.example.com",
    "statuscode": 0,
    "statusmsg": "OK",
    "data": {
      "fact": "samba_share",
      "value": {
        "example-share": {
          "browsable": "yes",
          "comment": "Example Share",
          "force group": "test",
          "force user": "test",
          "guest ok": "no",
          "guest only": "no",
          "inherit permissions": "yes",
          "path": "/var/shares/test",
          "read only": "no",
          "writable": "yes"
        },
        "homes": {
          "browseable": "no",
          "comment": "Home Directories",
          "create mask": "0700",
          "directory mask": "0700",
          "read only": "yes",
          "valid users": "%S"
        },
        "print$": {
          "browseable": "yes",
          "comment": "Printer Drivers",
          "guest ok": "no",
          "path": "/var/lib/samba/printers",
          "read only": "yes"
        },
        "printers": {
          "browseable": "no",
          "comment": "All Printers",
          "create mask": "0700",
          "guest ok": "no",
          "path": "/var/spool/samba",
          "printable": "yes",
          "read only": "yes"
        }
      }
    }
  }

Conclusion, you don't have to use ruby to get structural data into facter.
It's a great feature though !!!
Hope anyone will find it useful.

Rgds. Franz

Hi, maybe it's a little bit late but recently i struggled with the same problem
I wanted to have a structured external custom fact , that enumerates my samba shares
I want to provide a fully documented example and hopefully someone will find it useful
Foresightly, i want to mention , that the documented standard paths for custom facts are wrong
I ended up outputting the structed data to directory: /opt/puppetlabs/facter/facts.d/
OS: Debian or Ubuntu (any os which provides these perl libs will work !!)
Packages you'll need:
libconfig-std-perl
libjson-perl
Puppet: Puppet PE 2016.1.2

The simple script:

#!/usr/bin/perl

use warnings;
use strict;

use Config::Std;
use Data::Dumper;
use JSON;
my $config = {};
my $coder = JSON->new;
my $retval = {};
my $outfile = '/opt/puppetlabs/facter/facts.d/samba_share.json';

read_config '/etc/samba/smb.conf' =>  %{$config};


foreach my $key (keys %{$config}) {
        if ($key !~ /^global/i ) {
                $retval->{samba_share}->{$key} = $config->{$key};
        }
}

my $json = $coder->canonical->pretty->encode($retval);
open(FILE, ">$outfile") or die "Cannot open file $outfile";
printf (FILE "%s",$json);
close (FILE);

Create a cronjob on the node (10m), dontt knox how to get the facter TTL, so 10m should be sufficient

Local node:
Command: facter samba_share
Output:

{
  example-share => {
    browsable => "yes",
    comment => "Example Share",
    force group => test",
    force user => "test",
    guest ok => "no",
    guest only => "no",
    inherit permissions => "yes",
    path => "/var/shares/test",
    read only => "no",
    writable => "yes"
  },
  homes => {
    browseable => "no",
    comment => "Home Directories",
    create mask => "0700",
    directory mask => "0700",
    read only => "yes",
    valid users => "%S"
  },
  print$ => {
    browseable => "yes",
    comment => "Printer Drivers",
    guest ok => "no",
    path => "/var/lib/samba/printers",
    read only => "yes"
  },
  printers => {
    browseable => "no",
    comment => "All Printers",
    create mask => "0700",
    guest ok => "no",
    path => "/var/spool/samba",
    printable => "yes",
    read only => "yes"
  }
}

Via MCO (using username peadmin and the mco binary !!!):
Command: mco rpc rpcutil -j -I [certname] getfact fact=sambashare
Output:

[
  {
    "agent": "rpcutil",
    "action": "get_fact",
    "sender": "testnode.example.com",
    "statuscode": 0,
    "statusmsg": "OK",
    "data": {
      "fact": "samba_share",
      "value": {
        "example-share": {
          "browsable": "yes",
          "comment": "Example Share",
          "force group": "test",
          "force user": "test",
          "guest ok": "no",
          "guest only": "no",
          "inherit permissions": "yes",
          "path": "/var/shares/test",
          "read only": "no",
          "writable": "yes"
        },
        "homes": {
          "browseable": "no",
          "comment": "Home Directories",
          "create mask": "0700",
          "directory mask": "0700",
          "read only": "yes",
          "valid users": "%S"
        },
        "print$": {
          "browseable": "yes",
          "comment": "Printer Drivers",
          "guest ok": "no",
          "path": "/var/lib/samba/printers",
          "read only": "yes"
        },
        "printers": {
          "browseable": "no",
          "comment": "All Printers",
          "create mask": "0700",
          "guest ok": "no",
          "path": "/var/spool/samba",
          "printable": "yes",
          "read only": "yes"
        }
      }
    }
  }

] Conclusion, you don't have to use ruby to get structural data into facter.
It's a great feature though !!!
Hope anyone will find it useful.

Rgds. Franz

Hi, maybe it's a little bit late but recently i struggled with the same problem
I wanted to have a structured external custom fact , that enumerates my samba shares
I want to provide a fully documented example and hopefully someone will find it useful
Foresightly, i want to mention , that the documented standard paths for custom facts are wrong
I ended up outputting the structed data to directory: /opt/puppetlabs/facter/facts.d/
OS: Debian or Ubuntu (any os which provides these perl libs will work !!)
Packages you'll need:
libconfig-std-perl
libjson-perl
Puppet: Puppet PE 2016.1.2

The simple script:

#!/usr/bin/perl

use warnings;
use strict;

use Config::Std;
use Data::Dumper;
use JSON;
my $config = {};
my $coder = JSON->new;
my $retval = {};
my $outfile = '/opt/puppetlabs/facter/facts.d/samba_share.json';

read_config '/etc/samba/smb.conf' =>  %{$config};


foreach my $key (keys %{$config}) {
        if ($key !~ /^global/i ) {
                $retval->{samba_share}->{$key} = $config->{$key};
        }
}

my $json = $coder->canonical->pretty->encode($retval);
open(FILE, ">$outfile") or die "Cannot open file $outfile";
printf (FILE "%s",$json);
close (FILE);

Create a cronjob on the node (10m), dontt knox how to get the facter TTL, so 10m should be sufficient

Local node:
Command: facter samba_share
Output:

{
  example-share => {
    browsable => "yes",
    comment => "Example Share",
    force group => test",
    force user => "test",
    guest ok => "no",
    guest only => "no",
    inherit permissions => "yes",
    path => "/var/shares/test",
    read only => "no",
    writable => "yes"
  },
  homes => {
    browseable => "no",
    comment => "Home Directories",
    create mask => "0700",
    directory mask => "0700",
    read only => "yes",
    valid users => "%S"
  },
  print$ => {
    browseable => "yes",
    comment => "Printer Drivers",
    guest ok => "no",
    path => "/var/lib/samba/printers",
    read only => "yes"
  },
  printers => {
    browseable => "no",
    comment => "All Printers",
    create mask => "0700",
    guest ok => "no",
    path => "/var/spool/samba",
    printable => "yes",
    read only => "yes"
  }
}

Via MCO (using username peadmin and the mco binary !!!):
Command: mco rpc rpcutil -j -I [certname] getfact fact=sambashareget_fact fact=samba_share
Output:

[
  {
    "agent": "rpcutil",
    "action": "get_fact",
    "sender": "testnode.example.com",
    "statuscode": 0,
    "statusmsg": "OK",
    "data": {
      "fact": "samba_share",
      "value": {
        "example-share": {
          "browsable": "yes",
          "comment": "Example Share",
          "force group": "test",
          "force user": "test",
          "guest ok": "no",
          "guest only": "no",
          "inherit permissions": "yes",
          "path": "/var/shares/test",
          "read only": "no",
          "writable": "yes"
        },
        "homes": {
          "browseable": "no",
          "comment": "Home Directories",
          "create mask": "0700",
          "directory mask": "0700",
          "read only": "yes",
          "valid users": "%S"
        },
        "print$": {
          "browseable": "yes",
          "comment": "Printer Drivers",
          "guest ok": "no",
          "path": "/var/lib/samba/printers",
          "read only": "yes"
        },
        "printers": {
          "browseable": "no",
          "comment": "All Printers",
          "create mask": "0700",
          "guest ok": "no",
          "path": "/var/spool/samba",
          "printable": "yes",
          "read only": "yes"
        }
      }
    }
  }

] Conclusion, you don't have to use ruby to get structural data into facter.
It's a great feature though !!!
Hope anyone will find it useful.

Rgds. Franz

Hi, maybe it's a little bit late but recently i struggled with the same problem
I wanted to have a structured external custom fact , that enumerates my samba shares
I want to provide a fully documented example and hopefully someone will find it useful
Foresightly, i want to mention , that the documented standard paths for custom facts are wrong
I ended up outputting the structed data to directory: /opt/puppetlabs/facter/facts.d/
OS: Debian or Ubuntu (any os which provides these perl libs will work !!)
Packages you'll need:
libconfig-std-perl
libjson-perl
Puppet: Puppet PE 2016.1.2

The simple script:

#!/usr/bin/perl

use warnings;
use strict;

use Config::Std;
use Data::Dumper;
use JSON;
my $config = {};
my $coder = JSON->new;
my $retval = {};
my $outfile = '/opt/puppetlabs/facter/facts.d/samba_share.json';

read_config '/etc/samba/smb.conf' =>  %{$config};


foreach my $key (keys %{$config}) {
        if ($key !~ /^global/i ) {
                $retval->{samba_share}->{$key} = $config->{$key};
        }
}

my $json = $coder->canonical->pretty->encode($retval);
open(FILE, ">$outfile") or die "Cannot open file $outfile";
printf (FILE "%s",$json);
close (FILE);

Create a cronjob on the node (10m), dontt knox how to get the facter TTL, so 10m should be sufficient

Local node:
Command: facter samba_share
Output:

{
  example-share => {
    browsable => "yes",
    comment => "Example Share",
    force group => test",
    force user => "test",
    guest ok => "no",
    guest only => "no",
    inherit permissions => "yes",
    path => "/var/shares/test",
    read only => "no",
    writable => "yes"
  },
  homes => {
    browseable => "no",
    comment => "Home Directories",
    create mask => "0700",
    directory mask => "0700",
    read only => "yes",
    valid users => "%S"
  },
  print$ => {
    browseable => "yes",
    comment => "Printer Drivers",
    guest ok => "no",
    path => "/var/lib/samba/printers",
    read only => "yes"
  },
  printers => {
    browseable => "no",
    comment => "All Printers",
    create mask => "0700",
    guest ok => "no",
    path => "/var/spool/samba",
    printable => "yes",
    read only => "yes"
  }
}

Via MCO (using username peadmin and the mco binary !!!):
Command: mco rpc rpcutil -j -I [certname] get_fact fact=samba_share
Output:

 [
   {
     "agent": "rpcutil",
     "action": "get_fact",
     "sender": "testnode.example.com",
     "statuscode": 0,
     "statusmsg": "OK",
     "data": {
       "fact": "samba_share",
       "value": {
         "example-share": {
           "browsable": "yes",
           "comment": "Example Share",
           "force group": "test",
           "force user": "test",
           "guest ok": "no",
           "guest only": "no",
           "inherit permissions": "yes",
           "path": "/var/shares/test",
           "read only": "no",
           "writable": "yes"
         },
         "homes": {
           "browseable": "no",
           "comment": "Home Directories",
           "create mask": "0700",
           "directory mask": "0700",
           "read only": "yes",
           "valid users": "%S"
         },
         "print$": {
           "browseable": "yes",
           "comment": "Printer Drivers",
           "guest ok": "no",
           "path": "/var/lib/samba/printers",
           "read only": "yes"
         },
         "printers": {
           "browseable": "no",
           "comment": "All Printers",
           "create mask": "0700",
           "guest ok": "no",
           "path": "/var/spool/samba",
           "printable": "yes",
           "read only": "yes"
         }
       }
     }
   }
]

] Conclusion, you don't have to use ruby to get structural data into facter.
It's a great feature though !!!
Hope anyone will find it useful.

Rgds. Franz

Hi, maybe it's a little bit late but recently i struggled with the same problem
I wanted to have a structured external custom fact , that enumerates my samba shares
I want to provide a fully documented example and hopefully someone will find it useful
Foresightly, i want to mention , that the documented standard paths for custom facts are wrong
I ended up outputting the structed data to directory: /opt/puppetlabs/facter/facts.d/
OS: Debian or Ubuntu (any os which provides these perl libs will work !!)
Packages you'll need:
libconfig-std-perl
libjson-perl
Puppet: Puppet PE 2016.1.2

The simple script:
Update !!! ("Include" also honored)

#!/usr/bin/perl

use warnings;
use strict;

use Config::Std;
use Data::Dumper;
use JSON;
my $config  = {};
my $include = {};
my $coder  = JSON->new;
my $retval  = {};
my $outfile = '/opt/puppetlabs/facter/facts.d/samba_share.json';

my $retconfig = eval { read_config '/etc/samba/smb.conf' =>  %{$config};

%{$config} };

foreach my $key (keys %{$config}) {
    ( keys %{$config} ) {
    if ($key ( $key !~ /^global/i ) {
         $retval->{samba_share}->{$key} = $config->{$key};
    }
    if ( $key =~ /^global/i ) {
        if ( ref $config->{$key} eq 'HASH' ) {
            foreach my $global ( keys %{ $config->{$key} } ) {
                if ( $global eq 'include' ) {
                    my $retinc = eval {
                        read_config qq{$config->{$key}->{$global}} =>
                          %{$include};
                    };
                }
                foreach my $incshare ( keys %{$include} ) {
                    $retval->{samba_share}->{$incshare} = $include->{$incshare};
                }
            }
        }
    }
}

my $json = $coder->canonical->pretty->encode($retval);
open(FILE, ">$outfile") open( FILE, ">$outfile" ) or die "Cannot open file $outfile";
printf (FILE "%s",$json);
close (FILE);
printf( FILE "%s", $json );
close(FILE);

Create a cronjob on the node (10m), dontt knox how to get the facter TTL, so 10m should be sufficient

Local node:
Command: facter samba_share
Output:

{
  example-share => {
    browsable => "yes",
    comment => "Example Share",
    force group => test",
    force user => "test",
    guest ok => "no",
    guest only => "no",
    inherit permissions => "yes",
    path => "/var/shares/test",
    read only => "no",
    writable => "yes"
  },
  homes => {
    browseable => "no",
    comment => "Home Directories",
    create mask => "0700",
    directory mask => "0700",
    read only => "yes",
    valid users => "%S"
  },
  print$ => {
    browseable => "yes",
    comment => "Printer Drivers",
    guest ok => "no",
    path => "/var/lib/samba/printers",
    read only => "yes"
  },
  printers => {
    browseable => "no",
    comment => "All Printers",
    create mask => "0700",
    guest ok => "no",
    path => "/var/spool/samba",
    printable => "yes",
    read only => "yes"
  }
}

Via MCO (using username peadmin and the mco binary !!!):
Command: mco rpc rpcutil -j -I [certname] get_fact fact=samba_share
Output:

    [
      {
        "agent": "rpcutil",
        "action": "get_fact",
        "sender": "testnode.example.com",
        "statuscode": 0,
        "statusmsg": "OK",
        "data": {
          "fact": "samba_share",
          "value": {
            "example-share": {
              "browsable": "yes",
              "comment": "Example Share",
              "force group": "test",
              "force user": "test",
              "guest ok": "no",
              "guest only": "no",
              "inherit permissions": "yes",
              "path": "/var/shares/test",
              "read only": "no",
              "writable": "yes"
            },
            "homes": {
              "browseable": "no",
              "comment": "Home Directories",
              "create mask": "0700",
              "directory mask": "0700",
              "read only": "yes",
              "valid users": "%S"
            },
            "print$": {
              "browseable": "yes",
              "comment": "Printer Drivers",
              "guest ok": "no",
              "path": "/var/lib/samba/printers",
              "read only": "yes"
            },
            "printers": {
              "browseable": "no",
              "comment": "All Printers",
              "create mask": "0700",
              "guest ok": "no",
              "path": "/var/spool/samba",
              "printable": "yes",
              "read only": "yes"
            }
          }
        }
      }
]

Conclusion, you don't have to use ruby to get structural data into facter.
It's a great feature though !!!
Hope anyone will find it useful.

Rgds. Franz