# Per instance contexts

**URL:** <https://forum.opennebula.io/t/per-instance-contexts/1108>\
**Category:** Product Support\
**Created:** [August 21, 2015, 8:44am UTC](https://forum.opennebula.io/t/per-instance-contexts/1108 "2015-08-21T08:44:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nux](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/nux/32/4443_2.png) [@Nux](https://forum.opennebula.io/u/Nux)\
**Post date:** [August 21, 2015, 8:44am UTC](https://forum.opennebula.io/t/per-instance-contexts/1108/1 "2015-08-21T08:44:00Z")

</div>

Hello,

I’ve been toying with 4.14b1 for a couple of days now and it looks really nice and simple, but I have one question (for now), how can I contextualize various stuff per instance?

I’d like for example to set a ROOT\_PASSWORD that the VM can use and apply at creation and so on.

Thanks!

---

<div class="post-metadata">

**Author:** ![Samuel](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/samuel/32/4445_2.png) [@Samuel](https://forum.opennebula.io/u/Samuel)\
**Post date:** [August 23, 2015, 4:11am UTC](https://forum.opennebula.io/t/per-instance-contexts/1108/2 "2015-08-23T04:11:41Z")

</div>

Hi,

You’re looking for something like this:

> **[OpenNebula/addon-context-linux](https://github.com/OpenNebula/addon-context-linux)**
>
> Linux VM Contextualization. Contribute to OpenNebula/addon-context-linux development by creating an account on GitHub.

There’s also the opennebula-context package, you might want to install on your OS disks

I haven’t tried any of them, as I am using my own scripts.  
Assuming your template template defines some USERPASS, and maybe some USERNAME (my script sets it to ‘root’ if empty), then you may use something like this:

` . /mnt/context.sh
[...]
    if test "$USERPASS"; then
        echo "$USERNAME:$USERPASS" | chpasswd
    fi
    if test "$SSH_PUBLIC_KEY"; then
        mkdir -p $HOMEDIR/.ssh
        echo "$SSH_PUBLIC_KEY oneadmin@nebula" >>$HOMEDIR/.ssh/authorized_keys
        chown -R $USERNAME:$USERNAME $HOMEDIR/.ssh
        find $HOMEDIR/.ssh -type f -exec chmod 0600 {} \;
        find $HOMEDIR/.ssh -type d -exec chmod 0700 {} \;
        if test "$USERNAME" = root; then
            ssh-keygen -t dsa -N '' -f id_dsa
        else
            su -l $USERNAME -c "ssh-keygen -t dsa -N '' -f id_dsa"
        fi
    fi
`

An other snippet that would help you finding your CONTEXT disk:

[code]try\_disk()  
{  
local isdone  
isdone=false  
test “$1” || return 2  
if mount -t iso9660 /dev/$1 /mnt \>/dev/null 2\>&1; then  
if test -s /mnt/context.sh; then  
$$your\_cloud\_init\_function\_name\_here$$  
isdone=true  
fi  
umount /mnt  
if $isdone; then  
return 0  
fi  
fi

```
return 1

```

}

nebula\_generic\_cloud\_init()  
{  
if test -L /dev/disk/by-label/CONTEXT; then  
try\_disk disk/by-label/CONTEXT  
else  
for dev in `awk '{print $3}' /proc/diskstats`  
do  
echo $dev | grep loop \>/dev/null && continue  
try\_disk $dev && break  
done  
fi  
if test -L /dev/disk/by-label/swap; then  
swapon -L swap  
fi  
}  
[/code]

Then, some ugly way to do it would be do patch your /etc/rc.local with the following:

`if test -e /oneboot; then
    . /usr/lib/nebula/context-init
    nebula_generic_cloud_init
    rm -f /oneboot
fi`

---

<div class="post-metadata">

**Author:** ![Nux](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/nux/32/4443_2.png) [@Nux](https://forum.opennebula.io/u/Nux)\
**Post date:** [August 23, 2015, 8:30am UTC](https://forum.opennebula.io/t/per-instance-contexts/1108/3 "2015-08-23T08:30:15Z")

</div>

Thanks Samuel, what I am after is a way to sey a root password per instance.  
i know the template allows me to set $ROOT\_PASSWORD=XYZ, but I need “XYZ” to be something I am setting per VM/instance, so each machine has its own individual and unique password etc.

I don’t see any feature like the above, at least not in the UI or docs.

Lucian

---

<div class="post-metadata">

**Author:** ![cmartin](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/cmartin/32/4278_2.png) [@cmartin](https://forum.opennebula.io/u/cmartin)\
**Post date:** [August 24, 2015, 8:44am UTC](https://forum.opennebula.io/t/per-instance-contexts/1108/4 "2015-08-24T08:44:11Z")

</div>

Hi,

You can set a different password each time the template is instantiated with the template user inputs:  
[http://docs.opennebula.org/4.12/user/virtual\_resource\_management/vm\_guide.html#ask-for-user-inputs](http://docs.opennebula.org/4.12/user/virtual_resource_management/vm_guide.html#ask-for-user-inputs)

---

<div class="post-metadata">

**Author:** ![Nux](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/nux/32/4443_2.png) [@Nux](https://forum.opennebula.io/u/Nux)\
**Post date:** [August 24, 2015, 1:45pm UTC](https://forum.opennebula.io/t/per-instance-contexts/1108/5 "2015-08-24T13:45:28Z")

</div>

Holy cow, those input+context things can potentially be very powerful, thanks for letting me know.
