#!/usr/bin/perl
# add-puppethost.pl
use Net::LDAP;
use Net::LDAP::Util qw(ldap_error_text ldap_error_name);
# put your ldap info here
my $ldaphost = "";
my $ldapuser = "";
my $passwd = "";
my $base = "";
if ($#ARGV != 2) {
print "Usage: $0 fqdn ipaddress description\n";
exit 1;
}
my $fqdn = $ARGV[0];
my $ip = $ARGV[1];
my $desc = $ARGV[2];
$ldap = Net::LDAP->new ( $ldaphost ) or die "$@";
$mesg = $ldap->bind ( "$ldapuser",
password => "$passwd",
version => 3 );
if ($mesg->code) {
die "An error occurred binding to the LDAP server: "
.ldap_error_text($mesg->code)."\n";
}
$result = $ldap->add("cn=$fqdn,$base",
attr => [ 'cn' => $fqdn,0],
'ipHostNumber' => $ip,
'description' => $desc,
'objectClass' => 'device',
'objectClass' => 'puppetClient',
'objectClass' => 'ipHost'
]
);
if ($result->code) {
die "An error occurred adding the host $fdqn: "
.ldap_error_text($result->code)."\n";
}
$ldap->unbind;