ansible pip module and --upgrade

13,896 views
Skip to first unread message

Jilles van Gurp

unread,
Feb 17, 2015, 1:23:10 PM2/17/15
to ansible...@googlegroups.com
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 <module>
    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: 

---
- name: Install Python Pip
  yum: name=python-pip state=latest

- name: ensure docker is installed
  yum: name=docker state=latest

- name: Install Docker-py
  pip: name=docker-py

- name: Start docker daemon
  service: name=docker state=started enabled=yes sleep=1


The problem as it turned out to be, was that pip was basically 'succeeding' with the following message:

ok: [testing.inbot.io] => {"changed": false, "cmd": "/bin/pip install docker-py", "name": "docker-py", "requirements": null, "state": "present", "stderr": "", "stdout": "Requirement already satisfied (use --upgrade to upgrade): docker-py in /usr/lib/python2.7/site-packages\nRequirement already satisfied (use --upgrade to upgrade): requests>=2.2.1,<2.5.0 in /usr/lib/python2.7/site-packages (from docker-py)\nRequirement already satisfied (use --upgrade to upgrade): six>=1.3.0 in /usr/lib/python2.7/site-packages (from docker-py)\nRequirement already satisfied (use --upgrade to upgrade): websocket-client>=0.11.0 in /usr/lib/python2.7/site-packages (from docker-py)\nRequirement already satisfied (use --upgrade to upgrade): backports.ssl-match-hostname in /usr/lib/python2.7/site-packages (from websocket-client>=0.11.0->docker-py)\nCleaning up...\n", "version": null, "virtualenv": null}

 Solution: 

sudo pip install docker-py --upgrade

After that everything works as it is supposed to.

Matt Martz

unread,
Feb 18, 2015, 9:13:35 AM2/18/15
to ansible...@googlegroups.com
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
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/fd9826b2-2520-433a-a48a-f5f39ef8af9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Matt Martz
@sivel
sivel.net

Quentin Nerden

unread,
Jul 23, 2015, 2:08:45 PM7/23/15
to Ansible Project, ma...@sivel.net
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 <module>
    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

Quentin Nerden

unread,
Jul 24, 2015, 9:25:40 AM7/24/15
to Ansible Project, ma...@sivel.net, ken...@gmail.com
I created this issue to track this: for Ansible 1.9.2 https://github.com/ansible/ansible-modules-core/issues/1792

David Karlsson

unread,
Jan 1, 2017, 9:59:04 PM1/1/17
to Ansible Project
This worked for me:

- name: Upgrade pip
  pip:
    name: pip
    extra_args: --upgrade

David Karlsson

unread,
Jan 1, 2017, 9:59:04 PM1/1/17
to Ansible Project
This worked for me:

- name: Upgrade pip
  pip:
    name: pip
    extra_args: --upgrade



Den tisdag 17 februari 2015 kl. 19:23:10 UTC+1 skrev Jilles van Gurp:
Reply all
Reply to author
Forward
0 new messages