import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.DumperOptions

DumperOptions options = new DumperOptions();
options.setIndent(2);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setIndicatorIndent(2);
options.setIndentWithIndicator(true);

def yaml = new Yaml(options)

def parameter
switch(smardigoManagementAction) {
  case { it.contains('pmci-tenant') }: 
    parameter = [
                  stage                     : envStage, 
                  scope_id                  : contextScopeId,
                  process_instance_id       : execution.getProcessInstanceId(),
                  smardigo_management_action: smardigoManagementAction,
                  tenant                    : tenant,
                  data                      : binding.hasVariable('data') ? data : []
                ]
    break;
  case { it.contains('pmci-database') || it.contains('pmci-inventory') || it.contains('pmci-kibana') ||
         it.contains('pmci-realm')    || it.contains('pmci-server')    || it.contains('pmci-service')  }: 
    parameter = [
                  stage                     : envStage, 
                  scope_id                  : contextScopeId,
                  process_instance_id       : execution.getProcessInstanceId(),
                  smardigo_management_action: smardigoManagementAction,
                  tenant                    : tenant,
                  cluster                   : binding.hasVariable('service') ? service.cluster<<[features:service.connect_features]: [],
                  data                      : binding.hasVariable('data') ? data : []
                ]
    break;
  default: 
    parameter = [
                  stage                     : envStage, 
                  scope_id                  : contextScopeId,
                  process_instance_id       : execution.getProcessInstanceId(),
                  smardigo_management_action: smardigoManagementAction
                ]
    break;
}

def filename = 'xvars-' + smardigoManagementAction + '-' +  execution.getProcessInstanceId() + '.yml'
def ansibleCommand= 'ansible-playbook ' + smardigoManagementAction + '.yml --vault-password-file ~/vault-pass-' + envStage + ' -e "@' + filename + '"'

def ansibleVariables= 'cat &lt;&lt;EOT &gt; ' + filename + '\n'
ansibleVariables+= '---\n'
ansibleVariables+= yaml.dump(parameter)
ansibleVariables+= 'EOT'

processes.byId(contextScopeId, contextProcessId).createComment(comment + ' gestartet')
comments.create(contextScopeId, contextProcessId, '<pre>' + ansibleVariables + '\n' + ansibleCommand + '</pre>')

ansibleCommand