From 9a3f6e699892e66a9893cbd31adad0bfb5a3d9e9 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 26 Nov 2020 20:40:28 +0100 Subject: kubernetes/standalone: fix config hash annotation if role is included multiple times --- roles/kubernetes/standalone/pod/tasks/main.yml | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/roles/kubernetes/standalone/pod/tasks/main.yml b/roles/kubernetes/standalone/pod/tasks/main.yml index b0644dfd..9ac6b497 100644 --- a/roles/kubernetes/standalone/pod/tasks/main.yml +++ b/roles/kubernetes/standalone/pod/tasks/main.yml @@ -44,11 +44,18 @@ set_fact: config_hash_value: "{{ config_hash_file_stat.stat.checksum }}" -- name: remove config-hash file +- name: make sure to unset config-hash value when: "'config_hash_items' not in kubernetes_standalone_pod" - file: - path: "/etc/kubernetes/config-hashes/{{ kubernetes_standalone_pod.name }}.yml" - state: absent + block: + - name: remove config-hash file + file: + path: "/etc/kubernetes/config-hashes/{{ kubernetes_standalone_pod.name }}.yml" + state: absent + + ## this is needed in case the role gets included multiple times within the same playbook + - name: set config-hash value + set_fact: + config_hash_value: - name: generate pod manifest copy: @@ -60,9 +67,9 @@ {% if 'labels' in kubernetes_standalone_pod %} labels: {{ kubernetes_standalone_pod.labels | to_nice_yaml(indent=2) | indent(4) }}{% endif %} - {% if config_hash_value is defined or 'annotations' in kubernetes_standalone_pod %} + {% if config_hash_value or 'annotations' in kubernetes_standalone_pod %} annotations: - {% if config_hash_value is defined %} + {% if config_hash_value %} config-hash: "{{ config_hash_value }}" {% endif %} {% if 'annotations' in kubernetes_standalone_pod %} -- cgit v1.2.3