Deploying VMs

168 views
Skip to first unread message

Adam J. McPartlan

unread,
Feb 17, 2022, 5:40:33 AM2/17/22
to gan...@googlegroups.com
Hiya,

I have made a basic bash script to create a VM (below) but to have a single file that will recreate the instances to defined specs does anyone do something similar or use something like Terraform or Packer? I'd be interested to hear how you manage it.


#!/bin/bash
## Take input and store in variables ##
echo "FDQN of new server: "
read svrname
echo "Disk Space required (in GB): "
read size
echo "RAM Required :"
read ram
echo "VCPUs required: "
read procz

echo ""
echo "####################################################"
echo "Thanks, please wait for your instance to be created"
echo "####################################################"
echo "..."

## Create Instance
gnt-instance add -t drbd -o noop -s $size -B maxmem=$ram,vcpus=$procz --no-start --no-name-check --no-ip-check $svrname

## End

After which I run:
gnt-instance start -H boot_order=cdrom,cdrom_image_path=/home/user/ubuntu-20.04.2-live-server-amd64.iso server.doamin.co.uk



Best wishes with thanks,

Adam


Daniel Howard

unread,
Feb 17, 2022, 6:55:50 PM2/17/22
to gan...@googlegroups.com
Adam,

You might dig this project, which can help you set up a "cloud image" to bootstrap instances in one command: https://github.com/neicnordic/ganeti-os-nocloud

For a long time, we've had a script that has a variety of "standard sizes" ... the script is messier than I'd like to share, but here's an idea of how it is designed, in case you'd want to do something similar:

> qfvm

Usage: /usr/local/bin/qfvm add <size> <name> [image]
Usage: /usr/local/bin/qfvm capacity

Where command is one of:
add: add a VM
capacity: report on current cluster capacity for various VM sizes

Where size is one of: xs s m l xl xxl

Size RAM CPUs Disk
xs   1G  1    8G
s    2G  1    12G
m    4G  2    16G
l    8G  4    24G
xl   16G 8    32G
xxl  32G 16   64G

Optionally, specify any of the following images as the base for your VM:
    default    ubuntu-20.04

NOTE: If you want larger than 'xxl' VM, what you might really
want is dedicated hardware. Contact the Ops team to get that
set up.

Example:
/usr/local/bin/qfvm add xs djh0.xxx.xxxxxxxxxx.com

Creates VM named djh0.xxx.xxxxxxxxxx.com with 1G RAM, 1G CPUs, and 8G disk.

If I run the script it then shows me the create command along the way:

NOTE: now I will run this command:
gnt-instance add -s 8G --no-wait-for-sync -B memory=1G,vcpus=1 -o nocloud+ubuntu-20.04 -O dns_nameservers=x.x.x.x --net 0:network=ops,ip=x.x.x.x --tags role:ops-djh,env:ops djh0.ops.xxx.xxxxxxxxxx.com


The tags are used for placement rules, like "don't put multiple instances of role:ops-djh on the same node" or "try to put env:prod on nicer hardware."

If folks are using a more standard modern tool, I'm keen to hear about it.

--
You received this message because you are subscribed to the Google Groups "ganeti" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ganeti+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ganeti/CAOHky1EKODkGJ3edVTnnv5%2BmyqpsevCpJFJBEx_CG6YVEaOMLw%40mail.gmail.com.


--

Brian Candler

unread,
Feb 25, 2022, 4:57:52 AM2/25/22
to ganeti
I've used snf-image in the past, using images that they published, and they even added some cloud-init support (not tested by me). However the whole project appears to be abandonware: the docs link is broken (as linked from here and here), and last commit 4 years ago.

Unfortunately, I don't think ganeti's proprietary metadata service (metad) was never extended to be compatible with EC2 or another cloud-init data source.  If it were, then you could just fire up the VM and pass it the cloud-init metadata directly.  Ref:

I haven't tried ganeti-os-nocloud but I believe it injects the metadata directly into the filesystem image.

The approach I would probably use today is to attach a temporary second drive (sdb or possibly floppy) containing the metadata.  I've done this for cloud-init with vanilla KVM (inside gns3 as it happens), and I don't see why it wouldn't work with ganeti.

"cloud-localds" can be used to create the initial image, and since it's a vfat filesystem, you can easily mount it and modify it afterwards.  Here is a slightly-trimmed version of script I use:

#!/bin/bash -eu

# Create the local data source for cloud-init to boot inside the GNS3 environment

