From c0bf293412d4ab8aa5bee8a0b088d3d177c41b11 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?V=C3=A1clav=20Barto=C5=A1?= <bartos@cesnet.cz>
Date: Mon, 3 Oct 2022 11:20:01 +0200
Subject: [PATCH] don't fail if CentOS image already exists

If CentOS image exists, its creation is just skipped and the rest of the "buildimages" step can continue.
---
 roles/build/tasks/centos.yml | 10 ----------
 roles/build/tasks/main.yml   | 12 +++++++++++-
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/roles/build/tasks/centos.yml b/roles/build/tasks/centos.yml
index 62a8fb1..2bbb763 100644
--- a/roles/build/tasks/centos.yml
+++ b/roles/build/tasks/centos.yml
@@ -1,15 +1,5 @@
 ---
 
-- name: Check for CentOS image
-  docker_image_info:
-    name: "{{repo}}/centos:{{version}}{{suffix}}"
-  register: centosimg
-
-- name: Assert CentOS image
-  assert:
-    that: centosimg.images | length == 0
-    fail_msg: "CentOS image already exists"
-
 - name: Create etc tree in build directory
   file:
     path: '{{ temp_root}}/{{ item.path }}'
diff --git a/roles/build/tasks/main.yml b/roles/build/tasks/main.yml
index 6dd4e6c..14bd779 100644
--- a/roles/build/tasks/main.yml
+++ b/roles/build/tasks/main.yml
@@ -5,7 +5,17 @@
       - "'CHANGE_ME' not in soctoolsproxy"
     fail_msg: "Review *all* settings in group_vars/all/main.yml"
 
-- include: centos.yml
+
+# Create CentOS image if not created yet
+- name: Check for CentOS image
+  docker_image_info:
+    name: "{{repo}}/centos:{{version}}{{suffix}}"
+  register: centosimg
+
+- name: Include tasks to create CentOS image
+  include_tasks: centos.yml
+  when: centosimg.images | length == 0
+
 
 - name: Create main build dir
   file:
-- 
GitLab