Commit graph

272 commits

Author SHA1 Message Date
Michael Schuett
0a5b7087bd Improve Message
Give user a course of action in the case where the suggestions do not
work. This will hopefully allow us to work through any further issues
much faster.
2015-11-02 10:49:24 -08:00
Michael Schuett
addbc329be Improve Error Reporting
This will hopefully help mac users be able to quickly resolve any issues
they may find when trying to use this module.
2015-11-02 10:49:24 -08:00
Michael Schuett
bf5929d32a docker_image TLS
Check commit enables using tls when using the docker_image module. It
also removes the default for docker_url which doesn't allow us to check
for DOCKER_HOST which is a more sane default. This allows you to use
docker_image on OSX but more documentation is needed.
2015-11-02 10:49:24 -08:00
Manuel Tiago Pereira
3079c5e001 Add support for legacy registries to pull_image().
Since we now have several exceptions to the assumption that the
result of the pull would be on the last status line returned by
docker-py's pull(), I've changed the function so that it looks
through the status lines and returns what if finds on it.
Despite the repeated `break`s, the code seems simpler and a little
more coherent like this. From what I've checked using
`https://github.com/jlafon/ansible-profile`, the execution time is
mostly the same.
2015-10-28 11:35:14 +00:00
Brian Coca
4c14e6267f Merge pull request #2258 from SamYaple/fix_docker_bug_2257
Don't assume ExposedPorts exists (bug #2257)
2015-10-14 11:31:06 -04:00
Adam Williamson
64b8596250 fix #2043: strip empty dict from end of 'pull' stream
When pulling an image using Docker 1.8, it seems the output
JSON stream has an empty dict at the very end. This causes
ansible to fail when pulling an image, as it's expecting a
status message in that dict which it uses to determine whether
it had to download the image or not. As a bit of an ugly hack
for that which remains backward compatible, try the last item
in the stream, and if it's an empty dict, take the last-but-one
item instead.

The strip() is needed as the exact value appears to be '{}/r/n';
we could just match that, but it seems like the kind of thing
where maybe it'd happen to just be '{}/n' or '{}' or something
in some cases, so let's just use strip() in case.
2015-10-13 22:33:46 -07:00
Sam Yaple
f15d285514 Catch the second occurance of ExposedPorts as well 2015-10-13 10:34:08 +00:00
Sam Yaple
9db5ac8e45 Don't assume ExposedPorts exists (bug #2257)
A recent change [1] in docker between v1.8.2 and v1.8.3 changed what
is returned in the json when inspecting an image. Five variables which
could have been expected before will now be omited when empty. Only
one of those variables is being addressed in the docker, ExposedPorts.

Unfortunately there was also no API version change on this so this
can't be easily corrected with pinning the API to the older version.

This does a get() which will return None if the variable is not in the
dict formed from the json that was returned. Everything else works the
same way.

[1] 9098628b29
2015-10-13 10:24:36 +00:00
Brian Coca
da1a317f7d Merge pull request #2139 from justnom/devel
Adding additional Docker log drivers.
2015-10-12 18:45:55 -04:00
Aaron Boushley
81e9d1bde5 Fix issue with comparing versions improperly.
This allows old versions of docker api to function.
2015-10-09 16:26:46 -07:00
Andrew Pashkin
cee7e928fc Add 'entrypoint' parameter to Docker module 2015-10-06 12:47:47 +03:00
Colin Hutchinson
f7aa6c4d27 make a text link into a actual hyperlink
the text link doesn't fit on some screen resolutions. Making it into sphinx hyperlink will solve that
2015-10-03 21:50:15 -04:00
Andrew Pashkin
e96549c95d Harden matching running containers by "command" in the Docker module
Before this patch:

  - Command was matched if 'Command' field of docker-py
    representation of Docker container ends with 'command' passed
    to Ansible docker module by user.
  - That can give false positives and false negatives.
  - For example:
      a) If 'command' was set up with more than one spaces,
         like 'command=sleep  123', it would be never matched again
         with a container(s) launched by this task.
         Because after launching, command would be normalized and
         appear, in docker-py API call, just as 'sleep 123' - with one
         space. This is false negative case.
      b) If 'entrypoint + command = command', for example
         'sleep + 123 = sleep 123', module would give false positive
         match.

