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?