# ansible pip module and --upgrade

**URL:** <https://forum.ansible.com/t/ansible-pip-module-and-upgrade/17537>\
**Category:** Ansible Project\
**Created:** [February 17, 2015, 6:23pm UTC](https://forum.ansible.com/t/ansible-pip-module-and-upgrade/17537 "2015-02-17T18:23:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jilles\_van\_Gurp](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@Jilles\_van\_Gurp](https://forum.ansible.com/u/Jilles_van_Gurp)\
**Post date:** [February 17, 2015, 6:23pm UTC](https://forum.ansible.com/t/ansible-pip-module-and-upgrade/17537/1 "2015-02-17T18:23:10Z")

</div>

I just ran into an obscure issue where I actually had a version of docker-py installed on a target system but not the latest version. Long version below but the tldr; is that I eventually solved it with a manual pip install --upgrade.

I was looking at the pip module documentation and there’s nothing about --upgrade there. I guess I could pass it in via extra\_args=“–upgrade” but this sounds like it deserves a bit more prominent mention. Also it sounds like it might actually be a useful default even if the user specifies no version (latest is implied) and the installed version is outdated. Either that or it should fail because it can’t get the latest version installed unless you specify --upgrade.

Long version:

So, I was getting the error that

`

Traceback (most recent call last):  
File “/home/linko/.ansible/tmp/ansible-tmp-1424196296.48-135783178760818/docker”, line 2422, in   
main()  
File “/home/linko/.ansible/tmp/ansible-tmp-1424196296.48-135783178760818/docker”, line 729, in main  
docker\_api\_version = dict(default=docker.client.DEFAULT\_DOCKER\_API\_VERSION),  
NameError: global name ‘docker’ is not defined

`

When trying to run my ansible playbook that first installs docker and then boots up a docker image. Basically it looked like I didn’t have docker-py installed; except I had.

Actually I was installing it via a docker role:

`

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [February 18, 2015, 2:13pm UTC](https://forum.ansible.com/t/ansible-pip-module-and-upgrade/17537/2 "2015-02-18T14:13:30Z")

</div>

I believe what you wanted to do with the pip module is actually provide state=latest. Omitting state just means state=present which satisfies pip if any current version is installed.

latest invokes pip with -U which is an alias for --upgrade

---

<div class="post-metadata">

**Author:** ![Quentin\_Nerden](https://avatars.discourse-cdn.com/v4/letter/q/34f0e0/32.png) [@Quentin\_Nerden](https://forum.ansible.com/u/Quentin_Nerden)\
**Post date:** [July 23, 2015, 5:29pm UTC](https://forum.ansible.com/t/ansible-pip-module-and-upgrade/17537/3 "2015-07-23T17:29:50Z")

</div>

I am running into this issue also  
On max OSX with  
ansible 1.9.2  
docker-py

I have upgraded both with:  
pip install docker-py --upgrade  
brew install ansible --upgrade

The playbook has:

- hosts: testgroup

# remote\_user: ubuntu

tasks:

- name: start container  
docker:  
name: redacted  
image: redacted/container\_redacted  
state: started

And I get:  
TASK: [start redactewd container\_redacted] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
failed: [server22] =\> {“failed”: true, “parsed”: false}  
BECOME-SUCCESS-gfuvfqhggbuflektwrxxarzyhxlmfuba  
Traceback (most recent call last):  
File “/home/user/.ansible/tmp/ansible-tmp-1437672252.13-215965289016980/docker”, line 3132, in   
main()  
File “/home/user/.ansible/tmp/ansible-tmp-1437672252.13-215965289016980/docker”, line 1436, in main  
docker\_api\_version = dict(required=False, default=DEFAULT\_DOCKER\_API\_VERSION, type=‘str’),  
NameError: global name ‘DEFAULT\_DOCKER\_API\_VERSION’ is not defined  
OpenSSH\_6.2p2, OSSLShim 0.9.8r 8 Dec 2011  
debug1: Reading configuration data /Users/nerdenq/.ssh/config  
debug1: /Users/user/.ssh/config line 3: Applying options for \*  
debug1: Reading configuration data /etc/ssh\_config  
debug1: /etc/ssh\_config line 20: Applying options for \*  
debug1: auto-mux: Trying existing master  
debug1: mux\_client\_request\_session: master session id: 2  
Shared connection to server22 closed.

FATAL: all hosts have already failed – aborting

Isn’t it normally fixed?

> <https://github.com/ansible/ansible-modules-core/issues/683>
>
> \*\*Issue Type:\*\*
> Bug Report
> 
> \*\*Ansible Version:\*\*
> 
> \`\`\`
> ansible 1.9 (devel …46b29c3f4b) last updated 2015/01/21 22:45:12 (GMT +100)
> lib/ansible/modules/core: (detached HEAD 396c399b54) last updated 2015/01/21 22:45:21 (GMT +100)
> lib/ansible/modules/extras: (detached HEAD 2396f36f11) last updated 2015/01/21 22:45:30 (GMT +100)
> v2/ansible/modules/core: (detached HEAD 8ba8f5ef4d) last updated 2015/01/21 22:45:39 (GMT +100)
> v2/ansible/modules/extras: (detached HEAD 2396f36f11) last updated 2015/01/21 22:45:45 (GMT +100)
> configured module search path = /usr/share/ansible
> \`\`\`
> 
> \*\*Environment:\*\*
> 
> \`\`\`
> Ubuntu 13.10
> Docker-py (0.7.1) 
> Docker version 1.4.1, build 5bc2ff8
> \`\`\`
> 
> \*\*Summary:\*\*
> 
> Using the docker module in a playbook and running that playbook returns the error below:
> 
> \`\`\`
> TASK: \[Run Docker private registry\] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* 
> failed: \[localhost\] =\> {"failed": true, "parsed": false}
> SUDO-SUCCESS-bomqzjizfwqbuvuvurlcknjmzfygsfvo
> Traceback (most recent call last):
> File "/home/.ansible/tmp/ansible-tmp-1421886278.27- 209846179492524/docker", line 2543, in \<module\>
> main()
> File "/home/.ansible/tmp/ansible-tmp-1421886278.27-209846179492524/docker", line 848, in main
> docker\_api\_version = dict(default=docker.client.DEFAULT\_DOCKER\_API\_VERSION),
> NameError: global name 'docker' is not defined
> FATAL: all hosts have already failed -- aborting
> 
> PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* 
> to retry, use: --limit @/home/registry.retry
> localhost : ok=2 changed=0 unreachable=0 failed=1 
> \`\`\`
> 
> \*\*Steps To Reproduce:\*\*
> 
> \`\`\`
> ---
> - name: Using ansible to update docker 
> hosts: local
> sudo: yes
> 
> tasks: 
> - name: Run Docker private registry
> docker:
> docker\_api\_version: 1.16
> image: registry
> state: running
> expose: 5000
> ports: "127.0.0.1:5000:5000"
> volumes: "~/docker/registry-storage:/var/www:ro"
> env: "STORAGE\_PATH=~/docker/registry-storage"
> \`\`\`
> 
> \*\*Expected Results:\*\*
> 
> \`\`\`
> TASK: \[Run Docker private registry\] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> ok: \[localhost\]
> \`\`\`
> 
> \*\*Actual Results:\*\*
> 
> The error thrown is already pasted in the summary section.

---

<div class="post-metadata">

**Author:** ![Quentin\_Nerden](https://avatars.discourse-cdn.com/v4/letter/q/34f0e0/32.png) [@Quentin\_Nerden](https://forum.ansible.com/u/Quentin_Nerden)\
**Post date:** [July 24, 2015, 1:25pm UTC](https://forum.ansible.com/t/ansible-pip-module-and-upgrade/17537/4 "2015-07-24T13:25:39Z")

</div>

I created this issue to track this: for Ansible 1.9.2 [https://github.com/ansible/ansible-modules-core/issues/1792](https://github.com/ansible/ansible-modules-core/issues/1792)

---

<div class="post-metadata">

**Author:** ![David\_Karlsson](https://avatars.discourse-cdn.com/v4/letter/d/a88e4f/32.png) [@David\_Karlsson](https://forum.ansible.com/u/David_Karlsson)\
**Post date:** [December 29, 2016, 3:53pm UTC](https://forum.ansible.com/t/ansible-pip-module-and-upgrade/17537/5 "2016-12-29T15:53:12Z")

</div>

This worked for me:

- name: Upgrade pip  
pip:  
name: pip  
extra\_args: --upgrade

---

<div class="post-metadata">

**Author:** ![David\_Karlsson](https://avatars.discourse-cdn.com/v4/letter/d/a88e4f/32.png) [@David\_Karlsson](https://forum.ansible.com/u/David_Karlsson)\
**Post date:** [December 29, 2016, 3:54pm UTC](https://forum.ansible.com/t/ansible-pip-module-and-upgrade/17537/6 "2016-12-29T15:54:02Z")

</div>

This worked for me:

- name: Upgrade pip  
pip:  
name: pip  
extra\_args: --upgrade
