Fixing Ubuntu Vivid Vervet apt error for CDROM source: sed one-liner goodness

While I tend towards mainly Ubuntu 14.04 LTS (Trusty Tahr) as my core Linux derivative, it is time to move on to the 15.x stream and embrace the Ubuntu 15.04 (Vivid Vervet) for the next bunch of work I’ll be doing.

A common practice is that I run the installation and then do an apt-get update to make sure I’ve got the latest goodness from the source repository. If you’ve tried this after doing a CD or ISO install of Vivid Vervet, you will discover that it leaves the CD-ROM as an apt source.

This is what the process will look like out of the box:

apt-update-error1

apt-update-error2

This leaves you with that sad, can’t be updated feeling.  Nobody likes that feeling.

Removing the CD-ROM apt source with sed

Because I’m fundamentally lazy, I decided that the process of using nano to edit the /etc/apt/sources.list file is a few too many steps.  Plus, I’m a vim lover, but it isn’t installed and can’t be because of the apt source issue.

Note:  I also recognize that true laziness would mean using Vagrant, but there are times when an ISO install happen, so I wanted to share this 🙂

Sed is a great little tool baked into Linux, so let’s just do the process using sed and the one-liner as follows:

sudo sed -i 's/deb cdrom/#deb cdrom/g' /etc/apt/sources.list

sed-fix-apt-source

That just means that we stream the /etc/apt/sources.list file and replace the instances of deb cdrom with #deb cdrom which turns it into a comment line in the file.

There is a comment line in the sources.list file which will get an extra hash in front of it, but I’m doing this rather quick and dirty.

Once we run that command we can now run the apt-get update again now and it looks much better:

apt-update-success

Now you can update as needed.  Hope this is a simple, but helpful tip!




Starting with Vagrant and VirtualBox: A Basic Ubuntu 14.04 LTS Server

As a part of my #vDM30in30 post series, I’ve got some lab work that we will be doing together. This is the start which will be the foundation for the next set of posts that work with Vagrant and VirtualBox.

We are about to go on an adventure together! Using Vagrant is becoming a standard part of every day for me. As a frequent tester of new technology, one of the most important tools in my toolkit is automation. My tool of choice for that is nearly always Vagrant.

Install Vagrant for your OS of choice from here: https://www.vagrantup.com/downloads.html

Install VirtualBox for your OS of choice from here: https://www.virtualbox.org/wiki/Downloads

Once you’re installed and ready, we will create our new Vagrant configuration together.

Create a Directory and Initialize a Vagrant Configuration

First, we need to create our directory where our configuration will go, and in my case I’ve created a simple folder named VagrantIntro on my OS X machine. The same process holds true for Windows systems, so this will make things easier as we go.

Now we need to initialize a Vagrant configuration with a very simple command vagrant init

01-vagrant-init

You will see on screen that there has been a ‘Vagrantfile’ created. This is the configuration for your Vagrant deployment which we will be building to set up our first Ubuntu server.

We are going to edit that file shortly, but first let’s jump into what the Vagrant Box list is and how we are going to choose which server to deploy from it.

VagrantBox.es

To figure out which Vagrant box to use, we can scan through the online catalog of Vagrant boxes, neatly found at VagrantBox.es which holds a current list of available images. There are lots of images there to choose from, but in our case we want to narrow the search to show only ones that are the Ubuntu 14.04 Trusty server.

Using the search field above the table, type in Trusty and you will see a more narrowed down list for us:

02-vagrant-boxes

You can see that there are a few fields there to show what the configuration for each box is. These are the Name, Provider, URL, and Size in MB. For our Trusty images, we have a list of 5 entries to choose from which include two cloud images for x64 and x86 editions, a full Virtual Box image which includes Chef and Puppet already (Yay!), and also a VMware version of the same file, and finally a KVM edition which is a traditional Ubuntu server build.

We choose, or rather I choose, to use the 14.04 LTS edition. LTS stands for Long Term Support, and these tend to be very stable and popular images for building servers.

For our configuration, we will use the 14.04 amd64 edition for VirtualBox. Make sure you keep the URL handy https://oss-binaries.phusionpassenger.com/vagrant/boxes/latest/ubuntu-14.04-amd64-vbox.box, as we will be needing it to add to our Vagrantfile next.

Editing the Vagrantfile

For our experiment, we want a completely empty Vagrantfile to start off so that we have a simple version to build on. Copy your current Vagrantfile to another file and rename it to Vagrantfile.old and then open up your Vagrantfile with the editor of your choice (I use Sublime), and empty out the contents of the file.

Now we have a basic Vagrant file to create which will look like this:


# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'virtualbox'

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "ubuntutest" do |ubuntutest|
ubuntutest.vm.hostname = "ubuntutest"
ubuntutest.vm.box = "trusty-server"
ubuntutest.vm.box_url = "https://oss-binaries.phusionpassenger.com/vagrant/boxes/latest/ubuntu-14.04-amd64-vbox.box"
end
end

As we move through the series, we will deconstruct the Vagrantfile and really dive into how each code block works. For now, this is meant to get our first machine up and running.

Vagrant Up!

Now that we have our configuration file ready, we can check the status to be sure that it is ready to go. This is done with the vagrant status command. Because I’m on a Mac and I don’t use root privileges, you can see from my screen shot that it will show me using sudo vagrant status which may be different than what you so.

vagrant-status-not-created

Next we run my favorite command to kick everything off which is quite simply vagrant up which will run through our configuration file and create a machine named ubuntutest based on the Ubuntu 14.04 Trusty image. Yup, it’s just that easy:

vagrant-up

We can check on our machine status by running the vagrant status again, and this time you will se a little bit of magic has happened because we now have a running machine!

vagrant-status-up

Now we need to clean up after ourselves because this is just the first step and we may want to take a break between things. We are going to suspend our virtual guest because it doesn’t need to be running all of the time. This is easily done with the vagrant suspend ubuntutest command, after which we will run another vagrant status command to confirm that the machine is in a saved state.

suspended

There we go! Now pat yourself on the back, take a break and enjoy because we are going to keep on rolling ahead with this Vagrant configuration and grow it much larger in the series. 🙂




Puppet 101 – Basic installation for master and agent machines on Ubuntu 12.04 with VMware Workstation

You don’t have to go far to hear the word Puppet these days. Configuration management isn’t just a new trend that is hitting IT environments. It is a methodology for stateful, repeatable, DevOps style management of your infrastructure.

For the VMware folks, this is now a part of the vCloud ecosystem in a way because of the integration of Puppet into the vCloud Hybrid Service (vCHS) that was recently announced.

Most Common Question

Nearly every single day I hear from someone “Puppet looks cool, I need to figure out how to use it”. This inevitably leads to the most common question: “How do I get started with Puppet?”

Before you say “I don’t use Linux”, don’t worry. What I want to do here is to show you the simplest step-by-step way to install Ubuntu on a server and a client with Puppet server and a Puppet agent configuration.

Let me be clear that our Puppet installation here isn’t difficult, but it does require some time and you have to be sure to follow the process, albeit concise, without missing any steps.

Two Flavors of Puppet to Start Off With

There are two distinct types of Puppet deployment: Enterprise or Open Source. This leads to the next challenge for many, which is finding out which is the appropriate one to run with. Hint: They are both great to start with 🙂

With the Puppet Enterprise environment (https://puppetlabs.com/puppet/puppet-enterprise/) you can deploy easily using the web dashboard, manage your environment with the full backing of the Puppet team. It has all sorts of reasons to make it an amazing fit for you.

That being said, it is also a commercial product which comes with a license and support cost. This is not a problem for your real production deployment where you need/want that support, but we just want to kick the tires on it first to figure out how to use it.

Enter Puppet Open Source (https://puppetlabs.com/puppet/puppet-open-source/) which lets us use the fully open source version of the product, and the price tag is a grand total of zero dollars. Well, capital expense is zero, but there are some requirements for running this which include comfort with the Linux environment.

Basic Installation For Brand New Users

I’m going to use my VMware Workstation environment to start things off. I also have the Ubuntu 64-bit Server 12.04 LTS (Long Term Support) ISO file which I’ll use for deploying. Before we get started, you need to go here  to download that: http://www.ubuntu.com/download/server

Now that you have your requirements, let’s install our two virtual guests which will be using DHCP (easiest deployment to get us started quickly) using the names puppetserver and puppetclient for our virtual machines. We will use the VMware Workstation “easy install” wizard to quickly deploy the guest OS.

Install Our First VM (puppetserver)

Using or VMware Workstation, we will create a new virtual guest by choosing File | New Virtual Machine and using the steps below:

01-newvm

02-vmhardware

03-osChoice

At this point you have to choose your username that will be your login account to the Ubuntu console. Type in your full name, a user name and a password:

04-username

05-vmname-puppetserver

06-processor

07-memory

08-network

09-controller

10-newdisk

11-scsi

12-singlefile

13-diskfilename

14-finish

15-deploying

16-firstvmread

Install Our Second VM (puppetclient)

Rather than repeating all of our screen shots, just repeat the process as you did above, except you need to select puppetclient as the VM name in step 5.

17-puppetclient

Now that you have deployed your second machine, you can see the two guests in your VMware Workstation window.

18-bothmachines

Yay! We have our two guest machines ready to start our Puppet deployment.

Configuring our Puppet Master (puppetserver)

Log in to the console using the credentials you defined during the setup wizard. We will launch all commands using the sudo command which will elevate our privileges to launch each action. The first time you use sudo, you will be prompted for your credentials. Further sudo commands in the same session will use those cached credentials.

Update the apt repositories with the apt-get utility

sudo apt-get update

Change the host name using sed (Linux stream editor)

sudo sed -i ‘s/ubuntu/puppetserver/g’ /etc/hostname

Set our IP up for the network interface eth0 using nano (a fairly simple Linux editor). Once we edit the info with the format below, using your own IP information, we just type Ctrl-X, then type Y followed by pressing Enter to confirm the file name, save and exit. While I don’t personally use nano, the general usage is simple for those just getting started.

sudo nano /etc/network/interfaces

server-ipsetup

Add a record to the Hosts file for our server and our client (use your own IP addresses of course)

sudo nano /etc/hosts

server-hosts

Install Puppet

sudo apt-get install -y puppetmaster

Stop the puppetmaster service

sudo service puppetmaster stop

Remove the default certificate

sudo rm -r /var/lib/puppet/ssl

Reboot the server

sudo reboot

Log in to the console once the reboot is completed. We will do some tasks after our client is configured.

That’s it. No, really, that’s the end of the server configuration. Next we configure our client machine

Configuring our Puppet Agent (puppetclient)

Now we log in to the console of our second guest which will become the agent managed machine. We will be performing the following steps:

Update the apt repositories with the apt-get utility

sudo apt-get update

Change the host name using sed (Linux stream editor)

sudo sed -i ‘s/ubuntu/puppetclient/g’ /etc/hostname

Set our IP up for the network interface eth0 using nano (a fairly simple Linux editor). Once we edit the info with the format below, using your own IP information, we just type Ctrl-X, then type Y followed by pressing Enter to confirm the file name, save and exit. While I don’t personally use nano, the general usage is simple for those just getting started.

sudo nano /etc/network/interfaces

client-ipsetup

Reboot to ensure the new IP and hostname take effect

sudo reboot

Log in to the console again

Add a record to the Hosts file for our server and our client (use your own IP addresses of course)

sudo nano /etc/hosts

client-hosts

Install Puppet

sudo apt-get install -y puppet

Add the puppetmaster server entry in the puppet.conf file. We will create an [agent] section and put an entry which says server = puppetmaster

sudo nano /etc/puppet/puppet.conf

client-puppet

Set the puppet agent to start automatically using sed

sudo sed -i ‘s/no/yes/g’ /etc/default/puppet

Restart the puppet agent

sudo service puppet restart

Now are client is fully configured. Let’s go back to the puppetserver console and manage the puppet agent request which will have been created by restarting the services on the client.

On the puppetserver console we list the pending certificates and then we sign the certificate with the requesting name attached. This is the sequence that we use:

sudo puppet cert –list

sudo puppet cert sign agentname

server-cert

And now we have our Puppet server and Puppet client all ready to go!!

We have lots of tasks we can do now, but we start with the basic step of creating our first manifest.

Creating your site.pp file

On your puppetserver you need to create your first manifest. With future articles we will do lots more than this, but the first step is to get your initial file started to test the running of the manifest against your new puppet client.

sudo nano /etc/puppet/manifests/site.pp

Add the following content shown in the image and save the file

server-manifest

Next we can either wait for the manifest to run at the next interval…which we won’t do because we are impatient 😉

Log into the puppet client console and initiate the puppet agent by restarting the service

sudo service puppet restart

Now we will run the puppet agent to test the connection

sudo puppet agent –test

client-agent-firstrun

Yay! It worked. Let’s confirm the file has shown up as we defined it in our site.pp manifest:

client-file

So now we have successfully completed a few tasks:

  1. Installed our puppet server
  2. Installed a puppet client
  3. Connected the puppet client to the server
  4. Created a basic (very, very basic) manifest
  5. Run the manifest against our client

This may not seem like a big accomplishment for some, but surprisingly there are many administrators who have little or no experience with using Linux systems, and the first few steps, although simple, can be daunting for some.

In future posts we will take the next important steps of creating manifest modules, deploying the puppet client to a Microsoft Windows machine, and then getting into more detailed manifest configuration.

Puppet Cheat Sheets

We will use these for our next post as we start to build some basic manifests for testing out the various components. We can use these to help us dip our toes further into the water of Puppet automation.

Puppet Labs Module Cheat Sheet – http://docs.puppetlabs.com/module_cheat_sheet.pdf

puppetlabs-cheatsheet-module

Puppet Labs Core Types Cheat Sheet – http://docs.puppetlabs.com/puppet_core_types_cheatsheet.pdf

puppetlabs-cheatsheet-coretypes

So read those guides and we will be adding some more flavor to our little Puppet test environment very soon! I hope that this is a helpful guide to get people started on your journey with puppet 🙂