---
# Initial Step:
#
# Schedule a new job giving a specific topic and specifying the remote CI.
# The return of this action contains all the data associated with the job,
# we hence register those data for later consumptions
#
- hosts: localhost
  gather_facts: false
  tasks:

    - include_tasks: 'new.yml'

    - name: New
      command: echo 'new'

# Pre-run state
#
# User is free to do whaterver she needs before entering pre-run state.
# Usually this is used to spawn the undercloud vm
#
- hosts: localhost
  gather_facts: false
  tasks:
    - name: Set job state - pre-run
      dci_job:
        id: "{{ job_info.job.id }}"
        status: "pre-run"

    - name: Pre-run
      command: echo 'pre-run'

# Running state
#
# User is free to do whaterver she needs before entering running state.
# Usually this is used to provision the undercloud and the overcloud
#
- hosts: localhost
  gather_facts: false
  tasks:

    - name: Set job state - running
      dci_job:
        id: "{{ job_info.job.id }}"
        status: "running"

    - name: Running
      command: echo 'running'

# Post-run state
#
# User is free to do whaterver she needs before entering post-run state.
# Usually this is used to run tests on the overcloud
#
- hosts: localhost
  gather_facts: false
  vars:
    dci_status: 'post-run'
    dci_comment: 'Post-run state commands'
  tasks:

    - name: Set job state - post-run
      dci_job:
        id: "{{ job_info.job.id }}"
        status: "post-run"

    - name: Post-Run
      command: echo 'post-run'


# Success state
# 
# User is free to do whaterver she needs before entering pre-run state.
# Usually this is used to teardown the plateform
#
- hosts: localhost
  gather_facts: false
  tasks:
    - name: Set job state - success
      dci_job:
        id: "{{ job_info.job.id }}"
        status: "success"

    - name: Success
      command: echo 'Succes'

    - name: "Final step"
      debug:
        msg: "The job is now finished. Review the log at: {{ lookup('env','DCI_UI_URL') | default('https://www.distributed-ci.io', True) }}/jobs/{{ job_info.job.id }}/jobStates"
