[one-users] Reference CONTEXT variables within CONTEXT
Valentin Bud
valentin.bud at gmail.com
Thu May 16 05:14:26 PDT 2013
Hello Community,
First of all, I apologise I forgot to say hi in my previous E-Mail :|.
On Thu, May 16, 2013 at 10:28:14AM +0300, Valentin Bud wrote:
> I am trying to reference the CONTEXT variables from within CONTEXT.
>
> For example, I define the DOMAIN="domain.tld" and the HOSTNAME="host".
> I would like to have a variable FQDN="$HOST.$DOMAIN.".
>
> I have tried to achieve the above using the following in CONTEXT section
> of the template.
>
> Case I
> --
>
> $ onetemplate show vars
>
> TEMPLATE CONTENTS
> CONTEXT=[
> DOMAIN="domain.tld",
> FQDN="$DOMAIN.$HOSTNAME.",
> HOSTNAME="host" ]
>
> [... output omitted for brevity ...]
>
> Instantiating the template results in the following variables added to
> the VM.
>
> $ onevm show vars
>
> VIRTUAL MACHINE TEMPLATE
> CONTEXT=[
> DISK_ID="1",
> DOMAIN="domain.tld",
> *FQDN="..",*
> HOSTNAME="host",
> TARGET="hda" ]
>
> Case II
> --
>
> $ onetemplate show vars
>
> CONTEXT=[
> DOMAIN="domain.tld",
> FQDN="$CONTEXT[$DOMAIN].$CONTEXT[$HOSTNAME].",
> HOSTNAME="host" ]
> [... output omitted for brevity ...]
>
> Same result in the VM.
>
> $ onevm show vars
>
> VIRTUAL MACHINE TEMPLATE
> CONTEXT=[
> DISK_ID="1",
> DOMAIN="domain.tld",
> *FQDN=".."*,
> HOSTNAME="host",
> TARGET="hda" ]
> [... output omitted for brevity ...]
>
> Is it possible to achieve what am I trying or should I search for a new
> solution?
>
> I have a simple use case. I am generating, via a hook, the ssh keys for
> the VM in question. At boot I copy the keys from /mnt to /etc/ssh via
> a crafted one-context script. Awesome mechanism by the way :-).
>
> I am generating the keys in
> CONTEXT_FILES_LOCATION=/var/lib/cloud/context/host.domain.tld.
>
> I would like to use the following in the CONTEXT section:
>
> CONTEXT=[
> CONTEXT_FILES_LOCATION=/var/lib/cloud/context/host.domain.tld./,
> DOMAIN="domain.tld",
> FILES="$CONTEXT_FILES_LOCATION/$FQDN/ssh_host_rsa_key ...",
> HOSTNAME="host",
> FQDN="$HOSTNAME.$DOMAIN." ]
>
> This makes the template much more dynamic. I would just change the HOSTNAME
> and the paths would get generated dynamically.
>
Writing the HOSTNAME, DOMAIN, CONTEXT_FILES_LOCATION outside the CONTEXT
section and referencing them from within CONTEXT works :-).
Example
--
$ onetemplate show vars
TEMPLATE CONTENTS
CONTEXT=[
CONTEXT_FILES_LOCATION="$CONTEXT_FILES_LOCATION",
DOMAIN="$DOMAIN",
FILES="$CONTEXT_FILES_LOCATION/$FQDN/ssh_host_rsa_key
$CONTEXT_FILES_LOCATION/$FQDN/ssh_host_rsa_key.pub",
FQDN="$HOSTNAME.$DOMAIN.",
HOSTNAME="$HOSTNAME" ]
CONTEXT_FILES_LOCATION="/var/lib/cloud/context"
CPU="1"
DISK=[
IMAGE="vars" ]
DOMAIN="domain.tld"
GRAPHICS=[
LISTEN="0.0.0.0",
TYPE="vnc" ]
HOSTNAME="host"
MEMORY="2048"
NIC=[
NETWORK="host.domain.tld" ]
OS=[
ARCH="x86_64" ]
VCPU="4"
After instantiating the machine I have the desired results.
$ onevm show vars
VIRTUAL MACHINE TEMPLATE
CONTEXT=[
CONTEXT_FILES_LOCATION="/var/lib/cloud/context",
DISK_ID="1",
DOMAIN="dev.corview.de",
FILES="/var/lib/cloud/context//ssh_host_rsa_key
/var/lib/cloud/context//ssh_host_rsa_key.pub",
FQDN="vars.domain.tld.",
HOSTNAME="vars",
TARGET="hda" ]
Now I can easily generate SSH host keys for each machine if this wasn't
done already in a previous VM instantation.
Thanks and sorry for the noise. If this is mentioned somewhere in the
docs, my bad.
Cheers and Goodwill,
--
Valentin Bud
http://databus.pro/ | valentin at databus.pro
More information about the Users
mailing list