Guest User

Untitled

a guest
Apr 28th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. # add-puppetclass.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.  
  16. if ($#ARGV != 1) {
  17. print "Usage: $0 fqdn puppetclass\n";
  18. exit 1;
  19. }
  20.  
  21. my $fqdn = $ARGV[0];
  22. my $class = $ARGV[1];
  23.  
  24.  
  25. $ldap = Net::LDAP->new ( "$ldaphost" ) or die "$@";
  26.  
  27. $mesg = $ldap->bind ( "$ldapuser",
  28. password => "$passwd",
  29. version => 3 );
  30.  
  31. if ($mesg->code) {
  32. die "An error occurred binding to the LDAP server: "
  33. .ldap_error_text($mesg->code)."\n";
  34. }
  35.  
  36.  
  37. $result = $ldap->modify("cn=$fqdn,$base",
  38. add => [ 'puppetclass' => $class
  39. ]
  40. );
  41.  
  42. if ($result->code) {
  43. die "An error occurred adding the class $class to host $fqdn: "
  44. .ldap_error_text($result->code)."\n";
  45. }
  46.  
  47.  
  48.  
  49. $ldap->unbind;
Add Comment
Please, Sign In to add comment