# Inspired by https://github.com/asenci/gns3-ubuntu-cloud-init-data/
# See also:
# https://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html
# https://cloudinit.readthedocs.io/en/latest/topics/network-config-format-v1.html
# https://cloudinit.readthedocs.io/en/latest/topics/network-config-format-v2.html
# https://cloudinit.readthedocs.io/en/latest/topics/modules.html
# https://cloudinit.readthedocs.io/en/latest/topics/faq.html#what-datasource-am-i-using

# NOTE: after modifying config, you can reinitialize an existing VM using
#   sudo cloud-init clean     # (this also wipes ssh keys etc)
#   sudo cloud-init init

ETH0='ens3'
PASSWD='$6$<SNIPPED>'
: "${TMPDIR:=/tmp}"
DATE="$(date -u +%Y%m%d)"

mkdir -p nocloud

FQDN="noc.ws.nsrc.org"
IPV4="100.64.0.250"
IPV6="2001:db8:0:0::250"

######## NETWORK CONFIG ########
cat <<EOS >"$TMPDIR/network-config"
version: 2
ethernets:
  $ETH0:
    accept-ra: false
bridges:
  br0:
    interfaces:
      - $ETH0
    # note https://bugs.launchpad.net/cloud-init/+bug/1879673
    parameters:
      forward-delay: 0
      stp: false
    accept-ra: false
    addresses:
      - $IPV4/22
      - $IPV6/64
    gateway4: 100.64.0.1
    gateway6: 2001:db8:0:0::254
    nameservers:
      addresses:
        - 100.64.0.1
      search:
        - ws.nsrc.org
EOS

######## USER DATA ########
# This configures all other aspects of boot, including creating user/password.
cat <<EOS >"$TMPDIR/user-data"
#cloud-config
fqdn: $FQDN
chpasswd:
  expire: false
ssh_pwauth: true
users:
  - name: sysadm
    gecos: System Administrator
    groups: [adm, audio, cdrom, dialout, dip, floppy, lxd, netdev, plugdev, sudo, video]
    lock_passwd: false
    passwd: $PASSWD
    shell: /bin/bash
final_message: System is ready!
EOS

yamllint -d relaxed "$TMPDIR/user-data"
yamllint -d relaxed "$TMPDIR/network-config"
OUTFILE="nocloud/noc-hdb.img"
rm -f "$OUTFILE"
cloud-localds -f vfat -d raw -H "$FQDN" -N "$TMPDIR/network-config" \
    "$OUTFILE" "$TMPDIR/user-data"


If you're happy for your VM to pick up an IP address via DHCP then you can skip the network-config bit, and use only the user-data section to prime your user account, ssh_authorized_keys etc.  Then all your VMs can boot using the same cloud-init disk.

Petter Urkedal

unread,
Feb 25, 2022, 6:19:58 AM2/25/22
to gan...@googlegroups.com
On 2022-02-25 01:57, Brian Candler wrote:
> I haven't tried ganeti-os-nocloud
> <https://github.com/neicnordic/ganeti-os-nocloud> but I believe it injects
> the metadata directly into the filesystem image.

Yes.

> The approach I would probably use today is to attach a temporary second
> drive (sdb or possibly floppy) containing the metadata. I've done this for
> cloud-init with vanilla KVM (inside gns3 as it happens), and I don't see
> why it wouldn't work with ganeti.

I agree it's a nicer solution. As far as I recall, a reason I didn't go
for providing metadata by separate disk or network was that I didn't see
a way to configure and de-configure the devices before and after the
first boot. If I understand you correctly, you would let the disk be
permanently attached to the VMs?

Brian Candler

unread,
Feb 25, 2022, 7:16:14 AM2/25/22
to ganeti
I wouldn't leave it permanently attached.

