Ubuntu 14.04 Server - WiFi WPA2 Personal

I suggest you set up /etc/network/interfaces something like:

auto lo
iface lo inet loopback

auto wlan0
iface wlan0 inet static
address 192.168.1.150
netmask 255.255.255.0
gateway 192.168.1.1
wpa-ssid <your_router>
wpa-psk <your_wpa_key>
dns-nameservers 8.8.8.8 192.168.1.1

Be sure to select a static address outside the range used by the DHCP server in the router, switch or other access point. Of course, substitute your details here.

Get the system to read and use the changes:

sudo ifdown wlan0 && sudo ifup -v wlan0

Did you connect?

ping -c3 192.168.1.1
ping -c3 www.google.com

I managed to connect to my WPA2 access point by putting the following in /etc/network/interfaces. Slightly modified from the accepted answer, and using DHCP.

auto wlan0
iface wlan0 inet dhcp
wpa-ssid <your_router>
wpa-psk <your_wpa_key>

Then a simple sudo ifup -v wlan0 and it connected. All good.