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

Commit

Permalink
Merge pull request #196 from omeryahud/common-tempaltes-old-cr-fix
Browse files Browse the repository at this point in the history
[Bugfix] Failing to query for old common-templates CR fails the playbook
  • Loading branch information
omeryahud authored Jun 29, 2020
2 parents 416e4fb + d1ee4aa commit d640898
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions roles/KubevirtCommonTemplatesBundle/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,24 @@
set_fact:
templates: "{{ lookup('k8s', api_version=ct_status.results[0].result.apiVersion, kind='template') }}"

- name: Fetch old cr
block:
- set_fact:
- block:
- name: Fetch old CR
set_fact:
old_cr: "{{ lookup('k8s', api_version='kubevirt.io/v1', kind='KubevirtCommonTemplatesBundle') }}"
- set_fact:
old_cr_exists: true
rescue:
- set_fact:
old_cr_exists: false
- name: Fail if k8s lookup plugin errored
fail:
msg: "An error occured while fetching the old CR: {{ ansible_failed_result.msg }}"
when:
# This is the error that is raised when a resource is not found
# see: https://github.com/ansible-collections/community.kubernetes/blob/9fb808c7f37caea0300db1b466117ad0367db492/plugins/module_utils/common.py#L230
# this means there is no old CR to take ownership from
- '"Failed to find exact match" not in ansible_failed_result.msg'

# If the old cr exists, it would have a metadata field
- name: Check if the old CR exists
set_fact:
old_cr_exists: "{{ true if (old_cr is defined) and (old_cr.metadata | default(None)) != None else false }}"

- name: Filter for templates owned by the old cr
set_fact:
Expand Down

0 comments on commit d640898

Please sign in to comment.