---
- hosts: all
  tasks:
    - name: Download Couchbase deb
      get_url: url=http://packages.couchbase.com/releases/2.2.0/couchbase-server-community_2.2.0_x86_64.deb
                 dest=~/.
    - name: Install Couchbase deb
      command: /usr/bin/dpkg -i ~/couchbase-server-community_2.2.0_x86_64.deb
                 creates=/opt/couchbase
---
- hosts: all
  tasks:
    - name: Check if Couchbase is installed
      command: /usr/bin/dpkg-query -l couchbase-server
      register: couchbase_check
      failed_when: "couchbase_check.rc not in (0, 1)"
      changed_when: False
    - name: Download Couchbase deb
      get_url: url=http://packages.couchbase.com/releases/2.2.0/couchbase-server-community_2.2.0_x86_64.deb
                 dest=~/.
      when: couchbase_check.rc == 1
    - name: Install Couchbase deb
      command: /usr/bin/dpkg -i ~/couchbase-server-community_2.2.0_x86_64.deb
      when: couchbase_check.rc == 1
Use variables to more effectively control flow
Use variables to more effectively control flow
