From f8e391a0082fd1156c3e862b027029091520769c Mon Sep 17 00:00:00 2001 From: Valentin Heidelberger Date: Mon, 19 Aug 2024 15:08:35 +0200 Subject: [PATCH 1/2] recreate container if container definition has changed and restart is true Signed-off-by: Valentin Heidelberger --- plugins/module_utils/podman/podman_container_lib.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/module_utils/podman/podman_container_lib.py b/plugins/module_utils/podman/podman_container_lib.py index efecc30a..2f9a4dfb 100644 --- a/plugins/module_utils/podman/podman_container_lib.py +++ b/plugins/module_utils/podman/podman_container_lib.py @@ -1791,7 +1791,11 @@ def make_started(self): self.update_container_result() return if self.container.exists and self.restart: - if self.container.running: + if self.container.different: + self.container.recreate_run() + self.results['actions'].append('recreated %s' % + self.container.name) + elif self.container.running: self.container.restart() self.results['actions'].append('restarted %s' % self.container.name) From 832661fd122d9fd44cdc274195f9ef955554f154 Mon Sep 17 00:00:00 2001 From: Valentin Heidelberger Date: Mon, 19 Aug 2024 15:10:08 +0200 Subject: [PATCH 2/2] simplify make_started function in case a container is running, container definition has not changed and restart is not true Signed-off-by: Valentin Heidelberger --- plugins/module_utils/podman/podman_container_lib.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/plugins/module_utils/podman/podman_container_lib.py b/plugins/module_utils/podman/podman_container_lib.py index 2f9a4dfb..bb2bc95a 100644 --- a/plugins/module_utils/podman/podman_container_lib.py +++ b/plugins/module_utils/podman/podman_container_lib.py @@ -1812,13 +1812,8 @@ def make_started(self): self.container.name) self.update_container_result() return - elif self.container.running and not self.container.different: - if self.restart: - self.container.restart() - self.results['actions'].append('restarted %s' % - self.container.name) - self.update_container_result() - return + elif self.container.running and not self.container.different \ + and not self.restart: self.update_container_result(changed=False) return elif not self.container.exists: