[Freeipa-users] IPA command to batch create users.

Rob Crittenden rcritten at redhat.com
Thu Mar 24 20:00:17 UTC 2016


Natxo Asenjo wrote:
>
> hi,
>
> On Thu, Mar 24, 2016 at 8:14 PM, Armstrong, Jeffrey
> <jeffrey.armstrong at gasoc.com <mailto:jeffrey.armstrong at gasoc.com>> wrote:
>
>     Hello,____
>
>     __ __
>
>     I would like to find out if I can create a large number of users in
>     IPA at one time.  If so, what is the command to do that.____
>
>
> you can use ipa user-add command in a bash loop, or read the user names
> from a file, feeding that file to ipa user-add.

There is also a batch command which is used by the UI to send multiple 
commands at once. This saves on some roundtrip time.

Here is some semi-python, grossly simplified

batch = []
for line in 'output_from_etc_passwd':
     (login, passwd, uid, gid, gecos, dir, shell) = line.split(':')
     batch.append(dict(method='user_add',
                       params=([login], dict(gidnumber=int(gid),
                                 uidnumber=int(uid),
                                 gecos=gecos.strip(), homedir=dir, 
shell=shell,
                                 givenname=first, sn=last, 
noprivate=u'true',
                                 addattr='userPassword={crypt}%s' % 
passwd))))

results = api.Command['batch'](batch)['results']

You probably don't want too many requests at once, say 50 or 100 might 
be nice.

The results will be a list of all the outputs from the various commands.

rob




More information about the Freeipa-users mailing list