This patch fixes it, by making matching more explicit - against
'Config'->Cmd' field of 'docker inspect' output, provided by docker-py
API and with proper normalization of user input by splitting it to
tokens with 'shlex.split()'.
2015-10-02 12:30:03 +03:00
Leonty
2080c8ab6e Support 'labels' parameter for docker. 2015-09-25 23:58:20 +03:00
justnom
518ac36878 Adding additional Docker log drivers.
Adding additional `log_driver` choices:
* journald
* gelf
* fluentd

Compatible with Docker version >= 1.8.0
2015-09-23 11:54:51 -04:00
Philippe Jandot
8052d49b07 fix regression introduced by f38186ce8b, and propose a fix for docker facts 2015-09-16 16:49:09 +02:00
David Dyball
a0a374b8ca Updated PR based on comments 2015-09-08 16:19:26 +01:00
Toshio Kuratomi
6e5a832dc2 Fix read-only usage to depend on the docker-py and docker server version 2015-09-04 15:59:19 -07:00
Toshio Kuratomi
1f358f349b We had two separate methods trying to do the same thing but neither one was complete. This merges them so that all of the options get parsed and applied. 2015-09-03 15:39:18 -07:00
Yann Hamon
8f03f1e4e1 Docker module: restarted should update the container when necessary 2015-08-26 00:01:35 +02:00
Omri Iluz
daf7a0551b No need for .keys on volumes list
Since c3f92cca21 changed "volumes" to be a list instead of a dictionary, we don't need (and cannot) .keys when appending to set.
Reported as bug #1957
2015-08-23 02:29:39 -07:00
Ilya Epifanov
d951172920 fixed memory_limit for docker api version >= 1.19 2015-08-16 18:34:56 +03:00
sebi
599d60efc0 mem_limit client version check 2015-08-06 16:46:01 +03:00
Toshio Kuratomi
1001eae3c8 Set a default value for DEFAULT_DOCKER_API_VERSION so we can create the AnsibleModule without docker-py 2015-08-03 08:44:48 -07:00
Brian Coca
c6da9d0758 added missing version_Added to extra_hosts
fixes #1843
2015-07-30 13:05:00 -04:00
Toshio Kuratomi
2785364ebe Merge pull request #1736 from larsks/bug/docker-version-parse
docker: fix parsing of docker __version__ string
2015-07-29 12:36:37 -07:00
Brian Coca
49400d90ac Merge pull request #1830 from ecliptik/devel
Fix incorrect var name for api_version
2015-07-28 18:25:20 -04:00
Micheal Waltz
b43f236b05 Fix incorrect var name for api_version 2015-07-28 15:11:33 -07:00
Brian Coca
dbdbcb33cc defined DEFAULT_DOCKER_API_VERSION to avoid it erroring out before we send the message that docker.py is missing 2015-07-27 22:33:15 -04:00
Brian Coca
44d23ababd Merge pull request #1767 from ecliptik/devel
Use proper HostConfig element which contains the proper Memory value …
2015-07-27 18:23:33 -04:00
Brian Coca
d91834bdf5 Merge pull request #1763 from larsks/bug/missing-mem-limit
restore mem_limit
2015-07-27 18:22:37 -04:00
Micheal Waltz
613fe54908 Use a if/else instead to avoid loading possibly invalid values for Memory 2015-07-23 12:17:26 -07:00
Micheal Waltz
77d1c896fe Set the API version when checking differences in containers and use
this to determine the location of the Memory value depending on the version used.

