diff --git a/plugins/module_utils/podman/podman_container_lib.py b/plugins/module_utils/podman/podman_container_lib.py index f8a0f8a0..e317e2f1 100644 --- a/plugins/module_utils/podman/podman_container_lib.py +++ b/plugins/module_utils/podman/podman_container_lib.py @@ -1659,7 +1659,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) diff --git a/tests/integration/targets/podman_container/tasks/main.yml b/tests/integration/targets/podman_container/tasks/main.yml index 984dc946..f0ca1852 100644 --- a/tests/integration/targets/podman_container/tasks/main.yml +++ b/tests/integration/targets/podman_container/tasks/main.yml @@ -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') }}"