From 1d5f19eadddf6bdde5b56e72d346e630a37a68c7 Mon Sep 17 00:00:00 2001
From: Benjamin Bertrand <benjamin.bertrand@esss.se>
Date: Fri, 21 Sep 2018 16:01:39 +0200
Subject: [PATCH] Fix TowerCLIError when ztp_stack is empty

ztp_stack can be empty.
We pass it as extra vars only if it's not.
The survey of the AWX_ZTP_CONFIGURATION template shall be updated to set
the ztp_stack parameter as not required.

JIRA INFRA-547
---
 app/tasks.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/app/tasks.py b/app/tasks.py
index 42e15e2..f85b4f2 100644
--- a/app/tasks.py
+++ b/app/tasks.py
@@ -120,14 +120,15 @@ def trigger_vm_creation(name, interface, memory, cores):
 
 def trigger_ztp_configuration(host):
     """Trigger a job to generate a switch ZTP configuration"""
-    ztp_stack = ",".join([item.serial_number for item in host.stack_members()])
     extra_vars = [
         f"ztp_host={host.name}",
         f"ztp_ip={host.main_interface.ip}",
         f"ztp_mac={host.main_interface.mac}",
         f"ztp_model={host.model}",
-        f"ztp_stack='{ztp_stack}'",
     ]
+    ztp_stack = ",".join([item.serial_number for item in host.stack_members()])
+    if ztp_stack:
+        extra_vars.append(f"ztp_stack={ztp_stack}")
     job_template = current_app.config["AWX_ZTP_CONFIGURATION"]
     current_app.logger.info(
         f"Launch new job to generate ZTP configuration for {host.name} device: {job_template} with {extra_vars}"
-- 
GitLab