From 73cb007ab955b97fd1d64c8c842dde90d84d0c1e Mon Sep 17 00:00:00 2001
From: Will Szumski <will@stackhpc.com>
Date: Mon, 25 Oct 2021 10:02:51 +0100
Subject: [PATCH] Do not fail when admin openrc file does not exist

Change-Id: If89bb28fa2e8cc615da21893201cc438d5b6ff05
Story: 2009323
Task: 43745
---
 ansible/roles/public-openrc/tasks/main.yml                | 2 ++
 ...-generate-openrc-when-using-tags-c8e554173e0b9ac3.yaml | 8 ++++++++
 2 files changed, 10 insertions(+)
 create mode 100644 releasenotes/notes/fix-failure-to-generate-openrc-when-using-tags-c8e554173e0b9ac3.yaml

diff --git a/ansible/roles/public-openrc/tasks/main.yml b/ansible/roles/public-openrc/tasks/main.yml
index b805e866..baee4d99 100644
--- a/ansible/roles/public-openrc/tasks/main.yml
+++ b/ansible/roles/public-openrc/tasks/main.yml
@@ -3,8 +3,10 @@
   slurp:
     src: "{{ kolla_config_path }}/admin-openrc.sh"
   register: admin_openrc
+  when: (kolla_config_path ~ '/admin-openrc.sh') is exists
 
 - name: Ensure a public OpenStack API environment file exists
   template:
     src: public-openrc.sh.j2
     dest: "{{ public_openrc_kolla_config_path }}/public-openrc.sh"
+  when: admin_openrc is not skipped
diff --git a/releasenotes/notes/fix-failure-to-generate-openrc-when-using-tags-c8e554173e0b9ac3.yaml b/releasenotes/notes/fix-failure-to-generate-openrc-when-using-tags-c8e554173e0b9ac3.yaml
new file mode 100644
index 00000000..5c564192
--- /dev/null
+++ b/releasenotes/notes/fix-failure-to-generate-openrc-when-using-tags-c8e554173e0b9ac3.yaml
@@ -0,0 +1,8 @@
+---
+fixes:
+  - |
+    ``public-openrc.sh`` is now only generated if the ``admin-openrc.sh`` file
+    generated by Kolla Ansible exists. This fixes an issue where the task would
+    fail, when running in a clean environment, with a set of Kolla Ansible tags
+    that did not include the generation of ``admin-openrc.sh``. See `story
+    2009323 <https://storyboard.openstack.org/#!/story/2009323>`__.
-- 
GitLab