---
  - hosts: nodes
    become: yes
    become_user: root
    remote_user: centos

    tasks:
      - name: Check Current Leader
        shell: docker node ls | grep {{ ansible_hostname }}
        register: docker_info
        changed_when: false

      - name: Run deploy, if node is leader
        shell: docker stack deploy --compose-file /opt/monitoring/docker-compose.yml swarm_monitoring
        when:
          - "'Leader' in docker_info.stdout"
          - "'Active' in docker_info.stdout"
