version: '2.0'

migrate_vm:
  type: direct
  input:
    - vm_id
    - command_timeout: 3600
  concurrency: 3

  output:
    stdout: <% $.ssh_stdout %>

  tasks:
    execute_command:
      action: std.ssh
      input:
        host: "{{ ssh_host }}"
        username: "{{ ssh_username }}"
        private_key: |
{{ ssh_private_key }}
        cmd: "{{ script_path }} <% $.vm_id %>"
        return_result_on_error: true
      on-complete:
        - collect_output

    collect_output:
      action: std.noop
      publish:
        ssh_stdout: <% task(execute_command).result.stdout %>
        exit_code: <% task(execute_command).result.exit_code %>
      on-complete:
        - decision_task

    decision_task:
      action: std.echo
      input:
        output: "Checking exit code..."
      on-success:
        - log_completion: <% $.exit_code = 0 %>
        - fail_workflow: <% $.exit_code != 0 %>

    fail_workflow:
      action: std.fail

    log_completion:
      action: std.noop
