Repository: ansible/ansible-modules-core

Issue:
docker_containers
the core docker module no longer publishes ansible facts using the docker_containers variable. 



Discussion:
@smashwilson: I see where we accidentally removed this here: 80aca4b9369073d7b58ff168cf4eef8bb126c2d0

@thoughtjigs: Do you know what was in the docker_containers fact before?  It doesn't look like it was the complete list of containers.  Was it the same value that's now returned in containers (containers.changed inside of the module code) it just needs to be automatically stored in a fact?

Oh, I see, interesting. Yeah, I can take a look at adding that back in.

It looks like it was only the changed containers before the refactor, but because it's a fact, I would personally expect it to be the "inspect" results for _all_ of the running containers that match, not just the ones that were changed -- the output of `get_deployed_containers()` after the state has been applied. Does that make more sense?

It'll be easy enough to put back either way, though.

That's what I expected too but it seems like it's not what was there before.   If get_deployed_containers() turns out to be a superset of what we would have used before then I think it's fairly safe to do that (especially if we are returning just the changed containers in a different variable now).  If it's not a superset then it's a tougher call but I'd like to hear what people using the docker module want -- I don't use it enough to form an opinion on my own.

@abadger @smashwilson It was only the changed containers. As that is what my playbooks are expecting returning all containers would break my playbooks. However, it is a slightly under-documented feature ... having ansible facts returned for different collections of containers would be useful. Perhaps there could be several dictionaries of facts: docker_changed, docker_running, docker_stopped. docker_containers could continue to contain only the changed docker_container facts and be deprecated in favor of the above three. 

Additionally, providing switches for container fact gathering might be useful for large container inventories ... though I have seen no performance hit when using my dynamic docker container inventory script that gathers facts on all containers. 

I could take a look at creating a patch for this as this is critical to our playbooks (I had to revert to 1.8.4 for the time being) if that would be useful. 

Thanks

there is a docker_facts module in the queue, I would not overload this one with too many features (changed containers seems fine).


Resolving patch:
diff --git a/cloud/docker/docker.py b/cloud/docker/docker.py
--- a/cloud/docker/docker.py
+++ b/cloud/docker/docker.py
@@ -1503,7 +1503,8 @@ def main():
                          msg=manager.get_summary_message(),
                          summary=manager.counters,
                          containers=containers.changed,
-                         reload_reasons=manager.get_reload_reason_message())
+                         reload_reasons=manager.get_reload_reason_message(),
+                         ansible_facts=_ansible_facts(containers.changed))
 
     except DockerAPIError as e:
         module.fail_json(changed=manager.has_changed(), msg="Docker API Error: %s" % e.explanation)


Test patch: