Jinja2 block that is unreadable I have a block of Jinja2 (used in Sceptre/CloudFormation). It is not readable in my opinion, but I can't find any way to clean it up to improve it. 

{% set args = "--kubelet-extra-args '--node-labels=nodegroup=" + sceptre_user_data.node_group_name %}

{% if sceptre_user_data.node_labels != "None" %}
  {% set args = args + "," + sceptre_user_data.node_labels %}
{% endif %}

zone=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)

{% if sceptre_user_data.cni_custom_network == "Yes" %}
  {% set args = args + ",k8s.amazonaws.com/eniConfig=pod-netconfig-$zone" %}
{% endif %}

{% if sceptre_user_data.taints != "None" %}
  {% set args = args + " --register-with-taints=" + sceptre_user_data.taints %}
{% endif %}

{% set args = args + "'" %}

eval "/etc/eks/bootstrap.sh ${EKSClusterName} {{ args }}"


I tried using join filters although that seemed to make it worse.

(This has nothing to do with Flask, but is all about Jinja2 obviously. But there appears to be no Jinja2 tag.)
In the end I refactored like this:

{% set node_group_name = sceptre_user_data.node_group_name %}
{% set node_labels = sceptre_user_data.node_labels %}
{% set taints   = sceptre_user_data.taints %}
{% set cni_custom_network = sceptre_user_data.cni_custom_network %}

...

do_bootstrap() {
  {% set args = "--kubelet-extra-args '--node-labels=nodegroup=" + node_group_name %}

  {% if node_labels != "None" %}
    {% set args = args + "," + node_labels %}
  {% endif %}

  {% if cni_custom_network == "Yes" %}
    zone=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)
    {% set args = args + ",k8s.amazonaws.com/eniConfig=pod-netconfig-$zone" %}
  {% endif %}

  {% if taints != "None" %}
    {% set args = args + " --register-with-taints=" + taints %}
  {% endif %}

  {% set args = args + "'" %}

  eval "/etc/eks/bootstrap.sh ${EKSClusterName} {{ args }}"
}

do_bootstrap


I would still welcome feedback from anyone who knows a Jinja2 trick that might help that I don't know.