---

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

- import_playbook: pmci-inventory-database.yml

#############################################################
#   Creating database backups for created inventory
#############################################################

- hosts: "pmci_database_selector"
  serial: "{{ serial_number | default(1) }}"
  remote_user: root
  vars:
    database_backup_state: dump
    ansible_ssh_host: "{{ stage_server_domain }}"
    tenant_id: "{{ tenant.key }}" # legacy paramater, backwards compatibility
    cluster_name: "{{ cluster.key }}" # legacy paramater, backwards compatibility
    custom_backup_name: "backup" # legacy paramater, backwards compatibility

  roles:
    - role: connect_postgres
      when: "'connect' in group_names"

    - role: connect_wordpress_maria
      when: "'connect_wordpress' in group_names"

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

- hosts: "{{ stage }}-virtual-host-to-read-groups-vars"
  serial: "{{ serial_number | default(1) }}"
  gather_facts: false
  connection: local
  run_once: true
  vars:
    connect_jwt_username: "{{ management_admin_username }}"

  tasks:
    - name: "Sending smardigo management message to <{{ shared_service_url_management }}>"
      include_tasks: tasks/smardigo_management_message.yml
