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

**URL:** <https://forum.ansible.com/t/error-while-evaluating-conditional-when-trying-to-install-pip-for-sudo/19612>\
**Category:** Ansible Project\
**Created:** [October 26, 2015, 3:48am UTC](https://forum.ansible.com/t/error-while-evaluating-conditional-when-trying-to-install-pip-for-sudo/19612 "2015-10-26T03:48:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Kilmer](https://avatars.discourse-cdn.com/v4/letter/m/d78d45/32.png) [@Mike\_Kilmer](https://forum.ansible.com/u/Mike_Kilmer)\
**Post date:** [October 26, 2015, 3:48am UTC](https://forum.ansible.com/t/error-while-evaluating-conditional-when-trying-to-install-pip-for-sudo/19612/1 "2015-10-26T03:48:01Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![Markus\_Ellers](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Markus\_Ellers](https://forum.ansible.com/u/Markus_Ellers)\
**Post date:** [October 29, 2015, 4:57am UTC](https://forum.ansible.com/t/error-while-evaluating-conditional-when-trying-to-install-pip-for-sudo/19612/2 "2015-10-29T04:57:07Z")

</div>

Can you try running

debug: var = pip\_latest\_output

This might help getting to the bottom of it
