def cluster_features = ['connect'] + execution.getVariable('connect-features')

def env = [
  cluster_features: cluster_features,
  cluster_name: cluster.name,
  cluster_service: cluster.service,
  cluster_size: cluster.size,
  connect_version: binding.hasVariable('connect') ? connect.version : 'latest',
  current_realm_name: tenant.key,
  current_realm_display_name: tenant.name,
  process_instance_id: execution.getProcessInstanceId(),
  scope_id: contextScopeId,
  smardigo_management_action: smardigoManagementAction,
  stage: cluster.stage,
  tenant_id: tenant.key,
  connect_client_admin_username: binding.hasVariable('connect_admin_username') ? connect_admin_username : '',
  connect_client_admin_password: binding.hasVariable('connect_admin_password') ? connect_admin_password : '',
  connect_realm_admin_username: binding.hasVariable('keycloak_admin_username') ? keycloak_admin_username : '',
  connect_realm_admin_password: binding.hasVariable('keycloak_admin_password') ? keycloak_admin_password : '',
  wordpress_admin_username: binding.hasVariable('wordpress_admin_username') ? wordpress_admin_username : '',
  wordpress_admin_password: binding.hasVariable('wordpress_admin_password') ? wordpress_admin_password : ''
]
if (binding.hasVariable('extraVariables')) {
  env << extraVariables
}

def filename = 'xvars-' + smardigoManagementAction + '-' +  execution.getProcessInstanceId() + '.yml'
def ansibleCommand= 'ansible-playbook ' + smardigoManagementAction + '.yml --vault-password-file ~/vault-pass -e "@' + filename + '"'
def ansibleVariables= 'cat <<EOT >> ' + filename + '\n'
ansibleVariables+= '---\n'
env.each { key, val ->
  if (val instanceof List) {
    ansibleVariables+= key + ':\n- \'' + val.join('\'\n- \'') + '\'\n'
  } else {
    ansibleVariables+= key + ': \'' + val + '\'\n'
  }
}
ansibleVariables+= 'EOT'

processes.byId(contextScopeId, contextProcessId).createComment(comment + ' gestartet')
processes.byId(contextScopeId, contextProcessId).createComment(ansibleVariables + '\n' + ansibleCommand)

ansibleCommand