---

### tags:
###   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 database for <{{ inventory_hostname }}> if necessary"
  include_role:
    name: connect_postgres
  vars:
    ansible_ssh_host: "{{ stage }}-postgres-01.{{ domain }}"

- name: "Create realm for <{{ inventory_hostname }}> if necessary"
  include_role:
    name: connect_realm

- name: "Create connect for <{{ inventory_hostname }}> if necessary"
  include_role:
    name: connect

- 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