In v1.18 and earlier it was ['Config']['Memory'], but in v1.19 it
changed to ['HostConfig']['Memory'].
2015-07-23 11:34:33 -07:00
Johan Haals
1ea03e7182 ensures API compatibility for read_only containers 2015-07-23 16:45:01 +02:00
Johan Haals
851e55b55f changed version_added for read_only param
this feature will be released in 2.0
2015-07-22 08:28:16 +02:00
Johan Haals
8ec6538ad4 Merge remote-tracking branch 'upstream/devel' into docker-read-only-container 2015-07-22 08:27:35 +02:00
Christian Hammerl
b96d304b93 docker: add support to add/drop capabilities 2015-07-21 19:34:24 -04:00
Micheal Waltz
b0b1566b89 Use proper HostConfig element which contians the proper Memory value - fixes #1766 2015-07-21 12:58:58 -07:00
Lars Kellogg-Stedman
6aedc1020e restore mem_limit
mem_limit got lost in the #1744; this restores it.  Thanks to @dgromov
for the report.
2015-07-21 11:52:48 -04:00
Johan Haals
38f01b52e8 Added support for --read-only Docker containers
Adds support for mounting the container's root filesystem as read only.
2015-07-21 14:24:07 +02:00
Brian Coca
88167a5dac minor doc fixes to docker_user 2015-07-20 21:18:49 -04:00
Brian Coca
5240124525 Merge pull request #361 from simono/docker-add-user
Add option docker_user for docker module.
2015-07-20 21:17:42 -04:00
Brian Coca
030d6d645c added version_Added for new signal option in docker module 2015-07-20 20:53:59 -04:00
Brian Coca
ac28f16126 Merge pull request #1014 from nemunaire/docker-kill-signal
[Docker] Add signal parameter when killing container
2015-07-20 20:52:49 -04:00
Brian Coca
2441928484 corrected v ersion added 2015-07-20 20:09:36 -04:00
Daniel Kerwin
d4d78a1998 Too late for 1.8 2015-07-20 21:50:25 +02:00
Daniel Kerwin
a702dbd29a Switch to _cap_ver_req and add cpu_set to create_containers 2015-07-20 21:50:24 +02:00
Daniel Kerwin
a8bc50a11f Renamed to cpu_set 2015-07-20 21:48:39 +02:00
Daniel Kerwin
fca75a9705 Add support for cpusets. Requires docker-py >= 0.6.0 2015-07-20 21:48:39 +02:00
Brian Coca
cf25888e2d Merge pull request #978 from bobrik/faster-docker-updates
[docker] pulling missing docker image before doing anything
2015-07-20 15:33:32 -04:00
Maksim Losev
efb6088c27 Use HostConfig object when creating container with Docker Remote API > 1.15
This is mlosev's patch (from #1208), rebased against devel as of
2790af2.  It resolves #1707, which was caused by an API incompatibility
between the docker module and server API version 1.19.
2015-07-16 16:38:20 -04:00
Lars Kellogg-Stedman
444a2ad808 Do not erroneously mask exceptions
There was a catch-all `except` statement in `create_containers`:

        try:
            containers = do_create(count, params)
        except:
            self.pull_image()
            containers = do_create(count, params)

