def env = [
  process_instance_id: execution.getProcessInstanceId(),
  scope_id: contextScopeId,
  smardigo_management_action: smardigoManagementAction,
  stage: cluster.stage,
  database_engine: databaseEngine,
]
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