Instead of running Shell scripts or any
other type of script, we can define configuration changes on the
instance with the help of a cloud-config file.
Unfortunately the CirrOS image is so tiny that it doesn't have a
cloud-init installed, and I will therefore obtain a real operating
system, in this case Fedora. To do that, I have to go to the internet.
Here we are in the Fedora Cloud section, and as you can see,
there is an image for OpenStack. Let me just copy the image location,
and back in the commandline, I'm now downloading it.
That takes a few minutes, so a little time warp would be nice here.
So it's been downloaded, and now I have to upload this image to
Glance's image store. We will cover Glance in more detail in the
Cloud Operator course, and for now just accept that the command is
image create, and don't worry about the options for this command.
And now we have two images. Okay, before I continue, let me get rid
of the existing instance, good. Now I have to write a cloud-config
file, but I don't know the syntax so well.
So I'm going to look up the documentation, it's on the site here,
cloud-init.readthedocs.io, and you can see here there are a few
cloud-config examples, I'm just going to use the very first one,
which allows me to add groups and users to the instance.
Now I can create my cloud-init file, I'm going to call it adduser.yaml.
So this format is YAML, which stands for YAML is not a Markup Language.
It can also be used to describe data just like JSON.
So this is the cloud-init language, and you will later see that it's,
in OpenStack, it's also used for describing complex cloud applications.
The important line here is right at the beginning without the
#cloud-config, it's not identified as a cloud-config file.
I created a group here, or described a group named Pluralsight,
and a user name Plural, and I want this user to be part of the default
group, Plural, and also its Pluralsight group.
This default up there, by the way, is required to keep the default
user on that instance, and for a Fedora image, the default user is
named Fedora, as you will see. I want my new user to be able to
access the instance with an SSH key. So I need to find out what is my
public key, and I will just paste that into the cloud-config file like that.
And that should be it. Alright, so I will now launch a Fedora
instance with this cloud-config file as user-data.
So I also have to change the name of the image obviously,
and Fedora is just too large for flavor 1, so I'm going to use flavor
2, that's sort of the minimum for a Fedora image to run.
Okay, now when you run Packstack on a virtual machine, as I suggested
you do, you will see that Fedora takes a long time to start up,
and that is so because by default, Packstack uses QEMU,
an emulation tool, to run virtual machines, to run instances.
And my Packstack server here has been set up for nested KVM and is much faster.
If you want to set up Packstack for KVM, just look at the lab
descriptions, and it's actually very simple to do that.
Alright, so let me set up the instance for access from outside,
whoops, here, let me try again, yep. Of course the floating IP as
well, is it accessible, that looks good, so let's see if our user data
was successful again. And it's successful if I have a new user.
You saw me log on as user Fedora, which is the default user,
but here in the password file, you can see that Plural is also configured.
And as you can see, it belongs to the two groups, Plural and Pluralsight.
The last thing I'd like to show you is an alternative for accessing metadata.
You have already seen the metadata API, but we can also use the config drive.
Some clouds configure the config drive to be the default,
but this Packstack installation here requires me to add a parameter
when I launch the instance, --config-drive true.
And here again you can see the config_drive option in the instance details.
Okay, so security group and floating IP as before, and now let's enter
the instance and explore that config drive.
To the instance, the config drive looks like a CDROM.
We can see it by listing all its storage, here it is.
It can be mounted, it's mounted, and I can explore it now.
It's a bit hard to read perhaps, but there are two directories named
ec2 and openstack. Ec2 is for the Amazon version of instance
metadata, and openstack obviously for the OpenStack version.
So in the openstack, we have the various versions, let me go to the
latest one, and here we have our familiar meta_data.json file.
It's the same as the one that we retrieved with curl.
And we have here the metadata key-value pair and also the Secure Shell key.
I can also see the user data, it's here, and as you can see,
that's our Shell script. With that, we can wrap up this demo and also
the Nova training module.