Guest User

Untitled

a guest
Apr 28th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. # add-puppethost.pl
  4.  
  5. use Net::LDAP;
  6. use Net::LDAP::Util qw(ldap_error_text ldap_error_name);
  7.  
  8. # put your ldap info here
  9.  
  10. my $ldaphost = "";
  11. my $ldapuser = "";
  12. my $passwd = "";
  13. my $base = "";
  14.  
  15. if ($#ARGV != 2) {
  16. print "Usage: $0 fqdn ipaddress description\n";
  17. exit 1;
  18. }
  19.  
  20. my $fqdn = $ARGV[0];
  21. my $ip = $ARGV[1];
  22. my $desc = $ARGV[2];
  23.  
  24.  
  25.  
  26. $ldap = Net::LDAP->new ( $ldaphost ) or die "$@";
  27.  
  28. $mesg = $ldap->bind ( "$ldapuser",
  29. password => "$passwd",
  30. version => 3 );
  31.  
  32. if ($mesg->code) {
  33. die "An error occurred binding to the LDAP server: "
  34. .ldap_error_text($mesg->code)."\n";
  35. }
  36.  
  37. $result = $ldap->add("cn=$fqdn,$base",
  38. attr => [ 'cn' => $fqdn,0],
  39. 'ipHostNumber' => $ip,
  40. 'description' => $desc,
  41. 'objectClass' => 'device',
  42. 'objectClass' => 'puppetClient',
  43. 'objectClass' => 'ipHost'
  44. ]
  45. );
  46.  
  47. if ($result->code) {
  48. die "An error occurred adding the host $fdqn: "
  49. .ldap_error_text($result->code)."\n";
  50. }
  51.  
  52.  
  53.  
  54. $ldap->unbind;
Add Comment
Please, Sign In to add comment