How to get started with Razor and Puppet – Part 1

Please read the comments, updates there!
Razor has gotten a CLI and API update, making some of the commands shown here not work correctly. If you come across something that doesn’t work, please look at the Razor wiki for help regarding that command.

Razor – The new posterchild of automated deployments is a great joint development project between EMC and Puppetlabs. It automates server deployments in both virtual and physical environments, and can thereafter easily hand it off to a third party management solution such as Puppet.

Want to automatically install Ubuntu 12.04 web servers? Check.
Want to automatically install ESXi hosts and link them to a vCenter resource? Check.
Want to automate installation of vCenter itself? Can do! (more of a Puppet thing than Razor)

So, the base of this “How to” is that we want to automatically install a few Ubuntu servers that was requested by our development team. We’ll create three of them just to make sure the dev team is happy with the resources they’ve gotten. We’ll only use Razor for deployment right now and will handle the handoff to Puppet later on.

To start with we need a master server that will serve out the images, install the OS and report back when done. To get Razor up and running we don’t really need Puppet, but we’ll install it anyway as we’ll use it for some really cool stuff in the later tutorials.

First off, get yourself a Ubuntu 12.04 server. Install it with all defaults in VMware Workstation, Fusion, VirtualBox, or on a proper ESXi-environment, you choose freely. I will be using Workstation for this. When the installation is complete, install OpenSSH so we can easily manage the server visa an SSH client like PuTTY. Oh, and for simplicitys sake, you should run all the commands as root, just so you know (you can use the command “sudo su -” for that).

aptitude install openssh-server

After that, connect to your server using PuTTY, no need for the console anymore. Install the Puppetlabs repo so we can get the latest Puppet packages instead of the default ones in the Ubuntu repos, and install puppet: (UPDATE July 5th and 29th, new link to the deb package and installation instructions)

wget http://apt.puppetlabs.com/puppetlabs-release-precise.deb
dpkg -i puppetlabs-release-precise.deb
apt-get update
apt-get install puppet
apt-get install puppetmaster

Now we want to make sure that the puppet service will be running even if we reboot the server:

puppet resource service puppet ensure=running enable=true
puppet resource service puppetmaster ensure=running enable=true

Now here comes the first cool part. We’ll actually use Puppet to install Razor for us! Instead of having to mess around with deb-packages or git, we’ll do it the simple way and use the Puppet module system to download the Razor module and all it’s dependencies.

puppet module install puppetlabs-razor

Just to make sure all rights are as they should be, run this command as well:

chown -R puppet:puppet /etc/puppet/modules

So now we’ve downloaded the Razor module to our Puppet library, but we haven’t really installed it. To install a package in Puppet, a Puppet agent is used. We’ll use the Puppet agent a lot more in the following tutorials, but for now we just want to run a single Puppet agent command that will “download” the Razor module to our server and install it there. You could run this on a totally different node that the Puppet node, which is something I might write a post on later. For now, just run this command:

puppet apply /etc/puppet/modules/razor/tests/init.pp --verbose

You’ll see A LOT of stuff happening, downloading files, creating files, removing stuff, moving other things, and so on. This is totally normal so don’t be afraid🙂 One thing that might mess with your installation though is that the Razor installation uses something called the “sudo” module while installing. This is generally not something you need to worry about, but what does happen during the installation is that the sudoers file will be replaced with a default one. That means your Ubuntu username (no, not root, the other one, the one you used to log in to the server in the first place) is no longer in the /etc/sudoers file meaning you no longer have the right to “sudo” any commands. You can easily fix this by editing the sudoers file, or do like me and create a file in /etc/sudoers.d/ that contains your username and your rights using the following commands. Long explanation, but really short implementation:

echo "jonas ALL=(ALL) ALL" > /etc/sudoers.d/20_jonas
chmod 440 /etc/sudoers.d/20_jonas

This file will be wiped everytime you do a new installation or upgrade of Razor, just be aware of that. And use your own username instead of “jonas”, of course.

