- name: "Install Kibana 7"
  hosts: kb7
  tasks:
    - name: Install components and prerequisites
      include_tasks: 01_install-components.yaml

    - name: Install Kibana
      include_tasks: 02_install-kibana.yaml

    - name: Update Kibana configuration file
      lineinfile:
        path: /etc/kibana/kibana.yml
        regexp: "{{ item.regexp }}"
        line: "{{ item.line }}"
      with_items:
        - { regexp: '^server.host:', line: 'server.host: 0.0.0.0' }
        - { regexp: '^server.port:', line: 'server.port: 5601' }
        - { regexp: '^server.name:', line: 'server.name: "kb7"' }
        - { regexp: '^elasticsearch.hosts:', line: 'elasticsearch.hosts: ["http://es7-1:9200"]' }

    - name: Reload daemon
      systemd:
        daemon_reload: yes

    - name: Enable Kibana service
      systemd:
        name: kibana
        enabled: yes

    - name: Start Kibana service
      systemd:
        name: kibana
        state: restarted
