Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker_compose: fix idempotency for stopped services #159

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/159-docker_compose-idempotence-fix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "docker_compose - fix idempotence bug when using ``stopped: true`` (https://github.com/ansible-collections/community.docker/issues/142, https://github.com/ansible-collections/community.docker/pull/159)."
12 changes: 8 additions & 4 deletions plugins/modules/docker_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,12 +730,12 @@ def cmd_up(self):

if self.pull:
pull_output = self.cmd_pull()
result['changed'] = pull_output['changed']
result['changed'] |= pull_output['changed']
result['actions'] += pull_output['actions']

if self.build:
build_output = self.cmd_build()
result['changed'] = build_output['changed']
result['changed'] |= build_output['changed']
result['actions'] += build_output['actions']

if self.remove_orphans:
Expand All @@ -760,6 +760,10 @@ def cmd_up(self):
for service in self.project.services:
if not service_names or service.name in service_names:
plan = service.convergence_plan(strategy=converge)
if plan.action == 'start' and self.stopped:
# In case the only action is starting, and the user requested
# that the service should be stopped, ignore this service.
continue
if plan.action != 'noop':
result['changed'] = True
result_action = dict(service=service.name)
Expand Down Expand Up @@ -802,12 +806,12 @@ def cmd_up(self):

if self.restarted:
restart_output = self.cmd_restart(service_names)
result['changed'] = restart_output['changed']
result['changed'] |= restart_output['changed']
result['actions'] += restart_output['actions']

if self.scale:
scale_output = self.cmd_scale()
result['changed'] = scale_output['changed']
result['changed'] |= scale_output['changed']
result['actions'] += scale_output['actions']

for service in self.project.services:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@
that:
- present_1 is changed
- present_2 is changed
# - present_3 is not changed -- FIXME! https://github.com/ansible-collections/community.docker/issues/142
# - present_4 is not changed -- FIXME! https://github.com/ansible-collections/community.docker/issues/142
- present_3 is not changed
- present_4 is not changed
- started_1 is changed
- started_2 is changed
- started_3 is not changed
Expand Down