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.
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
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.