0

My code look like this :

    run("""echo "%s:x:" """ % (username))
    if not contains('/etc/passwd', '%s:x:' % (username)):
        run("useradd --shell /bin/bash --create-home %s" % (username), pty=True)

On first run, it works fine and create the user, but on the second run I get an error that the user already exists.

    [root@vbox1] out: tom:x:
    [root@vbox1] run: useradd --shell /bin/bash --create-home tom
    [root@vbox1] out: useradd: user 'tom' already exists

I tried escaping the : with a \, but I get the same results. Is there something obvious that I'm missing?

Dax
  • 369
  • 2
  • 7

1 Answers1

1

Just want to answer my own question for completeness. It is a version problem and is documented with the latest version.

From the docs :

Changed in version 1.0: Swapped the order of the filename and text arguments to be consistent with other functions in this module.

Dax
  • 369
  • 2
  • 7