2012-03-16

Configuring Django on Vagrant not including chef

In my last post the formatting was going odd so have started again.  My next job is to get Django installed on the UAT rather than a plain Ubuntu box.  You will see at the end I deferred using chef and just got the machine up and running.

I am going to try and follow Simon William’s post. I have a working server.  I also looked at this video. git was not installed on my base machine so I logged in and installed it, made a new directory and got my test software:

sudo apt-get install git
git clone
https://github.com/simeonwillbanks/vagrant-up-django-app-server.git

The syntax of the command in the Vagrant file had changed from

config.vm.forward_port “http”, 80, 8080

to

config.vm.forward_port 80, 8080

Then I needed to install chef which I hadn’t done. So trying the bootstrap knife on my local machine, and having the usual problem about verifying hosts:

C:\Users\me\chef-repo\.chef>knife bootstrap 192.168.1.7 –x me -P mypassword --sudo --no-host-key-verify

It didn’t work.  Unsure why I just installed directly on my base station using the apt-get process which worked fine and I tested it had worked with:

chef-client –-version

However I had forgotten the /etc/chef/validation.pem file which I moved with a fabric script:

def base_key():
    put(r'c:\chef\validation.pem','/home/me/validation.pem')
    run('sudo mv /home/me/validation.pem /etc/chef/validation.pem')




Then chef-client worked (don’t forget the sudo)




sudo chef-client




I had to reedit the Vagrantfile.  Vagrant up now nearly worked.  However I would get the message “The file /etc/chef/validation.pem does not contain a correctly formatted private key.”  It looked fine but I must have edited it with notepad as it had CR (Ctrl-M) at the end of each line.



Now it booted ok but it complained that it had already been registered (which it had in the last debug cycle).  At the end of the cycle I just destroyed the machine leaving the node registered on the chef server.  I need to bring the machine offline gracefully.



This command is still failing:




chef-client -c /etc/chef/client.rb -j /etc/chef/dna.json




One of my problems mois that I am building Ubuntu lucid boxes which have chef 0.09 and I am running it from a base build of Ubuntu Oneiric 11.10 with chef 0.10.  So I am going to use veewee to make a new base box.  I install veewee:




sudo gem install veewee




It didn’t go well veewee installation didn’t complete and it corrupted some gemspec files that I had to hand edit to fix.  I rebooted and my test vagrant box is working again.  I learnt one useful thing in that the Vagrantfile directory (on my base machine ~/uatbox32) is mounted as /vagrant in the vagrant virtual machine.



I mounted the VBoxGuestAdditions.iso in the client box and that eliminated one problem.  I still need to work on the chef upgrade from 0.09 to 0.10 which I did on the virtual box with:




sudo gem install chef




I hadn’t realised that chef had both clients and nodes and I needed to delete both from the chef server page after a vagrant up.  On a reboot the guest additions reverted – I should have done halt rather than destroy.  Luckily I had packaged the build so can use that as a base.



I am going back to Fabric for deployment.  A  historical chanes that might catch you out (it caught me out).  In 0.9 and later versions of fabric (I am using 1.4) Fabric uses the ‘env’ environment dictionary which used to be called config.  So any examples with config.x = are no obsolete.



I have found some nice guidance on django best practices:



http://lincolnloop.com/django-best-practices/projects.html



After a lot of mucking about I now have a working site.  The next stage is to simplify and to roll out for the dev,test,uat and prod environments.



dev is on my development machine and might do anything.



test is on production type hardware and is for testing.



uat is on production type harward and a recent backup of the production database for final acceptance.



prod is then the delivered product.

No comments: