--- - name: APT https transport is enabled apt: name: apt-transport-https state: present tags: - metricbeat - packages - name: Elastic GPG key is installed apt_key: # url: https://artifacts.elastic.co/GPG-KEY-elasticsearch data: "{{ lookup('file', 'elasticsearch.key') }}" state: present tags: - metricbeat - packages - name: Elastic sources list is available apt_repository: repo: "deb https://artifacts.elastic.co/packages/{{ elastic_stack_version | mandatory }}/apt stable main" filename: elastic state: present update_cache: yes tags: - metricbeat - packages - name: Metricbeat is installed apt: name: metricbeat state: present tags: - metricbeat - packages - name: Metricbeat service is enabled systemd: name: metricbeat enabled: yes - name: Metricbeat knows where to find Elasticsearch lineinfile: dest: /etc/metricbeat/metricbeat.yml regexp: '^ hosts: .*' line: " hosts: [\"{{ metricbeat_elasticsearch_hosts | join('\", \"') }}\"]" insertafter: "output.elasticsearch:" notify: restart metricbeat when: - metricbeat_elasticsearch_hosts - name: Metricbeat auth/username for Elasticsearch are configured lineinfile: dest: /etc/metricbeat/metricbeat.yml regexp: '{{ item.regexp }}' line: '{{ item.line }}' insertafter: "output.elasticsearch:" with_items: - { regexp: '^ #username: .*', line: ' username: "{{ metricbeat_elasticsearch_auth_username }}"' } - { regexp: '^ #password: .*', line: ' password: "{{ metricbeat_elasticsearch_auth_password }}"' } notify: restart metricbeat when: - metricbeat_elasticsearch_auth_username != "" - metricbeat_elasticsearch_auth_password != ""