From 9219aeaaebeb4b3b7b3c7aa775f94e61e44f795d Mon Sep 17 00:00:00 2001 From: Ian Babrou Date: Sun, 22 Mar 2015 14:16:02 +0300 Subject: [PATCH] Pulling missing docker image before doing anything --- lib/ansible/modules/cloud/docker/docker.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/cloud/docker/docker.py b/lib/ansible/modules/cloud/docker/docker.py index bf986250e26..94984a4b595 100644 --- a/lib/ansible/modules/cloud/docker/docker.py +++ b/lib/ansible/modules/cloud/docker/docker.py @@ -1578,10 +1578,14 @@ def main(): if count > 1 and name: module.fail_json(msg="Count and name must not be used together") - # Explicitly pull new container images, if requested. - # Do this before noticing running and deployed containers so that the image names will differ - # if a newer image has been pulled. - if pull == "always": + # Explicitly pull new container images, if requested. Do this before + # noticing running and deployed containers so that the image names + # will differ if a newer image has been pulled. + # Missing images should be pulled first to avoid downtime when old + # container is stopped, but image for new one is now downloaded yet. + # It also prevents removal of running container before realizing + # that requested image cannot be retrieved. + if pull == "always" or (state == 'reloaded' and manager.get_inspect_image() is None): manager.pull_image() containers = ContainerSet(manager)