Docker Module Improvements/Discussion

Hi All,

I’ve just jumped back on the Ansible train after spending a long time working solely with Docker and noticed a few things I felt were lacking in the Docker module. I’m not the worlds best coder, but I am contemplating a PR to make a few changes to the core docker module or, alternatively, a new ansible-modules-extra addition.

At the moment the current docker module doesn’t seem to make use of all the docker client functionality and, as far as I can tell, is only useful for making sure a container is present/absent/running etc. There doesn’t appear to be a way to perform only one part of the action (e.g. only pull the image, don’t run it). Currently in order to do most tasks I just default back to command and run docker xxxx yyyyy from there, as I can usually achieve most things that way. I’d love for it to be close to feature-par with the commandline CLI in terms of what you can/can’t do with the module on remote hosts, so here are my thoughts.

a) Make multiple modules for docker (like there currently is for the aws_* modules, though I understand it’s not quite the same). Something along the lines of:

docker_pull Self Explanitory
docker_push “”
docker_run Wraps docker [create/start/stop/kill/delete] ← pretty much what we already have
docker_exec Run ad-hoc commands inside existing containers and return results
docker_image Populate a docker_images key in system facts
docker_tag Self Explanitory
docker_inspect Return a dict describing the container/image specified

or …

b) Make each of the above separations sub-commands to a single docker module (e.g. - docker: action=pull target:myimage:latest). I’m like this one less, but I can see that the docker_image module has already been deprecated in favour of a single docker module.

So, what are your thoughts and is this something you see as worthwhile?

Cheers,
David.

I think that having separate modules works better, it makes what you
are doing more apparent and keeps the code smaller and cleaner.

Ansible allows certain modules to share code and documentation, so the
common parts can still be factored out (see ec2 modules).

Hey Brian,

Thanks for the feedback. I think I’m going to go ahead and start working
on splitting it into separate modules. I’ll see how far I get and submit a
PR to get some further feedback once I have something to show.

Cheers,
David.

David,

Do you have the work you have been doing in a branch on your fork of the repo? If so I will gladly help with parts of this. I have a direct need for docker_pull so taking what you have and spitting it out and then get features that can be used would be a upfront goal for me.

-Ph

Hey Phil,

Yeh I have docker_pull working and some initial work on docker_exec, but due to docker-py not yet returning the exit code for exec calls, I haven’t completed that one.

My fork is here: https://github.com/daviddyball/ansible-modules-extras

Gladly accepting any commits.

Cheers,
Dave