Skip to content

Commit

Permalink
Recreate stopped containers if recreate flag is enabled
Browse files Browse the repository at this point in the history
If `recreate` flag is enabled we should be able to (force) recreate stopped
containers even if they're configuration isn't changed.

Signed-off-by: Roberto Alfieri <[email protected]>
  • Loading branch information
rebtoor committed Nov 27, 2023
1 parent 22e0c93 commit 7d95237
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion plugins/module_utils/podman/podman_container_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1654,7 +1654,8 @@ def make_started(self):
self.results['actions'].append('started %s' % self.container.name)
self.update_container_result()
return
elif self.container.stopped and self.container.different:
elif self.container.stopped and \
(self.container.different or self.recreate):
self.container.recreate_run()
self.results['actions'].append('recreated %s' %
self.container.name)
Expand Down
20 changes: 20 additions & 0 deletions tests/integration/targets/podman_container/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,26 @@
fail_msg: "Creating stopped container test failed!"
success_msg: "Creating stopped container test passed!"

- name: Force recreate stopped container
containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
name: container
image: alpine:3.7
state: started
command: sleep 1d
recreate: true
register: recreate_stopped

- name: Check output is correct
assert:
that:
- recreate_stopped is changed
- recreate_stopped.container is defined
- recreate_stopped.container['State']['Running']|bool
- "'recreated container' in recreate_stopped.actions"
fail_msg: Force recreate stopped test failed!
success_msg: Force recreate stopped test passed!

- name: Delete created container
containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
Expand Down

0 comments on commit 7d95237

Please sign in to comment.