This would mask a variety of errors that should be exposed, including
API compatability errors (as in #1707) and common Python exceptions (KeyError, ValueError, etc) that could result from errors in the code.

This change makes the `except` statement more specific, and only attempts to pull the image and start a container if the original create attempt failed due to a 404 error from the docker API.
2015-07-16 15:25:39 -04:00
Lars Kellogg-Stedman
6672205f49 docker: permit empty or false pid
The `docker` Python module only accepts `None` or `'host'` as arguments.
This makes it difficult to conditionally set the `pid` attribute using
standard Ansible syntax.

This change converts any value that evaluates as boolean `False` to
`None`, which includes empty strings:

    pid:

As well as an explicit `false`:

    pid: false

This permits the following to work as intended:

    - hosts: localhost
      tasks:
      - name: starting container
        docker:
          docker_api_version: 1.18
          image: larsks/mini-httpd
          name: web
          pid: "{{ container_pid|default('') }}"

If `container_pid` is set to `host` somewhere, this will create a
Docker container with `pid=host`; otherwise, this will create a
container with normal isolated pid namespace.
2015-07-15 21:15:49 -04:00
Lars Kellogg-Stedman
b7e92b3e52 docker: fix parsing of docker __version__ string
If `docker.__version__` contains non-digit characters, such as:

    >>> import docker
    >>> docker.__version__
    '1.4.0-dev'

Then `get_docker_py_versioninfo` will fail with:

    ValueError: invalid literal for int() with base 10: '0-de'

This patch corrects the parsing of the version string so that
`get_docker_py_versioninfo` in this example would return:

    (1, 4, 0, '-dev')
2015-07-15 21:05:13 -04:00
Brian Coca
51b6b725cc Merge pull request #1078 from andrewgdavis/devel
ansible_facts reflects 1.8 output
2015-07-04 15:19:22 -04:00
Brian Coca
afeb3c8d07 Merge pull request #1031 from smashwilson/docker-wait
[docker] Wait for process exit on detached=no.
2015-06-30 00:24:02 -04:00
Brian Coca
5f5f01833f Merge pull request #1508 from tarrychk/issue_1442
Fix computation of port bindings
2015-06-29 23:54:27 -04:00
Brian Coca
038cc05f4e Merge pull request #1609 from smashwilson/default-net-bridge
[docker] Prevent unnecessary reloads due to the net parameter
2015-06-29 23:38:32 -04:00
Brian Coca
ec15b67712 Merge pull request #547 from steveeJ/devel
Fix bind-volumes on docker >= 1.4.0
2015-06-29 20:13:23 -04:00
Simon Olofsson
dc3161dfdd Add option docker_user for docker module.
docker_user can be used to specify the user or UID to use within the
container.
2015-06-26 00:18:56 +02:00
Ash Wilson
29e4a127e1 Default net to 'bridge' in container diff
This prevents an unnecessary reload when the `net` parameter is unspecified
(i.e. almost always).
2015-06-25 17:11:38 -05:00
Toshio Kuratomi
964d731722 Add version_added documentation to log_driver parameter 2015-06-25 08:29:42 -07:00
Toshio Kuratomi
718f32a042 Merge pull request #1405 from ryanwalls/docker-module-log-driver
Add support for --log-driver option that docker released with Docker 1.6
2015-06-25 08:25:46 -07:00
Brian Coca
19f6099777 minor doc fixes 2015-06-17 12:39:14 -04:00
Robin Roth
64fe01178f add comment: ports need to be exposed.
port mapping with this module only works for ports that are exposed either in the Dockerfile or via an additional arguments. This is different from the command line docker client, that is willing to also map ports that are not exposed.

This comments makes the behaviour more obvious.
2015-06-17 18:01:35 +02:00
Greg DeKoenigsberg
28a869a030 Updating cloud modules with proper github author information 2015-06-15 14:41:22 -04:00
Ed Hein
558f2ace1f Fix computation of port bindings. Port bindings configuration can be a list
if several host ports are bound to the same guest port.
2015-06-12 12:36:52 +02:00
Ryan Walls
a2630d40fb Fix typo in Docker module. 2015-06-02 00:09:01 -06:00
Ryan Walls
88eddb13c0 Update docker module to avoid false positives when containers are first created. Also have the module check
for api compatibility before trying to set a "--log-driver" option.
2015-06-01 09:48:24 -06:00
Ryan Walls
c95717afe5 Set default "log_driver" option to None in docker module. 2015-05-28 11:36:20 -06:00
Ryan Walls
5f1d88a829 Update docker module to look at log_driver variable when deciding if container configuration has changed. 2015-05-27 12:33:11 -06:00
Andrew Pashkin
27c174128b Add 'docker_api_version' to docker_image
By default docker-py uses latest version of Docker API. This is not
always desireable, and this patch adds option to specify version, that
should be used.
2015-05-23 23:17:30 +03:00
Ryan Walls
3f679933a6 Add support for --log-driver option that docker released with Docker 1.6 2015-05-22 16:36:38 -06:00
Pierre Baillet
06e3ac7bf4 Support optional dockerfile name 2015-05-18 16:51:12 +02:00
Toshio Kuratomi
60a66a544d Several cleanups to many modules:
* Fix docs to specify when python2.6+ is required (due to a library
  dep).  This helps us know when it is okay to use python2.6+ syntax in
  the file.
* remove BabyJson returns.  See #1211  This commit fixes all but the
  openstack modules.
* Use if __name__ == '__main__' to only run the main part of the module
  if the module is run as a program.  This allows for the potential to
  unittest the code later.
2015-05-11 12:15:53 -07:00
Ian Babrou
501a665060 Pulling missing docker image before doing anything 2015-05-07 10:25:41 +03:00
Ratnadeep Debnath
be66acb436 Fixed typo in cloud docker module. 2015-05-06 15:23:40 +05:30
Toshio Kuratomi
f444e49dfa Fix error when container has no names.
Rename loop variable from "i" to more informative "container"

Fixes #1188
2015-05-04 10:16:01 -07:00
Pascal Borreli
f29a6ec54d Fixed typos 2015-05-04 12:54:03 +01:00
Toshio Kuratomi
1fdf75d49d Second try at fixing #1227 -- set e default value earlier 2015-04-30 19:09:22 -07:00
Toshio Kuratomi
e51ea29d8f Return empty list if an image has no repo_tags 2015-04-30 17:44:05 -07:00
Toshio Kuratomi
e356692c74 Get docker's default api version definition from both 1.2 location and pre-1.2 location
Fixes #1227
2015-04-30 07:47:44 -07:00
Brian Coca
09aa79c58f Merge pull request #1102 from heiparta/extra_hosts
Add support for extra_hosts to docker module
2015-04-30 09:08:18 -04:00
Brian Coca
a811b9f12e removed deprecated docs, not true anymore 2015-04-28 16:48:28 -04:00
Toshio Kuratomi
e95c0b2df3 Only split on the first colon.
Fixes #1214
2015-04-28 08:33:50 -07:00
Heikki Partanen
91ca2d6386 Add support for extra_hosts to docker module
extra_hosts parameter (maps to --add-host in 'docker run' syntax) is used
to add host-to-ip mappings to the container.
2015-04-07 10:30:14 +03:00
Andrew Davis
f38186ce8b ansible_facts reflects 1.8 output 2015-04-03 12:41:10 -07:00
Ash Wilson
45b067f097 Record facts for each changed container. 2015-03-31 16:14:16 -04:00
Ash Wilson
b28459e6f5 Wait for process exit on detached=no. 2015-03-30 15:52:17 -04:00
Ryan Trauntvein
5320cc93e6 Specify that "state: reloaded" was added in Ansible 1.9 2015-03-27 16:36:10 -07:00
nemunaire
7f3df5634a Add optional signal parameter when killing docker container 2015-03-27 18:14:14 +01:00
Ash Wilson
9ce2fc718a Only fetch details when necessary. 2015-03-24 11:18:15 -04:00
Ash Wilson
47f4c3f2e5 Compare container images to Config.Image. 2015-03-24 11:07:12 -04:00
moncho
3421712e05 Update docker.py
Fix typo that prevents use_tls 'encrypt' option from working properly.
2015-03-19 19:30:36 +01:00
Toshio Kuratomi
76198a8223 Merge pull request #961 from nemunaire/fix-docker-version-print
[docker] Fix formating error when remote host doesn't have required version
2015-03-18 19:51:45 -07:00
Toshio Kuratomi
e338fef730 Add another valid status from downloading images 2015-03-18 18:27:01 -07:00
nemunaire
fce8c21176 Convert tuple items to string before format 2015-03-18 14:37:26 +01:00
Toshio Kuratomi
8658b82de7 Some code cleanup (removed unused variables and imports) 2015-03-16 11:58:03 -07:00
Toshio Kuratomi
34c4e0d495 Also use DOCKER_TLS_VERIFY env var to turn on tls verification 2015-03-16 11:43:52 -07:00
Toshio Kuratomi
ceda82603a Merge pull request #947 from ansible/docker-tls-none
When no use_tls is not specified and no tls parameters are given we need to not attempt tls.
2015-03-16 11:29:14 -07:00