Add command_as_args option for docker_swarm_service CLI-compatible mapping (#1307)

* fix: map docker_swarm_service command/args to ContainerSpec.Args

docker service create IMAGE [COMMAND] [ARG...] places post-image tokens
into ContainerSpec.Args so the image ENTRYPOINT is preserved. The module
previously wrote command to ContainerSpec.Command, which replaced the
entrypoint and broke flag-style commands such as -config.file=...

Fixes #1044
Fixes #212

* Add command_as_args option for CLI-compatible command mapping

Keep the historical default (command -> ContainerSpec.Command,
args -> ContainerSpec.Args) to avoid a breaking change. When
command_as_args=true, map command+args to ContainerSpec.Args to
match docker service create and preserve the image ENTRYPOINT.

Update docs, examples, unit tests for both modes, and the changelog
fragment. Addresses review feedback on #1307 / #1044.

* Update changelogs/fragments/1044-swarm-service-command-args.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/docker_swarm_service.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/docker_swarm_service.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/docker_swarm_service.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/docker_swarm_service.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/docker_swarm_service.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/docker_swarm_service.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/docker_swarm_service.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update changelogs/fragments/1044-swarm-service-command-args.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: VedantMadane <vedant@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Vedant Madane
2026-08-18 01:02:57 +05:30
committed by GitHub
parent 6ae46db845
commit 2950337e48
3 changed files with 168 additions and 9 deletions
@@ -0,0 +1,10 @@
minor_changes:
- docker_swarm_service - add ``command_as_args`` option. When set to ``true``,
``command`` and ``args`` are concatenated and mapped to ``ContainerSpec.Args``
(matching ``docker service create IMAGE [COMMAND] [ARG...]``), preserving the
image ``ENTRYPOINT``. The default remains ``false`` (historical mapping of
``command`` to ``ContainerSpec.Command`` and ``args`` to ``ContainerSpec.Args``) for
backward compatibility
(https://github.com/ansible-collections/community.docker/issues/1044,
https://github.com/ansible-collections/community.docker/issues/212,
https://github.com/ansible-collections/community.docker/pull/1307).