---

### tags:
###   update_deployment
###   update_connections
###   update_configurations

- name: "Creating smardigo user token"
  smardigo_user_token:
    secret:  "{{ connect_jwt_secret }}"
    user_id: "{{ connect_client_admin_username }}"
  register: smardigo_user_token_result
  delegate_to: 127.0.0.1
  become: false
  tags:
    - always

- name: "Setting smardigo_auth_token_value as fact"
  set_fact:
    smardigo_auth_token_value: "{{ smardigo_user_token_result.token }}"
  tags:
    - always

- name: "Create connect for <{{ inventory_hostname }}> if necessary"
  include_role:
    name: connect
  vars:
    # TODO override variables from connect role
    tenant_id: "{{ management_oidc_realm }}"
    cluster_name: "{{ management_oidc_client_id }}"
    connect_oidc_client_secret: "{{ management_oidc_client_secret }}"
    connect_postgres_database: "{{ stage_database_management_connect_name }}"
    connect_config_delete_scope_enabled: true
    connect_datasource_action_enabled: true
    connect_element_template_enabled: true
    connect_external_task_script_worker_enabled: true
    connect_search_elastic_enabled: true
    connect_swagger_enabled: true
    connect_workflow_heatmap_enabled: true
  tags:
    - update_deployment

- name: "Configure connect connections"
  include_tasks: connections.yml
  when:
    smardigo_auth_token_value is defined
  tags:
    - update_connections

- name: "Configure connect configurations"
  include_tasks: configurations.yml
  vars:
    local_folder_name: "/tmp/smardigo"
  when:
    smardigo_auth_token_value is defined
  tags:
    - update_configurations
