---
- name: Check for Homebrew
  stat: path=/usr/local/bin/brew
  register: brew_installed

- name: Download Homebrew
  get_url: url=https://github.com/mxcl/homebrew/tarball/master dest=/tmp/homebrew.tgz
  when: not brew_installed.stat.exists

- name: Make sure /usr/local exists
  file: path=/usr/local/ state=directory mode=0775 owner=iop group=staff recurse=yes
  sudo: yes

- name: Set group to staff 
  command: chgrp -R staff {{ item }}
  sudo: yes
  with_items: 
    - /usr/local 
    - /Library/Caches/Homebrew

- name: Set permissions for multiple users
  command: chmod -R g+w {{ item }}
  sudo: yes
  with_items:
    - /usr/local 
    - /Library/Caches/Homebrew

- name: Install Homebrew
  command: 'tar xzf /tmp/homebrew.tgz --strip 1 -C /usr/local'
  sudo: yes
  when: not brew_installed.stat.exists

- name: chown homebrew stuff
  shell: "chown -R {{ ansible_ssh_user }}:admin /usr/local/"
  sudo: yes
  when: not brew_installed.stat.exists

- name: Update Homebrew
  homebrew: name=null state=absent update_homebrew=yes

---
- name: Check for Homebrew
  stat: path=/usr/local/bin/brew
  register: brew_installed

- name: Download Homebrew
  get_url: url=https://github.com/mxcl/homebrew/tarball/master dest=/tmp/homebrew.tgz
  when: not brew_installed.stat.exists

- name: Make sure Homebrew directories exist
  file: path={{ item }} state=directory mode=0775 owner=iop group=staff recurse=yes
  sudo: yes
  with_items: 
    - /usr/local 
    - /Library/Caches/Homebrew

- name: Set group to staff 
  command: chgrp -R staff {{ item }}
  sudo: yes
  with_items: 
    - /usr/local 
    - /Library/Caches/Homebrew

- name: Set permissions for multiple users
  command: chmod -R g+w {{ item }}
  sudo: yes
  with_items:
    - /usr/local 
    - /Library/Caches/Homebrew

- name: Install Homebrew
  command: 'tar xzf /tmp/homebrew.tgz --strip 1 -C /usr/local'
  sudo: yes
  when: not brew_installed.stat.exists

- name: chown homebrew stuff
  shell: "chown -R {{ ansible_ssh_user }}:admin /usr/local/"
  sudo: yes
  when: not brew_installed.stat.exists

- name: Update Homebrew
  homebrew: name=null state=absent update_homebrew=yes

Make sure Homebrew Cache directory exists before trying to modify it.
Make sure Homebrew Cache directory exists before trying to modify it.
