Skip to content
This repository was archived by the owner on Jun 12, 2023. It is now read-only.

Commit d640898

Browse files
authored
Merge pull request #196 from omeryahud/common-tempaltes-old-cr-fix
[Bugfix] Failing to query for old common-templates CR fails the playbook
2 parents 416e4fb + d1ee4aa commit d640898

File tree

1 file changed

+16
-7
lines changed
  • roles/KubevirtCommonTemplatesBundle/tasks

1 file changed

+16
-7
lines changed

roles/KubevirtCommonTemplatesBundle/tasks/main.yml

+16-7
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,24 @@
2424
set_fact:
2525
templates: "{{ lookup('k8s', api_version=ct_status.results[0].result.apiVersion, kind='template') }}"
2626

27-
- name: Fetch old cr
28-
block:
29-
- set_fact:
27+
- block:
28+
- name: Fetch old CR
29+
set_fact:
3030
old_cr: "{{ lookup('k8s', api_version='kubevirt.io/v1', kind='KubevirtCommonTemplatesBundle') }}"
31-
- set_fact:
32-
old_cr_exists: true
3331
rescue:
34-
- set_fact:
35-
old_cr_exists: false
32+
- name: Fail if k8s lookup plugin errored
33+
fail:
34+
msg: "An error occured while fetching the old CR: {{ ansible_failed_result.msg }}"
35+
when:
36+
# This is the error that is raised when a resource is not found
37+
# see: https://github.com/ansible-collections/community.kubernetes/blob/9fb808c7f37caea0300db1b466117ad0367db492/plugins/module_utils/common.py#L230
38+
# this means there is no old CR to take ownership from
39+
- '"Failed to find exact match" not in ansible_failed_result.msg'
40+
41+
# If the old cr exists, it would have a metadata field
42+
- name: Check if the old CR exists
43+
set_fact:
44+
old_cr_exists: "{{ true if (old_cr is defined) and (old_cr.metadata | default(None)) != None else false }}"
3645

3746
- name: Filter for templates owned by the old cr
3847
set_fact:

0 commit comments

Comments
 (0)