On of my client's servers requires nodejs for Gulp and the version in Ubuntu's repos are old (even Trusty uses version 0.10.25). I created a role in Ansible to install a more current version. I was able to get it down to just a task/main.yml file which is below. The tasks file should be easily changed to allow for other packages.

---
- name: Install Dependencies
  apt: pkg= update_cache=yes cache_valid_time=86400 state=present
  with_items:
    - gcc
    - make
    - build-essential 
- name: Download Source
  get_url: url=https://nodejs.org/dist/v/node-v.tar.gz
           dest=/usr/local/src/nodejs-.tar.gz
- name: Extract Source
  shell: tar xf /usr/local/src/nodejs-.tar.gz -C /usr/local/src
         creates=/usr/local/src/node-v
- name: Install
  command: creates=/usr/local/bin/node 
  args: 
    chdir: /usr/local/src/node-v
  with_items:
    - ./configure
    - make
    - make install

When you include this in your project you'll need to add it as roles/nodejs/tasks/main.yml and then in your playbook you can add it like this:

- {role: nodejs, nodejs_version: 4.2.1}