SO… Now we have Puppet installed, we used it to install Razor, and we fixed our permissions. You’re probably asking yourselves “When are we getting to the deployment parts?” and to that I say SOON!

First we need to have some more pieces of the infrastructure in place, namely a DHCP server. Once again I’m using Puppet to install and configure a proper DHCP that we can use for everything we need. As I said, I’m running this lab in VMware Workstation which already includes a DHCP server which would interfere with an installed DHCP server. So what I did was to turn the builtin DHCP off, set a static IP on my Ubuntu server and install a proper DHCP:

  1. Open the “Virtual Network Editor”
  2. Verify that you have a NAT interface (should be VMnet8 if you’ve kept the defaults)
  3. Click on that interface, and uncheck the tickbox for “Use local DHCP…”
  4. Under “NAT Settings” you’ll find the default gateway for this network, make sure you make a note of that. Mine was 192.168.72.2.
  5. Make a not of the Subnet IPs you have, mine was 192.168.72.0 with a Subnet mask of 255.255.255.0
  6. Make sure all your VMs are connected to this NAT interface.

If your Puppet/Razor server is on this network as well you now have to set some static network settings on your eth0 interface to maintain network connectivity. Do this by editing your /etc/network/interfaces file like below.

# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.72.130
netmask 255.255.255.0
gateway 192.168.72.2

And your /etc/resolv.conf file like this:

#Using Google's public DNS server
nameserver 8.8.8.8

Then restart your networking with this command:

/etc/init.d/networking restart

Now that you’ve turned off the builtin DHCP server, set a static IP, let’s install a DHCP server!
For this I used another Puppet module (I know, cool right!) called saz-dnsmasq which will install the lightweight dnsmasq-package which includes a DHCP.

puppet module install saz-dnsmasq
puppet apply /etc/puppet/modules/dnsmasq/tests/init.pp --verbose

I also create a Puppet config for this that can then be reused whenever you need/want to reapply the DHCP configuration. Let’s try it out! Create a file called dnsmasq.pp and enter the following information in it (with your defaults of course, just change the bold ones to be your IPs that you want to give out addresses between, and the default gateway):

dnsmasq::conf { 'another-config':
    ensure  => present,
          content => "dhcp-range=192.168.72.100,192.168.72.150,12h\ndhcp-boot=pxelinux.0\ndhcp-option=3,192.168.72.2\ndhcp-option=6,8.8.8.8",
}

To actually set these settings on the DHCP service, run the following command and it will create a new file (called “another-config”) and restart the service:

puppet apply dnsmasq.pp

It’s that easy!

Now you should have a functioning Puppet installation that you’ve used multiple times already, a Razor installation that is ready to be configured, and a fully functional DHCP server. You are now ready for the next part!

Sources:
http://puppetlabs.com/blog/introducing-razor-a-next-generation-provisioning-solution/
http://puppetlabs.com/blog/puppet-razor-module/
http://nickapedia.com/2012/05/21/lex-parsimoniae-cloud-provisioning-with-a-razor/
https://github.com/puppetlabs/Razor/wiki/

About Jonas Rosland

Developer Advocate at EMC {code}
This entry was posted in Automation, EMC, Installation, IT Transformation, Puppet, Razor, VMware. Bookmark the permalink.

