Puppet Exec fails executing useradd

puppet

From what I understand, puppetd runs as root. As root, I launch

 puppetd --onetime --no-daemonize --verbose

So I don't understand why this doesn't work:

exec { "useradd -m testuser":
       path => "/bin:/usr/bin",
     }

I just get:

...Exec[useradd -m testuser]/returns: change from notrun to 0 failed:useradd -m testuser returned 1 instead of one of [0] at...

If I execute the command directly, it works just fine.

Any ideas?

PS: exec { "touch /root/a.test":} is successful, so it is indeed executing as root.

PS2: I get the exact same problem when executing "apt-get autoremove"

Best Answer

Well in most systems useradd will be in one of the sbin folders rather than /bin or /usr/bin. your path should be "/bin:/usr/bin:/sbin:/usr/sbin",. though this solution is rather horible i would use the user type rather than an exec it will give you much better management of users on a host (checks on pw and existance requires etc)

@user {
  "testuser":
    uid => ,
    gid =>,
    password => #hash of password,
    home => ,
    groups => ,
}

this is a virtual resource and can be added to your host by realize ( User[testuser]) allowing it to be referenced multiple times

it's a nice simple solution

Related Topic