---
- name: Manage the installation of the ePAS client configuration of the swarm service
  block:
    - name: Add the label that will be used as a constraint for the data volume
      docker_node:
        hostname: '{{ epas_client_timbrature_docker_client_timbrature_data_node }}'
        labels:
          epas_client: 'timbrature'
        labels_state: 'merge'
      when: not epas_client_timbrature_data_remote_volume

    - name: Create the directory where the compose file will be placed
      file: dest={{ epas_client_timbrature_compose_dir }} state=directory owner=root group=root mode=0750

    - name: Install the docker compose file
      template: src=epas-client-timbrature-docker-compose.yml.j2 dest={{ epas_client_timbrature_compose_dir }}/docker-epas-client-timbrature-stack.yml owner=root group=root mode='0400'

    - name: Login into the IIT registry
      shell: docker login -u {{ epas_client_timbrature_docker_registry_user }} -p {{ epas_client_timbrature_docker_registry_pwd }} {{ epas_client_timbrature_docker_registry }}

    - name: Start the ePAS stack 
      docker_stack:
        name: '{{ epas_client_timbrature_stack_name }}'
        state: present
        with_registry_auth: True
        compose:
          - '{{ epas_client_timbrature_compose_dir }}/docker-epas-client-timbrature-stack.yml'

  when: docker_swarm_manager_node is defined and docker_swarm_manager_node
  tags: [ 'epas', 'epas_client', 'epas_client_timbrature' ]