Cloud-init – Part 2 – Advanced Ubuntu

In Cloud-init – Part 1 – The Basics, we laid the groundwork for using cloud-init in a vSphere environment. In this post we will go into more advanced Ubuntu setups. This includes deploying PowerShell, v6 and v7, using repositories and if needed, a GUI with Visual Studio Code.

For the installation of software on the instance we use the user-data YAML file. In the following sections, we discuss some of the more obvious candidates you want to have on your station. Remember that the basic idea of the series is to have a “cattle” station to test/run (and optionally develop) your scripts.

Scripting Packages

PowerShell

Let’s start by installing PowerShell on the instance. This comes down to adding a couple of instructions to the YAML file we used in Part 1.

Annotations

Line 33-39: The instructions to install PowerShell are added to the runcmd section.

Line 33: You can use comments in your YAML file. I highly recommend doing that. It will help others, and probably yourself later on.

Line 34-35: The method uses the install-powershell.sh bash script to install the latest PowerShell v6 and the latest PowerShell v7 Preview. I personally prefer this method vs the apt-get method, since it is globally usable on multiple Linux distributions. The install-powershell.sh script determines on which distro it is running, and launches the appropriate command(s).

Result

Git & repo cloning

For your scripts, you, of course, use a repository. That means you will need to configure git, and a way to clone repositories to your instance.

The following extract of the YAML file only shows the lines in the runcmd section.

Annotations

Line 14-16: Since git is by default installed in the Ubuntu 18.04 LTS Cloud Image OVA file, we only need to configure some settings. In this we update some configuration settings, primarily to be able to correct sign off commits.

Line 17-19: As part of the deployment process through cloud-init, you can clone specific repositories to the instance. In these lines I used Alan Renouf‘s vCheck-vSphere repository as an example.

Result

Going GUI

There might be occasions when you need to provide a temporary station with a GUI. That can also be done with cloud-init’s user-data YAML file.

The Desktop

The choice of which desktop and which desktop manager is completely up to you. Just be aware that some of these might require more resources to be assigned to the instance.

The following sample is intended for an Ubuntu 18.04 LTS instance. Again this extract only shows the runcmd section of the YAML file.

Annotations

Line 1-10: In this example, I use lubuntu as the desktop. Primarily because it is fast and resource-friendly.

Line 2: We use tasksel to install the desktop, so we have to make sure that it is available.

Line 5: There is a known issue with the light-locker package. Until a final fix is available, the easiest solution is to just uninstall it. If you absolutely need a screen-saver, install one of the alternatives. Like for example xscreensaver.

Line 6: Next we start the display manager lightdm.

Line 7-10: We need a way to connect to the station we are deploying. In this example, I opted for RDP as my protocol.

Line 8: The apt-transport-https package is a pre-requisite.

Line 10: Configure the xrdp service to automatically start at the boot.

Visual Studio Code

Now that we have a GUI, we can use several GUI based applications. For working with PowerShell, the Visual Studio Code editor with the PowerShell extension is an obvious choice.

Annotations

Line 2-4: The standard installation procedure for Code on a Linux platform.

Line 5-8: This installs the extensions for PowerShell and GitLens. Remember that the cloud-init stages run under the root account, if you need to install packages for a user, make sure to change the owner.

Result

Conclusion

We have now set the stage to actually start using these instances. In one of the next posts in this cloud-init series, we will show how to run scripts on these stations.

If you have suggestions or questions about specific additions on these instances, feel free to use the comments.

Enjoy!

4 Comments

    Technology Short Take 122 - s0x

    […] Dekens has added four more articles to his site discussing this tool. Be sure to check them out (part 2, part 3, part 4, and part […]

    Cloud-init - Part 5 - Running Containers - LucD notes

    […] technically not a ‘real‘ cloud-init post, I consider it related to Part 1, Part 2 and Part3 in this […]

    Cloud-init - Part 4 - Running Scripts - LucD notes

    […] And although technically not a ‘real‘ cloud-init post, I consider it related to Part 1, Part 2 and Part3 in this series. In this post I’ll show how you can run scripts on these […]

    Cloud-init - Part 3 - Photon OS - LucD notes

    […] Part 1 and Part 2 of this series we used Ubuntu as the guest OS of our target instances. In Part 3 we will show how […]

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*

This site uses Akismet to reduce spam. Learn how your comment data is processed.