cloud-localds can also create an ISO image (in fact it's the default behaviour, or use "-f iso"), and I know that you can attach a CD-ROM temporarily for first boot only:

    gnt-instance start -H cdrom_image_path=/iso/blah my-instance

Maybe floppy_image_path would work too, in which case you can stick with an editable vfat filesystem.  You may need to experiment a bit to find which option(s) work.

Petter Urkedal

unread,
Feb 25, 2022, 7:37:48 AM2/25/22
to gan...@googlegroups.com
On 2022-02-25 04:16, Brian Candler wrote:
> I wouldn't leave it permanently attached.
>
> cloud-localds can also create an ISO image (in fact it's the default
> behaviour, or use "-f iso"), and I know that you can attach a CD-ROM
> temporarily for first boot only:
>
> gnt-instance start -H cdrom_image_path=/iso/blah my-instance
>
> Maybe floppy_image_path would work too, in which case you can stick with an
> editable vfat filesystem. You may need to experiment a bit to find which
> option(s) work.

Yes; this requires --no-start when adding it, but then various kind of
devices can be added temporarily, including additional disks but
excluding network devices (as far as I can tell). I guess that's
reasonable, or else one can add a wrapper script.

Rudolph Bott

unread,
Feb 28, 2022, 1:54:30 PM2/28/22
to gan...@googlegroups.com
Hi Adam,

we are using an Ansible module to integrate Ganeti (via RAPI) into our Ansible workflows:


We forked it from svalouch/ansible-modules-ganeti and added a bunch of new features. The usage is documented in the README if you want to try it out.

Cheers,
Rudi

--
You received this message because you are subscribed to the Google Groups "ganeti" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ganeti+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ganeti/CAOHky1EKODkGJ3edVTnnv5%2BmyqpsevCpJFJBEx_CG6YVEaOMLw%40mail.gmail.com.


--
 Rudolph Bott - bo...@sipgate.de

 sipgate GmbH - Gladbacher Str. 74 - 40219 Düsseldorf
 HRB Düsseldorf 39841 - Geschäftsführer: Thilo Salmon, Tim Mois
 Steuernummer: 106/5724/7147, Umsatzsteuer-ID: DE219349391

Adam J. McPartlan

unread,
Mar 1, 2022, 12:02:27 PM3/1/22
to gan...@googlegroups.com
Thank you for your replies, they are really appreciated.
I have not been ignoring you, I've just had to have some time off.

Some great responses to have a look at will take away and give them a try at some point once I catch up with everything else.

With thanks,
Adam



Daniel Howard

unread,
Feb 26, 2024, 2:20:15 PMFeb 26
to ganeti
On Monday, February 28, 2022 at 10:54:30 AM UTC-8 Rudolph Bott wrote:
Hi Adam,

we are using an Ansible module to integrate Ganeti (via RAPI) into our Ansible workflows:


We forked it from svalouch/ansible-modules-ganeti and added a bunch of new features. The usage is documented in the README if you want to try it out.

Rudi,

I was just looking at ansible-modules-ganeti. It is a nice enhancement to the deprecated module, but I have a few questions:
1) Have you tried ganeti 3.0 yet? :)
2) Where do I pick up ganeti_rapi_client.py? I don't see that filename at https://github.com/ganeti/ganeti/tree/master/lib/rapi.

We aren't RAPI users (yet), but we probably should be.

I think a faster approach for us might be an Ansible role that can test if an instance exists, and then craft an appropriate gnt-instance command, delegated to the appropriate master. There's a little fragment here that demonstrates the idea: https://codeberg.org/inflatador/ansible_role_ganeti/src/branch/main/tasks/create_vm.yml. OTOH, getting RAPI working with a module may offer greater flexibility.

What are folks doing these days?

-danny

Rudolph Bott

unread,
Feb 29, 2024, 5:27:54 PMFeb 29
to gan...@googlegroups.com
Hi Danny,

Am Mo., 26. Feb. 2024 um 20:20 Uhr schrieb Daniel Howard <dann...@toldme.com>:
On Monday, February 28, 2022 at 10:54:30 AM UTC-8 Rudolph Bott wrote

I was just looking at ansible-modules-ganeti. It is a nice enhancement to the deprecated module, but I have a few questions:
1) Have you tried ganeti 3.0 yet? :)

Yes, we have been using it with Ganeti 3.0 for a while now. We finished updating our last cluster from 2.x to 3.0 some time last year :-)
 
2) Where do I pick up ganeti_rapi_client.py? I don't see that filename at https://github.com/ganeti/ganeti/tree/master/lib/rapi.

If you are on Debian, you can simply install python3-ganeti-rapi - this package contains the python module.
 

We aren't RAPI users (yet), but we probably should be.

Yes, you should :-) On Debian you only need to alter /etc/default/ganeti to have it listen on 0.0.0.0 on your master node (unless you have some sort of reverse proxy in place) and create a user in /var/lib/ganeti/rapi/users according to the documentation[1]
 

I think a faster approach for us might be an Ansible role that can test if an instance exists, and then craft an appropriate gnt-instance command, delegated to the appropriate master. There's a little fragment here that demonstrates the idea: https://codeberg.org/inflatador/ansible_role_ganeti/src/branch/main/tasks/create_vm.yml. OTOH, getting RAPI working with a module may offer greater flexibility.

What are folks doing these days?

In short: we have all information stored in netbox, feed that information to ansible (via an inventory plugin) and have several ansible roles which a) create or update the instance if needed (using the above mentioned module and the Ganeti debootstrap OS provider) and b) carry out the base system configuration (auth, logging, monitoring etc.) after the VM has booted for the first time.

hope that helps :-)
 



-danny

--
You received this message because you are subscribed to the Google Groups "ganeti" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ganeti+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages