From 52911bfc22bc2fe90a169100a71ec188c18e5635 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 31 May 2023 09:27:49 +0200 Subject: [PATCH] fix(podman-play): fix regex for pod kube recreate (#582) Signed-off-by: Simon Kuhball Co-authored-by: rwxd --- plugins/modules/podman_play.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/modules/podman_play.py b/plugins/modules/podman_play.py index 7f56f7e..beff3c7 100644 --- a/plugins/modules/podman_play.py +++ b/plugins/modules/podman_play.py @@ -132,9 +132,6 @@ except ImportError: from ansible.module_utils.basic import AnsibleModule # noqa: F402 -NAME = re.compile('name "([^"]+)" is in use') - - class PodmanKubeManagement: def __init__(self, module, executable): @@ -194,7 +191,12 @@ class PodmanKubeManagement: "No metadata in Kube file!\n%s" % pod) else: with open(self.module.params['kube_file']) as text: - re_pod = NAME.search(text.read()) + # the following formats are matched for a kube name: + # should match name field within metadata (2 or 4 spaces in front of name) + # the name can be written without quotes, in single or double quotes + # the name can contain -_ + re_pod_name = re.compile(r'^\s{2,4}name: ["|\']?(?P[\w|\-|\_]+)["|\']?', re.MULTILINE) + re_pod = re_pod_name.search(text.read()) if re_pod: pod_name = re_pod.group(1) if not pod_name: