How to add a user in VM Template Start Script

TEMPLATES --> VMs --> CONTEXT --> Start Script

How do you add a user in the Context Start Script in OpenNebula 5.4? We are using the CentOS 7 image from the marketplace and putting this in:

echo -e “password” | passwd --stdin root
adduser $UNAME --stdin
#chage -d 0 root
chage -d 0 $UNAME

The password changes but user is never added. We also tried with useradd … we also tried adding root at the end of --stdin …

Please advise.

One thing I noticed is that if I use semi colons to separate each command and put it is as a contiguous line, it works. Like so

echo -e “password” | passwd --stdin root ; adduser $UNAME --stdin ; #chage -d 0 root ; chage -d 0 $UNAME

I use a management software like Chef. Don’t know the circumstances around your environment, but may be a good idea to start looking into something like it, or Ansible.

The command “adduser $UNAME --stdin” is invalid, check manpages of adduser.

There are older threads that explain how to add users with START_SCRIPT Adding users to VM instatiated from linux template

$ cat user.one
CONTEXT = [ USERNAME = root, PASSWORD = password, NETWORK = YES, START_SCRIPT=“useradd -m -s /bin/bash test_user && echo -e \“pass\npass\” | passwd test_user” ]
$ onetemplate update testvm -a user.one
$ onetemplate instantiate testvm
$ onetemplate show testvm

TEMPLATE CONTENTS
CONTEXT=[
NETWORK=“YES”,
PASSWORD=“password”,
START_SCRIPT=“useradd -m -s /bin/bash test_user && echo -e \“pass\npass\” | passwd test_user”,
USERNAME=“root” ]

Hello,

my “Start Script” contains this:
/bin/echo “adminuser:TEST” | chpasswd ; apt-get -y remove xscreesaver ; touch /root/TEST.txt

From that line, chpasswd and touch runs OK, but apt-get no… If I execute first apt-get and, then, chpasswd, only runs OK chpasswd…

Why? why is not apt-get running OK?

Thanks.