40 Responses to How to get started with Razor and Puppet – Part 1

  1. Jon Owings says:

    If you are in a network environment that might be blocking certain traffic, you may see the attempt to get certificates fail. Something to to tone of apt-key blah blah returned 2 instead the expected 1 of 0 (which doesn’t make sense).
    Now while I would never advocate circumventing corporate policies, if you run into this, run the razor install as Jonas describes from a VM outside of your corporate network, then copy or FTP /etc/apt/trusted.gpg to your internal machine. Razor install no longer chokes.

  2. Pingback: Using Puppet with Multiple Operating Systems - blog.scottlowe.org - The weblog of an IT pro specializing in virtualization, storage, and servers

  3. Nan Liu says:

    I should of supplied an example init.pp file that does not fully control sudoers. If you don’t want sudoers to be managed you need the following tests/init.pp manifests.

    class { ‘ssh’:
    config_file_replace => false,
    }
    class { ‘razor’:
    }

    • jonas says:

      Thanks Nan, that will definitely help. Perhaps it could be added to a new update of the code?
      And it should be sudo, not ssh, right? Like this:

      class { ‘sudo’:
      config_file_replace => false,
      }
      class { ‘razor’:
      }

      Great of you to stop by and comment, very much appreciated!

  4. Nan Liu says:

    Yes, sudo =), I’m putting a new pull request in today and we expect this to be in the next version of the module.

  5. Pingback: 学习Razor » 陈沙克日志

  6. keyz182 says:

    Hi, Nice guide!

    Just spotted that

    dpkg -i puppetlabs-release_1.0-3_all.deb

    needs changing to

    dpkg -i puppetlabs-release-precise.deb

    I didn’t notice, so ended up with the Ubuntu packaged puppet, and puppet module doesn’t work on that.

    /Kieran

  7. Jonas Rosland says:

    There have been some changes in the packages mentioned in this tutorial.
    First off, the “puppetlabs-tftp” package has an error, making it impossible to serve up boot images via TFTP. You can see it in /var/log/syslog like this:
    Aug 20 19:14:03 puppet in.tftpd[14596]: tftp: client does not accept options

    THIS APPLIES TO VERSION 0.2.0 of puppetlabs-tftp, not 0.1.1.
    To make it work again, you have to edit the /etc/puppet/modules/tftp/manifests/init.pp file like this:

    Edit this line:
    server_args => “${options} ${directory}”,
    To:
    server_args => “${options} -u ${username} ${directory}”,

    And edit this line:
    user => $username,
    To:
    user => ‘root’,
    And add this below the above line:
    group => ‘root’,

    Now run the following command to immediately update the tftp service:
    puppet apply /etc/puppet/modules/tftp/manifests/init.pp –verbose

    You can read more about it over at https://github.com/sileht/puppetlabs-tftp/commit/634aad0477bb3480270bc8beaaf8252bc06fcb77, and hope for it to be fixed soon so you don’t have to go through these changes yourselves.

    Big thanks to @VMTyler for catching this one.

    Apparently the new puppetlabs-razor module also installs the MK-image for you, so you don’t have to go through that step either. Even easier!🙂

  8. Doug says:

    Thanks for the “getting started” posts series. It has been very helpful in getting started with this stuff. One thing I’d note is that the dnamasq config text has “n” characters within the example text. It appears that HTML has caused a little problem and removed the backslash from each of those — they should be “\n” newline characters rather than just the letter “n”

  9. ranjitcool says:

    Nice post, I am trying to set razor to dhcp off of eth1 instead of eth0. In dnsmasq.conf – i made a change to set interface as eth1. In /etc/networking/interfaces i added eth1 and gave it a static ip of the dhcp gateway – it wont work. My other vm on that network same as the raxor dhcp eth1 network wont boot the microkernel What am i doing wrong?

    Thanks!

    • Jonas Rosland says:

      Do you have another DHCP server running on the same network? Did you make sure that the resulting dnsmasq.conf looks OK? Is the dnsmasq service started?

      • ranjitcool says:

        Thanks for the reply. I have two nics going to the ubuntu vm – one is regular network(eth0) so i can ssh to the vm while the other is configured with a ip such as 192.168.72.2/24. DHCP range in dnsmasq is 192.168.72.100-150. Interface is set to use eth1. razor restarted, dnsmasq restarted. nothing. What am i missing.. unsure – no errors thrown by linux.

      • Jonas Rosland says:

        If you want you can send me an email: firstname dot lastname at emc dot com, or follow me on twitter: @virtualswede, and we can look at your settings more in depth.

  10. Ashrith says:

    great post on getting started with razor. Thanks for the info!

  11. Michael Lozano says:

    In the section where you fix the sudo issue after installing the Puppet Agent, I couldn’t get the echo command to run (permission issues), It seems I didn’t have the ability to use sudo to fix the sudo issue.🙂 I solved this by using ‘sudo -i’ to elevate to a shell with root privileges,, running the commands, then exiting.the shell.

  12. Michael Lozano says:

    I had trouble with Part 2 because the pxe boot wanted to access the IP address the VM had before changing it to a static IP address. If you are going to change the IP address to something other than the original IP address the VM recieves from the DHCP server, I suggest changing the IP address BEFORE installing Puppet/Razor.

  13. Pingback: Homelab Rebuild – Part 2 “Process” | Professional OpenStack

  14. Justin says:

    getting puppet module install puppetlabs-razor
    is a unrecorgnised command, and when I list the help file module doesn’t exist
    puppet showing version v2.7.11

    also as a side note had to install chkconfig to ensure puppet service started on boot up

  15. Tom Blich says:

    These are great. Can you give me some hints on where/how I could change the default image that gets loaded on the system? As in how does it figure out what file systems get created, their sizes, etc?

    • Jonas Rosland says:

      Hi Tom!

      Sure, what you need to do is to make changes in the preseed/kickstart files for the OS you want to provision. Look at /opt/razor/lib/project_razor/model/ubuntu/precise/preseed.erb for Ubuntu Precis, /opt/razor/lib/project_razor/model/redhat/6/kickstart.erb for RedHat/CentOS, and so on. Have fun!

  16. For folks hoping to use this in a non-Ubuntu environment, note that with recent updates, Razor has apparently dropped support for RHEL 6 and CentOS 6. https://github.com/puppetlabs/puppetlabs-razor/issues/129

  17. Ferenc Cserepkei says:

    Hello, tried install puppet according your gude on ubuntu server/amd64 12.04.02- execution of command ‘puppet apply /etc/puppet/modules/razor/tests/init.pp –verbose’ ends up with:
    ERR! Unsupported
    ERR! Not compatible with your version of node/npm: connect@2.7.10
    ERR! Required: {“node”:”>= 0.8.0″}
    ERR! Actual: {“npm”:”1.1.4″,”node”:”0.6.12″}
    ERR!
    ERR! System Linux 3.5.0-23-generic
    ERR! command “node” “/usr/bin/npm” “install” “–global” “express”
    ERR! cwd /home/csfera/downloads
    ERR! node -v v0.6.12
    ERR! npm -v 1.1.4
    ERR! code ENOTSUP
    ERR! message Unsupported
    ERR! errno {}

    iI looks like the installer would like to see 0.8.0 version of node, but the infrastructure installed 0.6.12 before…
    How can I move forward?

  18. Sage Harvey says:

    Found another fix to the keyserver issue here: http://superuser.com/questions/300865/problem-adding-public-key-for-apt. In my case, the corporate firewall was likely the culprit blocking access to the keyserver.

  19. simon says:

    Whats about network environments where a DHCP server cant be used? Is there a solution to use razor as well?

    • Jonas Rosland says:

      Hi Simon,

      Well, I would think that you could use a MicroKernel image that is mounted on a VM or in a physical server, and has a set IP that it talks to for communication with the Razor server. The node would need to have a static IP as well, so I guess you need to have that hardcoded in there.

  20. Pingback: Puppet och Razor | wimpyfudge

  21. Amr Salah says:

    Hi jonas
    Thanks for your great effort
    I am using 3.4.1, I followed the tutorial till applying the init.pp file, but I got this error:
    puppet apply /etc/puppet/modules/razor/tests/init.pp –verbose
    Error: Could not run: Could not find file /etc/puppet/modules/razor/tests/init.pp

    The “test” directory does not exist by default, any suggestions ?

    • Jonas Rosland says:

      Please look into the new version of Razor, as the version in this blog post is no longer being heavily developed.

  22. Schorschi says:

    Same issue with newest Razor, 0.11. Test directory missing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s