This repository was archived by the owner on Jun 12, 2023. It is now read-only.
File tree 1 file changed +16
-7
lines changed
roles/KubevirtCommonTemplatesBundle/tasks
1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change 24
24
set_fact :
25
25
templates : " {{ lookup('k8s', api_version=ct_status.results[0].result.apiVersion, kind='template') }}"
26
26
27
- - name : Fetch old cr
28
- block :
29
- - set_fact :
27
+ - block :
28
+ - name : Fetch old CR
29
+ set_fact :
30
30
old_cr : " {{ lookup('k8s', api_version='kubevirt.io/v1', kind='KubevirtCommonTemplatesBundle') }}"
31
- - set_fact :
32
- old_cr_exists : true
33
31
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 }}"
36
45
37
46
- name : Filter for templates owned by the old cr
38
47
set_fact :
You can’t perform that action at this time.
0 commit comments