CNK's blog

Chef and Linode

Chef On Linode - with ‘knife linode’

OpsCode’s VirtualBox VM seems pretty light, sudo du -sh / gives 1.1G. Can I use that image to install stuff on Linode? Or am I better off starting with Linode’s Ubuntu 12.04 LTS image? I think I probably want to start with Linode’s image. While looking for other stuff, I ran across the knife-linode plugin. Looking at the docs on the Opscode site, there seem to be configuration parameters for knife-linode that will let you create a server using one of Linode’s stock images so let’s see if I can use that to create a box.

gem install knife-linode # Got version 0.2.0

To play with it, I needed to go to the Linode “My Profile” page and create an API key. Then I can list my current servers:

knife linode server list -A <key>

And delete one:

knife linode server delete <Linode ID> -A <key>

OK so now can I create one?

$ knife linode server create -A <key> --linode-datacenter 3 \
  --linode-flavor 1 --linode-image 99 --linode-node-name cnk-ubuntu1204-knife \ 
  --ssh-user cnk --ssh-password <pass>

Linode ID: 463372
Name: cnk-ubuntu1204-knife
IPs: <ip>,192.168.x.x
Status: Being Created
Public IP: <ip>
User: cnk

Waiting for sshd
done
Boostrapping Chef on <ip>

The user doesn’t seem to have been created. So I can’t ssh in as cnk (and cnk isn’t in /etc/passwd), but I can ssh in as root. And I don’t seem to have any ruby or chef - perhaps because I didn’t choose a distro or template file. Let’s try that again - with --distro chef-full added.

That give similar output (on a new IP). But when I logged in, I still don’t have chef or ruby. In fact, there isn’t anything in /opt at all. Let’s see if I can bootstrap chef by hand.

$ knife bootstrap <ip> -A <key> --distro chef-full
Bootstrapping Chef on <ip>
Failed to authenticate root - trying password auth
Enter your password: ************

192.81.134.47 --2014-01-13 04:40:10--  https://www.opscode.com/chef/install.sh
192.81.134.47 Resolving www.opscode.com (www.opscode.com)... 184.106.28.90
192.81.134.47 Connecting to www.opscode.com (www.opscode.com)|184.106.28.90|:443... connected.
192.81.134.47 HTTP request sent, awaiting response... 200 OK
192.81.134.47 Length: 14101 (14K) [application/x-sh]
192.81.134.47 Saving to: `STDOUT'
192.81.134.47
100%[======================================>] 14,101      --.-K/s   in 0s
192.81.134.47
192.81.134.47 2014-01-13 04:40:10 (392 MB/s) - written to stdout [14101/14101]
192.81.134.47
192.81.134.47 Downloading Chef 11.8.2 for ubuntu...
192.81.134.47 downloading https://www.opscode.com/chef/metadata?v=11.8.2&prerelease=false&p=ubuntu&pv=12.04&m=x86_64
192.81.134.47   to file /tmp/install.sh.3138/metadata.txt
192.81.134.47 trying wget...
192.81.134.47 url       https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/12.04/x86_64/chef_11.8.2-1.ubuntu.12.04_amd64.deb
192.81.134.47 md5       3d3b3662830a44eeec71aadc098a4018
192.81.134.47 sha256    a5b00a24e68e29a01c7ab9de5cdaf0cc9fd1c889599ad9af70293e5b4de8615c
192.81.134.47 downloaded metadata file looks valid...
192.81.134.47 downloading https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/12.04/x86_64/chef_11.8.2-1.ubuntu.12.04_amd64.deb
192.81.134.47   to file /tmp/install.sh.3138/chef_11.8.2_amd64.deb
192.81.134.47 trying wget...
192.81.134.47 Checksum compare with sha256sum succeeded.
192.81.134.47 Installing Chef 11.8.2
192.81.134.47 installing with dpkg...
192.81.134.47 Selecting previously unselected package chef.
(Reading database ... 21184 files and directories currently installed.)
192.81.134.47 Unpacking chef (from .../chef_11.8.2_amd64.deb) ...
192.81.134.47 Setting up chef (11.8.2-1.ubuntu.12.04) ...
192.81.134.47 Thank you for installing Chef!
192.81.134.47 Starting Chef Client, version 11.8.2
192.81.134.47 Creating a new client identity for localhost using the validator key.
192.81.134.47 resolving cookbooks for run list: []
192.81.134.47 Synchronizing Cookbooks:
192.81.134.47 Compiling Cookbooks...
192.81.134.47 [2014-01-13T04:40:34+00:00] WARN: Node localhost has an empty run list.
192.81.134.47 Converging 0 resources
192.81.134.47 Chef Client finished, 0 resources updated

That seems a bit better; now we have ruby 1.9.3-p484 in /opt/chef/embedded/bin/ruby. And it came with rubygems 1.8.24, bundler (1.1.5), rake (10.1.0, 0.9.2.2), and chef (11.8.2). There are a couple of gems that have more recent versions but I decided not to try running ‘gem update’ because the installed versions may have been chosen specifically to satisfy chef dependencies.

I’ll probably want to have chef doing my updates but for now, I think I should have the server patched so ran apt-get update and apt-get upgrade by hand for now. (Before I ran the upgrade, I took a list of the packages that were installed originally with dpkg-query -W > /root/original-packages.txt so I would know what the Linode Precise Penguin image came with.)

Connecting my Linode node to Chef server

After installing chef with the knife bootstrap command, I see it tries to converge the new node. However, there is nothing in my run list - and no cookbook repository for this new server. Time to make one - and then put my Linode API configuration into the knife.rb file so I can quit passing it on the command line all the time.

UGH actually knife seems to have created a node on the server for me. Was that during knife linode server create? or during the knife bootstrap command? I can’t really tell from the docs. I should have passed -N <name> to knife linode server create so that my node would not end up named ‘localhost’ (and then when that didn’t do the bootstrapping, again send the name). From what I can tell by Googling, you can’t really rename a node, though there are delete and readd proceedures that end up being quite similar. I think I’ll try this one to get the chef node for my Linode sever named something more sensible than localhost. I skipped step 6 since I didn’t see ‘localhost’ in the /etc/chef/client.rb file. Running chef-client -N linode gave:

# chef-client -N linode
Starting Chef Client, version 11.8.2
Creating a new client identity for linode using the validator key.
resolving cookbooks for run list: []
Synchronizing Cookbooks:
Compiling Cookbooks...
[2014-01-24T06:58:34+00:00] WARN: Node linode has an empty run list.
Converging 0 resources
Chef Client finished, 0 resources updated

And now I see a node named “linode” in both the Opscode web interface and in the output of knife node list. Yeah!

Comments