#!/usr/bin/env ansible-playbook
---

- name: DEPLOY BENCHMARK SERVER
  hosts: bench_server
  pre_tasks:
    - name: "Fail is benchmark server is not unique"
      fail:
        msg: "Benchmark server must be unique"
      when: groups['bench_server'] | length > 1
  tags: bench_server
  roles: 
    - bench-server
  tasks:
    - name: restart bench-server
      service:
        name: bench-server
        state: restarted
      tags: [ 'never', 'prepare-bench' ]

- name: DEPLOY BENCHMARK WORKERS
  hosts: bench_worker
  tags: bench_worker
  roles: 
    - bench-worker
  tasks:
    - name: restart bench-worker
      service:
        name: bench-worker
        state: restarted
      tags: [ 'never', 'prepare-bench' ]

- name: DEPLOY ELASTIC KIBANA SERVER
  hosts: elastic
  vars:
    - es_heap_size: 2g
    - es_config:
        network.host: '{{ hostvars[groups['elastic'][0]]['ansible_default_ipv4']['address'] }}'
        node.data: true
        node.master: true
        cluster.initial_master_nodes: '{{ hostvars[groups["elastic"][0]].ansible_hostname }}'
    - kibana_server_host: "{{ hostvars[groups['elastic'][0]]['ansible_default_ipv4']['address'] }}"
    - elastic_host: "{{ es_config['network.host'] }}"
    - es_api_host: "{{ es_config['network.host'] }}"
  tags: [ 'never', 'monbench' ]
  roles:
    - elastic

- name: DEPLOY METRICBEAT WORKERS
  hosts: mediaserver,postgres
  tags: [ 'never', 'monbench' ]
  vars:
    - kibana_server_host: "{{ hostvars[groups['elastic'][0]]['ansible_default_ipv4']['address'] }}"
    - elastic_host: "{{ es_config['network.host'] }}"
    - es_api_host: "{{ es_config['network.host'] }}"
  roles:
    - metricbeat

...
