'error while evaluating conditional' when trying to install pip for sudo

Hi all and thanks in advance for your insights.

OSX Mavericks. Ansible 1.9.4

I’ve been refactoring an ansible script to work in an EC2 instance and am a bit stuck at trying to install pip for sudo user, so as to be able to install psycopg2 for postgres-python integration.

The portion of the Task that’s causing the error is this:

  • name: check to see if pip is already installed
    command: “{{ pip }} --version”
    ignore_errors: true
    changed_when: false
    register: pip_is_installed
    changed_when: false

  • name: download pip
    get_url: url=https://bootstrap.pypa.io/get-pip.py dest={{ pip_download_dest }}
    when: pip_is_installed.rc != 0

  • name: install pip
    command: “{{ python }} {{ pip_download_dest }}/get-pip.py”
    sudo: yes
    when: pip_is_installed.rc != 0

  • name: delete get-pip.py
    file: state=absent path={{ pip_download_dest }}/get-pip.py
    when: pip_is_installed.rc != 0

$ pip --version

pip 1.5.2 from /usr/local/lib/python2.7/dist-packages (python 2.7)

  • name: check to see if pip is installed at the correct version
    shell: “{{ pip }} --version | awk ‘{print $2}’”
    register: pip_installed_version
    changed_when: false
    when: pip_version != None or pip_version != “LATEST”

  • name: install required version of pip
    command: “{{ pip }} install pip=={{ pip_version }}”
    sudo: yes
    when: pip_version != None and pip_installed_version.stdout != pip_version and pip_version != “LATEST”

  • name: Upgrade to latest version of pip
    command: “{{ pip }} install -U pip”
    register: pip_latest_output
    sudo: yes
    changed_when: pip_latest_output.stdout.find(‘Requirement already up-to-date’) == -1
    when: pip_version == None or pip_version == “LATEST”

  • name: install psycopg2 python module
    sudo: yes
    pip: name=psycopg2

And the line in bold above seems to be causing an error:

error while evaluating conditional: pip_latest_output.stdout.find('Requirement already up-to-date') == -1

From what I’m reading on a couple of GitHub issue threads, this error message can sometimes be misleading.

One thing I’m a little bit unclear on is, Ansible is running on the local deploying computer and not on the deployed to computer, right? I don’t believe ansible is installed on the remote EC2 OS.

The code looks fairly simple: if the output of running sudo pip install -U pip contains the string, ‘Requirement already up-to-date’, register as changed. Right?

Can you try running

debug: var = pip_latest_output

This might help getting to the bottom of it