---
- name: Verify Ansible versions
  hosts: all
  tags: always
  become: false
  run_once: true
  gather_facts: false
  tasks:
    - local_action: command ./versioncheck.py
      changed_when: false

- name: Configure ElasticSearch servers
  become: true
  hosts: logs.nimbus
  roles:
    - role: swap-file
      tags: swap-file
    - role: open-ports
      tags: open-ports
    - role: elasticsearch
      tags: elasticsearch
    - role: oauth-proxy
      tags: oauth-proxy

- name: Configure ElasticSearch servers
  become: true
  hosts: dash.nimbus
  pre_tasks:
    - name: Fetch available elasticsearch nodes
      uri:
        url: '{{ consul_catalog_url }}/service/elasticsearch?dc={{ es_lb_cluster_dc }}&tag={{ es_lb_cluster_name }}'
      register: es_services
    - name: Extract ElasticSearch hostnames
      set_fact:
        # we also need to remove our own node from the list
        es_lb_master_nodes: |
          {{ es_services.json
            | rejectattr("Node", "equalto", hostname)
            | list
            | json_query(
            '[].{
              name: Node,
              addr: ServiceAddress,
              port: to_string(ServiceMeta.cluster_port)
            }') }}
  roles:
    - role: swap-file
      tags: swap-file
    - role: open-ports
      tags: open-ports
    - role: elasticsearch-lb
      tags: elasticsearch-lb
    - role: logclean-job
      tags: logclean-job
    - role: kibana
      tags: kibana
    - role: oauth-proxy
      tags: oauth-proxy