From 59eacfe7e26a92c09debc8c6f73f0322dbd84bc7 Mon Sep 17 00:00:00 2001 From: kpavic Date: Wed, 20 Mar 2019 18:45:44 +0100 Subject: [PATCH] Add support for template overwriting --- README.md | 1 + playbooks/group_vars/all/global.yml | 3 +++ playbooks/roles/os_temps/tasks/build_new_app.yml | 2 +- .../roles/os_temps/tasks/setup_os_templates.yml | 12 ++++++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a4c513da..541dcd37 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,7 @@ or only certain components. ex. minishift, jenkins infra, pipeline containers, * force_minishift_install: Override an existing install of minishift : default=false * force_repo_clone: Force cloning of project repo : default=false +* force_template_overwrite: Force overwriting of OpenShift templates and their resources if they already exist : default=false ## Minishift and OpenShift setup options diff --git a/playbooks/group_vars/all/global.yml b/playbooks/group_vars/all/global.yml index 9ba586de..4c1084fc 100644 --- a/playbooks/group_vars/all/global.yml +++ b/playbooks/group_vars/all/global.yml @@ -13,6 +13,9 @@ setup_playbook_hooks: false force_minishift_install: false force_repo_clone: false +# Overwrite templates and their objects if they already exist +force_template_overwrite: false + # Use General DNS in case of VPN DNS failures dns_server: 8.8.8.8 diff --git a/playbooks/roles/os_temps/tasks/build_new_app.yml b/playbooks/roles/os_temps/tasks/build_new_app.yml index a566345c..c0b54b7e 100644 --- a/playbooks/roles/os_temps/tasks/build_new_app.yml +++ b/playbooks/roles/os_temps/tasks/build_new_app.yml @@ -30,7 +30,7 @@ - name: "{{ container_config_name }} :: Wait for {{ build_config_name_files[template_name] }} to be queued" shell: "{{ oc_bin }} get builds | grep '{{ build_config_name_files[template_name] }}'" register: oc_build_result - until: oc_build_result.stdout.find(" Running ") != -1 or oc_build_result.stdout.find(" Failed ") != -1 + until: oc_build_result.stdout.find(" Running ") != -1 or oc_build_result.stdout.find(" Failed ") != -1 or oc_build_result.stdout.find(" Completed ") != -1 retries: 6 delay: 10 ignore_errors: yes diff --git a/playbooks/roles/os_temps/tasks/setup_os_templates.yml b/playbooks/roles/os_temps/tasks/setup_os_templates.yml index 8c80bc41..1909f9e8 100644 --- a/playbooks/roles/os_temps/tasks/setup_os_templates.yml +++ b/playbooks/roles/os_temps/tasks/setup_os_templates.yml @@ -17,6 +17,18 @@ - debug: msg: "{{ container_config_name }} :: Template Name from querying the cluster: {{ template_name_check.stdout }}" +- name: "{{ container_config_name }} :: The template {{ template_name }} already exists, finding the label applied to all its objects" + shell: "{{ oc_bin }} describe templates/{{ template_name_check.stdout }} | grep \"Object Labels:\" | sed 's/Object Labels:\\s*//g' | cut -f1" + register: "template_label" + when: template_name_check.stdout != "" + +- name: "{{ container_config_name }} :: The template {{ template_name }} already exists, deleting all its labeled objects so they can be recreated" + shell: "{{ oc_bin }} delete all -l {{ template_label.stdout }}" + when: + - template_name_check.stdout != "" + - template_label.stdout != "" + - force_template_overwrite|bool == true + - name: "{{ container_config_name }} :: Updating template {{ template_name }}" shell: "{{ oc_bin }} replace -f {{ template_name }}" when: template_name_check.stdout != ""