title: Ruby net-ldap add user
body: <p>I am trying to create a new user using ldap by doing this:</p>
  
  <pre><code>require 'net/ldap'
  
  ldap = Net::LDAP.new
  ldap.host = 'ldap'
  ldap.auth('uid=myuser,ou=users,dc=my,dc=domain,dc=com', 'mypass')
  
  ldap.bind # this executes successfully, up to this point, all is well
  
  dn = 'uid=newuser,ou=users,dc=my,dc=domain,dc=com'
  attributes = { cn: 'newuser', sn: 'surname', objectclass: ['top', 'agent'] }
  
  ldap.add(dn: dn, attributes: attributes)
  
  ldap.get_operation_result
  #=&gt; #&lt;OpenStruct code=21, message="unknown result (21)"&gt;
  </code></pre>
  
  <p>I am new to ldap, and I can't find a place online that provides a clear example of how to use net-ldap to create a new user.</p>