---

# Parameters:
#   playbook inventory
#     stage := the name of the stage (e.g. devnso, qanso, prodnso)
#     tenant := object with tenant related data
#       key := 
#       name := 
#     cluster := object with cluster specific data (optional)
#       ...
#     data := object with action specific data (optional)
#       ...
#   smardigo message callback
#     scope_id := (scope id of the management process)
#     process_instance_id := (process instance id of the management process)
#     smardigo_management_action := (smardigo management action anme of the management process)

#############################################################
#   Creating inventory dynamically for given parameters
#############################################################

- import_playbook: pmci-inventory-cluster.yml

#############################################################
#   Deleting servers/domains for created inventory
#############################################################

- hosts: "stage_{{ stage }}"
  serial: "{{ serial_number | default(5) }}"
  gather_facts: false

  tasks:
    - name: "Delete server <{{ inventory_hostname }}>"
      include_role:
        name: hetzner-ansible-hcloud
        tasks_from: _set_server_state
      vars: 
        - server_state: "absent"

    - name: "Delete DNS entry <{{ inventory_hostname }}> for <{{ domain }}>"
      include_role:
        name: hetzner-ansible-dns
        tasks_from: _remove_dns
      vars:
        record_to_remove: '{{ inventory_hostname }}'

#############################################################
#   Sending smardigo management message to process
#############################################################

- import_playbook: pmci-callback.yml
