├── .ruby-version ├── ansible.cfg ├── test ├── integration │ ├── helpers │ │ └── serverspec │ │ │ ├── Gemfile │ │ │ └── spec_helper.rb │ ├── standard.yml │ ├── oss.yml │ ├── standard-6x.yml │ ├── multi.yml │ ├── oss │ │ └── serverspec │ │ │ └── default_spec.rb │ ├── standard │ │ └── serverspec │ │ │ └── default_spec.rb │ ├── standard-6x │ │ └── serverspec │ │ │ └── default_spec.rb │ ├── config.yml │ ├── config │ │ └── serverspec │ │ │ └── default_spec.rb │ └── multi │ │ └── serverspec │ │ └── default_spec.rb └── matrix.yml ├── .gitignore ├── Gemfile ├── vars ├── Debian.yml ├── RedHat.yml └── main.yml ├── templates ├── beats.repo.j2 ├── beat.j2 └── beat.yml.j2 ├── handlers └── main.yml ├── defaults └── main.yml ├── tasks ├── main.yml ├── beats.yml ├── beats-param-check.yml ├── beats-redhat.yml ├── beats-config.yml └── beats-debian.yml ├── Makefile ├── LICENSE ├── meta └── main.yml ├── .ci └── jobs │ ├── elastic+ansible-beats+pull-request.yml │ ├── elastic+ansible-beats+main.yml │ └── defaults.yml ├── .github ├── issue_template.md └── stale.yml ├── Gemfile.lock ├── .kitchen.yml ├── README.md └── CHANGELOG.md /.ruby-version: -------------------------------------------------------------------------------- 1 | 2.5.7 2 | -------------------------------------------------------------------------------- /ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] -------------------------------------------------------------------------------- /test/integration/helpers/serverspec/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rspec-retry' 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .kitchen/ 2 | *.pyc 3 | .vendor 4 | .bundle 5 | Converging 6 | TODO 7 | .idea/ 8 | beats.iml 9 | Dockerfile-* -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'test-kitchen' 4 | gem 'kitchen-docker' 5 | gem 'kitchen-ansible' 6 | gem 'net-ssh' 7 | -------------------------------------------------------------------------------- /vars/Debian.yml: -------------------------------------------------------------------------------- 1 | --- 2 | default_file: "/etc/default" 3 | repo_url: "https://artifacts.elastic.co/packages/{{ beats_major_version }}/apt" 4 | -------------------------------------------------------------------------------- /vars/RedHat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | default_file: "/etc/sysconfig" 3 | repo_url: "https://artifacts.elastic.co/packages/{{ beats_major_version }}/yum" 4 | -------------------------------------------------------------------------------- /templates/beats.repo.j2: -------------------------------------------------------------------------------- 1 | [beats] 2 | name=Elastic Beats Repository 3 | baseurl={{ repo_url }} 4 | enabled=1 5 | gpgkey={{ elastic_repo_key }} 6 | gpgcheck=1 7 | -------------------------------------------------------------------------------- /vars/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # vars file for beats 3 | 4 | beats_package_url: "https://download.elastic.co/beats" 5 | elastic_repo_key: "https://packages.elastic.co/GPG-KEY-elasticsearch" 6 | -------------------------------------------------------------------------------- /templates/beat.j2: -------------------------------------------------------------------------------- 1 | ################################ 2 | # {{beat}} 3 | ################################ 4 | 5 | # Beats PID File 6 | PIDFILE={{pid_file}} 7 | DAEMON_ARGS="-c {{conf_file}} {{daemon_args}}" 8 | -------------------------------------------------------------------------------- /test/matrix.yml: -------------------------------------------------------------------------------- 1 | --- 2 | OS: 3 | - ubuntu-1604 4 | - ubuntu-1804 5 | - ubuntu-2004 6 | - debian-8 7 | - debian-9 8 | - debian-10 9 | - centos-7 10 | - amazonlinux-2 11 | TEST_TYPE: 12 | - standard 13 | - standard-6x 14 | - multi 15 | - config 16 | - oss 17 | -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # handlers file for beats 3 | 4 | - name: restart the service 5 | become: yes 6 | service: 7 | name: "{{ beat_product }}" 8 | state: restarted 9 | enabled: true 10 | when: start_service and restart_on_change and not beats_started.changed 11 | -------------------------------------------------------------------------------- /test/integration/helpers/serverspec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'serverspec' 2 | set :backend, :exec 3 | 4 | require 'rspec/retry' 5 | 6 | RSpec.configure do |config| 7 | # show retry status in spec process 8 | config.verbose_retry = true 9 | # show exception that triggers a retry if verbose_retry is set to true 10 | config.display_try_failure_messages = true 11 | end -------------------------------------------------------------------------------- /test/integration/standard.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: wrapper playbook for kitchen testing "beats" 3 | hosts: localhost 4 | roles: 5 | - role: ansible-beats 6 | beat: filebeat 7 | beat_conf: 8 | filebeat: 9 | inputs: 10 | - paths: 11 | - /var/log/*.log 12 | type: log 13 | vars: 14 | use_repository: true 15 | -------------------------------------------------------------------------------- /test/integration/oss.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: wrapper playbook for kitchen testing "beats" 3 | hosts: localhost 4 | roles: 5 | - role: ansible-beats 6 | beat: filebeat 7 | beat_conf: 8 | filebeat: 9 | inputs: 10 | - paths: 11 | - /var/log/*.log 12 | type: log 13 | vars: 14 | use_repository: true 15 | oss_version: true 16 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # defaults file for beats 3 | beats_version: 7.17.0 4 | oss_version: false 5 | version_lock: false 6 | use_repository: true 7 | beats_add_repository: "{{ use_repository }}" 8 | start_service: true 9 | restart_on_change: true 10 | daemon_args: "" 11 | logging_conf: {"files":{"rotateeverybytes":10485760}} 12 | output_conf: {"elasticsearch":{"hosts":["localhost:9200"]}} 13 | beats_pid_dir: "/var/run" 14 | beats_conf_dir: "/etc/{{beat}}" 15 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # tasks file for beats 3 | 4 | - name: check-parameters 5 | include_tasks: beats-param-check.yml 6 | 7 | - name: define beat product 8 | set_fact: 9 | beat_product: "{{ beat }}" 10 | 11 | - name: os-specific vars 12 | include_vars: '{{ ansible_os_family }}.yml' 13 | 14 | - include_tasks: beats.yml 15 | 16 | - name: Force all notified handlers to run at this point, not waiting for normal sync points 17 | meta: flush_handlers 18 | -------------------------------------------------------------------------------- /test/integration/standard-6x.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: wrapper playbook for kitchen testing "beats" 3 | hosts: localhost 4 | roles: 5 | - role: ansible-beats 6 | beat: filebeat 7 | beat_conf: 8 | filebeat: 9 | prospectors: 10 | - paths: 11 | - /var/log/*.log 12 | input_type: log 13 | registry_file: /var/lib/filebeat/registry 14 | vars: 15 | beats_version: 6.8.23 16 | use_repository: "true" 17 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | default: build 2 | 3 | SHELL:=/bin/bash -eux 4 | PATTERN := standard-ubuntu-1804 5 | 6 | .PHONY: converge verify test login destroy list 7 | 8 | setup: 9 | bundle install 10 | docker ps 11 | 12 | converge: 13 | bundle exec kitchen converge $(PATTERN) 14 | 15 | verify: 16 | bundle exec kitchen verify $(PATTERN) 17 | 18 | test: 19 | bundle exec kitchen test $(PATTERN) --destroy=always 20 | 21 | login: 22 | bundle exec kitchen login $(PATTERN) 23 | 24 | destroy: 25 | bundle exec kitchen destroy $(PATTERN) 26 | 27 | destroy-all: 28 | bundle exec kitchen destroy 29 | 30 | list: 31 | bundle exec kitchen list 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012-2016 Elasticsearch 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | allow_duplicates: true 3 | dependencies: [] 4 | galaxy_info: 5 | role_name: beats 6 | author: Dale McDiarmid 7 | description: Beats for Linux 8 | company: "Elastic.co" 9 | issue_tracker_url: https://github.com/elastic/ansible-beats/issues 10 | license: "license (Apache)" 11 | min_ansible_version: 2.5 12 | platforms: 13 | - name: EL 14 | versions: 15 | - 7 16 | - 8 17 | - name: Debian 18 | versions: 19 | - all 20 | - name: Ubuntu 21 | versions: 22 | - all 23 | galaxy_tags: 24 | - beats 25 | - elastic 26 | - elk 27 | - logging 28 | - monitoring 29 | -------------------------------------------------------------------------------- /tasks/beats.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Install OS specific beats 3 | 4 | - name: Include specific Beats 5 | include_tasks: beats-debian.yml 6 | when: ansible_os_family == 'Debian' 7 | 8 | - name: Include specific Beats 9 | include_tasks: beats-redhat.yml 10 | when: ansible_os_family == 'RedHat' 11 | 12 | # Configuration file for beats 13 | - name: Beats configuration 14 | include_tasks: beats-config.yml 15 | 16 | # Make sure the service is started, and restart if necessary 17 | - name: Start {{ beat_product }} service 18 | become: yes 19 | service: 20 | name: '{{ beat }}' 21 | state: started 22 | enabled: true 23 | when: start_service 24 | register: beats_started 25 | -------------------------------------------------------------------------------- /tasks/beats-param-check.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Check beat variable 3 | fail: 4 | msg: "beat must be specified and cannot be blank e.g. filebeat" 5 | when: beat is not defined or (beat | length == 0) 6 | 7 | - name: Check beat_conf variable 8 | fail: 9 | msg: "beat_conf must be specified" 10 | when: beat_conf is not defined 11 | 12 | - name: Check ILM variables 13 | fail: 14 | msg: "beat_conf.setup.ilm.policy_file must be specified if default_ilm_policy is used" 15 | when: default_ilm_policy is defined and beat_conf.setup.ilm.policy_file is not defined 16 | 17 | - name: Set beats_major_version 18 | set_fact: 19 | beats_major_version: '{% if oss_version %}oss-{% endif %}{{ beats_version.split(".")[0] }}.x' 20 | -------------------------------------------------------------------------------- /test/integration/multi.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: wrapper playbook for kitchen testing "beats" 3 | hosts: localhost 4 | roles: 5 | - role: ansible-beats 6 | beat: filebeat 7 | beat_conf: 8 | filebeat: 9 | inputs: 10 | - paths: 11 | - /var/log/*.log 12 | type: log 13 | - role: ansible-beats 14 | beat: metricbeat 15 | beat_conf: 16 | metricbeat: 17 | modules: 18 | - module: "system" 19 | metricsets: 20 | - cpu 21 | - filesystem 22 | - network 23 | - process 24 | enabled: true 25 | period: 10s 26 | processes: [".*"] 27 | cpu_ticks: false 28 | vars: 29 | use_repository: true 30 | -------------------------------------------------------------------------------- /templates/beat.yml.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | ################### {{beat}} Configuration ######################### 4 | 5 | ############################# {{beat}} ###################################### 6 | {{ beat_conf | to_nice_yaml(indent=2) }} 7 | 8 | ############################################################################### 9 | ############################# Libbeat Config ################################## 10 | # Base config file used by all other beats for using libbeat features 11 | 12 | ############################# Output ########################################## 13 | 14 | {{ beat_output_conf | to_nice_yaml(indent=2) }} 15 | 16 | {% if shipper_conf is defined %}############################# Shipper ######################################### 17 | 18 | {{ beat_shipper_conf | to_nice_yaml(indent=2) }} 19 | {% endif %} 20 | ############################# Logging ######################################### 21 | 22 | {{ beat_logging_conf | to_nice_yaml(indent=2) }} 23 | -------------------------------------------------------------------------------- /.ci/jobs/elastic+ansible-beats+pull-request.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - job: 3 | name: elastic+ansible-beats+pull-request 4 | display-name: elastic / ansible-beats - pull-request 5 | description: Pull request testing with test kitchen 6 | parameters: [] 7 | scm: 8 | - git: 9 | branches: 10 | - $ghprbActualCommit 11 | refspec: +refs/pull/*:refs/remotes/origin/pr/* 12 | triggers: 13 | - github-pull-request: 14 | github-hooks: true 15 | org-list: 16 | - elastic 17 | allow-whitelist-orgs-as-admins: true 18 | cancel-builds-on-update: true 19 | status-context: devops-ci 20 | builders: 21 | - shell: |- 22 | #!/usr/local/bin/runbld 23 | set -euo pipefail 24 | 25 | export RBENV_VERSION='2.5.7' 26 | export PATH="$HOME/.rbenv/bin:$PATH" 27 | eval "$(rbenv init -)" 28 | rbenv local $RBENV_VERSION 29 | 30 | make setup 31 | make verify PATTERN=$TEST_TYPE-$OS 32 | -------------------------------------------------------------------------------- /.ci/jobs/elastic+ansible-beats+main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - job: 3 | name: elastic+ansible-beats+main 4 | display-name: elastic / ansible-beats - main 5 | description: Main branch testing with test kitchen 6 | scm: 7 | - git: 8 | branches: 9 | - refs/heads/main 10 | triggers: 11 | - timed: H H(02-04) * * * 12 | builders: 13 | - shell: |- 14 | #!/usr/local/bin/runbld 15 | set -euo pipefail 16 | 17 | export RBENV_VERSION='2.5.7' 18 | export PATH="$HOME/.rbenv/bin:$PATH" 19 | eval "$(rbenv init -)" 20 | rbenv local $RBENV_VERSION 21 | 22 | make setup 23 | make verify PATTERN=$TEST_TYPE-$OS 24 | publishers: 25 | - slack: 26 | notify-back-to-normal: True 27 | notify-every-failure: True 28 | room: infra-release-notify 29 | team-domain: elastic 30 | auth-token-id: release-slack-integration-token 31 | auth-token-credential-id: release-slack-integration-token 32 | -------------------------------------------------------------------------------- /test/integration/oss/serverspec/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'Open Source Tests' do 4 | 5 | describe service('filebeat') do 6 | it { should be_running } 7 | end 8 | 9 | describe package('filebeat') do 10 | it { should be_installed } 11 | end 12 | 13 | describe file('/etc/filebeat/filebeat.yml') do 14 | it { should be_file } 15 | it { should be_owned_by 'root' } 16 | end 17 | 18 | describe file('/etc/filebeat/filebeat.yml') do 19 | it { should contain 'filebeat:' } 20 | it { should contain 'logging:' } 21 | it { should contain 'output:' } 22 | end 23 | 24 | describe file('/etc/init.d/filebeat') do 25 | it { should exist } 26 | end 27 | 28 | if os[:family] == 'redhat' 29 | describe command('yum versionlock list | grep filebeat') do 30 | its(:stdout) { should_not match /filebeat/ } 31 | end 32 | elsif ['debian', 'ubuntu'].include?(os[:family]) 33 | describe command('sudo apt-mark showhold | grep filebeat') do 34 | its(:stdout) { should_not match /filebeat/ } 35 | end 36 | end 37 | 38 | end 39 | 40 | -------------------------------------------------------------------------------- /test/integration/standard/serverspec/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'Standard Tests' do 4 | 5 | describe service('filebeat') do 6 | it { should be_running } 7 | end 8 | 9 | describe package('filebeat') do 10 | it { should be_installed } 11 | end 12 | 13 | describe file('/etc/filebeat/filebeat.yml') do 14 | it { should be_file } 15 | it { should be_owned_by 'root' } 16 | end 17 | 18 | describe file('/etc/filebeat/filebeat.yml') do 19 | it { should contain 'filebeat:' } 20 | it { should contain 'logging:' } 21 | it { should contain 'output:' } 22 | end 23 | 24 | describe file('/etc/init.d/filebeat') do 25 | it { should exist } 26 | end 27 | 28 | if os[:family] == 'redhat' 29 | describe command('yum versionlock list | grep filebeat') do 30 | its(:stdout) { should_not match /filebeat/ } 31 | end 32 | elsif ['debian', 'ubuntu'].include?(os[:family]) 33 | describe command('sudo apt-mark showhold | grep filebeat') do 34 | its(:stdout) { should_not match /filebeat/ } 35 | end 36 | end 37 | 38 | end 39 | 40 | -------------------------------------------------------------------------------- /test/integration/standard-6x/serverspec/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'Standard Tests' do 4 | 5 | describe service('filebeat') do 6 | it { should be_running } 7 | end 8 | 9 | describe package('filebeat') do 10 | it { should be_installed } 11 | end 12 | 13 | describe file('/etc/filebeat/filebeat.yml') do 14 | it { should be_file } 15 | it { should be_owned_by 'root' } 16 | end 17 | 18 | describe file('/etc/filebeat/filebeat.yml') do 19 | it { should contain 'filebeat:' } 20 | it { should contain 'logging:' } 21 | it { should contain 'output:' } 22 | end 23 | 24 | describe file('/etc/init.d/filebeat') do 25 | it { should exist } 26 | end 27 | 28 | if os[:family] == 'redhat' 29 | describe command('yum versionlock list | grep filebeat') do 30 | its(:stdout) { should_not match /filebeat/ } 31 | end 32 | elsif ['debian', 'ubuntu'].include?(os[:family]) 33 | describe command('sudo apt-mark showhold | grep filebeat') do 34 | its(:stdout) { should_not match /filebeat/ } 35 | end 36 | end 37 | 38 | end 39 | 40 | -------------------------------------------------------------------------------- /test/integration/config.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Install specific version here 3 | - name: wrapper playbook for kitchen testing beats 4 | hosts: localhost 5 | roles: 6 | - role: ansible-beats 7 | beat: packetbeat 8 | version_lock: true 9 | beat_conf: 10 | interfaces: 11 | device: any 12 | protocols: 13 | dns: 14 | ports: 15 | - 53 16 | include_authorities: true 17 | http: 18 | ports: 19 | - 80 20 | - 8080 21 | - 8000 22 | - 5000 23 | - 8002 24 | memcache: 25 | ports: 26 | - 11211 27 | mysql: 28 | ports: 29 | - 3306 30 | pgsql: 31 | ports: 32 | - 5432 33 | redis: 34 | ports: 35 | - 6379 36 | thrift: 37 | ports: 38 | - 9090 39 | mongodb: 40 | ports: 41 | - 27017 42 | output_conf: 43 | elasticsearch: 44 | hosts: ["localhost:9200"] 45 | vars: 46 | use_repository: true 47 | -------------------------------------------------------------------------------- /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 | **Describe the feature**: 22 | 23 | 24 | 25 | **Beats product**: 26 | 27 | **Beats version** 28 | 29 | **Role version**: (If using main please specify github sha) 30 | 31 | **OS version** (`uname -a` if on a Unix-like system): 32 | 33 | **Description of the problem including expected versus actual behaviour**: 34 | 35 | **Playbook**: 36 | Please specify the full playbook used to reproduce this issue. 37 | 38 | **Provide logs from Ansible**: 39 | 40 | **Beats logs if relevant**: 41 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Number of days of inactivity before an issue becomes stale 3 | daysUntilStale: 90 4 | 5 | # Number of days of inactivity before an stale issue is closed 6 | daysUntilClose: 30 7 | 8 | # Label to use when marking an issue as stale 9 | staleLabel: triage/stale 10 | 11 | issues: 12 | # Comment to post when marking an issue as stale. 13 | markComment: > 14 | This issue has been automatically marked as stale because it has not had 15 | recent activity. It will be closed if no further activity occurs. Thank 16 | you for your contributions. 17 | # Comment to post when closing a stale issue. 18 | closeComment: > 19 | This issue has been automatically closed because it has not had recent 20 | activity since being marked as stale. 21 | pulls: 22 | # Comment to post when marking a PR as stale. 23 | markComment: > 24 | This PR has been automatically marked as stale because it has not had 25 | recent activity. It will be closed if no further activity occurs. Thank you 26 | for your contributions. 27 | 28 | To track this PR (even if closed), please open a corresponding issue if one 29 | does not already exist. 30 | # Comment to post when closing a stale PR. 31 | closeComment: > 32 | This PR has been automatically closed because it has not had recent 33 | activity since being marked as stale. 34 | 35 | Please reopen when work resumes. 36 | -------------------------------------------------------------------------------- /test/integration/config/serverspec/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'Config Tests' do 4 | 5 | describe service('packetbeat') do 6 | it { should be_running } 7 | end 8 | 9 | describe package('packetbeat') do 10 | it { should be_installed } 11 | end 12 | 13 | describe file('/etc/packetbeat/packetbeat.yml') do 14 | it { should be_file } 15 | it { should be_owned_by 'root' } 16 | end 17 | 18 | describe file('/etc/packetbeat/packetbeat.yml') do 19 | it { should contain 'logging:' } 20 | it { should contain 'output:' } 21 | it { should contain 'protocols:' } 22 | it { should contain 'dns:' } 23 | it { should contain 'memcache:' } 24 | it { should contain 'http:' } 25 | it { should contain 'mongodb:' } 26 | it { should contain 'mysql:' } 27 | it { should contain 'pgsql:' } 28 | it { should contain 'redis:' } 29 | it { should contain 'thrift:' } 30 | it { should contain 'interfaces:' } 31 | it { should contain 'device: any' } 32 | end 33 | 34 | describe file('/etc/init.d/packetbeat') do 35 | it { should exist } 36 | end 37 | 38 | if os[:family] == 'redhat' 39 | describe command('yum versionlock list | grep packetbeat') do 40 | its(:stdout) { should match /packetbeat/ } 41 | end 42 | elsif ['debian', 'ubuntu'].include?(os[:family]) 43 | describe command('sudo apt-mark showhold | grep packetbeat') do 44 | its(:stdout) { should match /packetbeat/ } 45 | end 46 | end 47 | 48 | end 49 | 50 | -------------------------------------------------------------------------------- /test/integration/multi/serverspec/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'Multi Tests' do 4 | 5 | describe service('filebeat') do 6 | it { should be_running } 7 | end 8 | 9 | describe package('filebeat') do 10 | it { should be_installed } 11 | end 12 | 13 | describe file('/etc/filebeat/filebeat.yml') do 14 | it { should be_file } 15 | it { should be_owned_by 'root' } 16 | end 17 | 18 | describe file('/etc/filebeat/filebeat.yml') do 19 | it { should contain 'filebeat:' } 20 | it { should contain 'logging:' } 21 | it { should contain 'output:' } 22 | end 23 | 24 | describe file('/etc/init.d/filebeat') do 25 | it { should exist } 26 | end 27 | 28 | describe service('metricbeat') do 29 | it { should be_running } 30 | end 31 | 32 | describe package('metricbeat') do 33 | it { should be_installed } 34 | end 35 | 36 | describe file('/etc/metricbeat/metricbeat.yml') do 37 | it { should be_file } 38 | it { should be_owned_by 'root' } 39 | end 40 | 41 | describe file('/etc/metricbeat/metricbeat.yml') do 42 | it { should contain 'module: system' } 43 | it { should contain 'metricsets:' } 44 | it { should contain 'period: 10s' } 45 | it { should contain 'processes:' } 46 | it { should contain 'cpu_ticks:' } 47 | it { should contain 'logging:' } 48 | it { should contain 'output:' } 49 | end 50 | 51 | describe file('/etc/init.d/metricbeat') do 52 | it { should exist } 53 | end 54 | 55 | 56 | end 57 | 58 | -------------------------------------------------------------------------------- /.ci/jobs/defaults.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | ##### GLOBAL METADATA 4 | 5 | - meta: 6 | cluster: devops-ci 7 | 8 | ##### JOB DEFAULTS 9 | 10 | - job: 11 | project-type: matrix 12 | logrotate: 13 | daysToKeep: 30 14 | numToKeep: 100 15 | parameters: 16 | - string: 17 | name: branch_specifier 18 | default: main 19 | description: the Git branch specifier to build (<branchName>, <tagName>, 20 | <commitId>, etc.) 21 | properties: 22 | - github: 23 | url: https://github.com/elastic/ansible-beats/ 24 | - inject: 25 | properties-content: HOME=$JENKINS_HOME 26 | concurrent: true 27 | node: master 28 | scm: 29 | - git: 30 | name: origin 31 | credentials-id: f6c7695a-671e-4f4f-a331-acdce44ff9ba 32 | reference-repo: /var/lib/jenkins/.git-references/ansible-beats.git 33 | branches: 34 | - ${branch_specifier} 35 | url: git@github.com:elastic/ansible-beats.git 36 | basedir: ansible-beats 37 | wipe-workspace: 'False' 38 | axes: 39 | - axis: 40 | type: slave 41 | name: label 42 | values: 43 | - linux 44 | - axis: 45 | name: OS 46 | filename: ansible-beats/test/matrix.yml 47 | type: yaml 48 | - axis: 49 | name: TEST_TYPE 50 | filename: ansible-beats/test/matrix.yml 51 | type: yaml 52 | wrappers: 53 | - ansicolor 54 | - timeout: 55 | type: absolute 56 | timeout: 360 57 | fail: true 58 | - timestamps 59 | -------------------------------------------------------------------------------- /tasks/beats-redhat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Redhat - add beats repository 3 | become: yes 4 | template: 5 | src: beats.repo.j2 6 | dest: /etc/yum.repos.d/beats.repo 7 | when: beats_add_repository | bool 8 | 9 | - name: RedHat - install yum-version-lock 10 | become: yes 11 | yum: 12 | name: yum-plugin-versionlock 13 | state: present 14 | update_cache: true 15 | when: version_lock | bool 16 | register: versionlock_install 17 | until: versionlock_install is succeeded 18 | 19 | - name: RedHat - unlock {{ beat }} for install 20 | become: yes 21 | shell: yum versionlock delete {{ beat }} || true 22 | changed_when: false 23 | when: version_lock | bool 24 | tags: 25 | - skip_ansible_lint 26 | 27 | - name: RedHat - Ensure {{ beat }} is installed 28 | become: yes 29 | yum: 30 | name: >- 31 | {{ beat }}{% if beats_version is defined and beats_version|length %}-{{ beats_version }}{% endif %} 32 | state: present 33 | update_cache: true 34 | register: beat_install 35 | until: beat_install is succeeded 36 | when: use_repository | bool 37 | notify: restart the service 38 | 39 | - name: RedHat - lock {{ beat }} version 40 | become: yes 41 | shell: >- 42 | yum versionlock add 43 | {{ beat }}{% if beats_version is defined and beats_version|length %}-{{ beats_version }}{% endif %} 44 | when: version_lock | bool 45 | changed_when: false 46 | tags: 47 | - skip_ansible_lint 48 | 49 | - name: RedHat - Install {{ beat }} from url 50 | become: yes 51 | yum: 52 | name: >- 53 | {% if custom_package_url is defined %}{{ custom_package_url }}{% 54 | else %}{{ beats_package_url }}/{{ beat }}-{{ beats_version }}-{{ ansible_architecture }}.rpm{% endif %} 55 | state: present 56 | register: beat_install 57 | until: beat_install is succeeded 58 | when: not use_repository 59 | notify: restart the service 60 | -------------------------------------------------------------------------------- /tasks/beats-config.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Configure Beats Node 3 | 4 | - name: Set default facts 5 | set_fact: 6 | pid_file: '{{ beats_pid_dir }}/{{ beat }}.pid' 7 | instance_default_file: '{{ default_file }}/{{ beat }}' 8 | conf_file: '{{ beats_conf_dir }}/{{ beat }}.yml' 9 | beat_output_conf: 10 | output: '{{ output_conf }}' 11 | 12 | - name: Set beat_shipper_conf 13 | set_fact: 14 | beat_shipper_conf: 15 | shipper: '{{ shipper_conf }}' 16 | when: shipper_conf is defined 17 | 18 | - name: Set beat_logging_conf 19 | set_fact: 20 | beat_logging_conf: 21 | logging: '{{ logging_conf }}' 22 | 23 | - name: Check pid_dir status 24 | stat: 25 | path: '{{ beats_pid_dir }}' 26 | register: pid_stat 27 | 28 | - name: Create PID Directory 29 | become: yes 30 | file: 31 | path: '{{ beats_pid_dir }}' 32 | state: directory 33 | when: pid_stat.stat.isdir is not defined or pid_stat.stat.islnk is not defined 34 | 35 | # fail if pid and config directories are not links or not directories i.e files 36 | 37 | - name: Create Config Directory 38 | become: yes 39 | file: 40 | path: '{{ beats_conf_dir }}' 41 | state: directory 42 | 43 | # Copy the default file 44 | - name: Copy Default File for Instance 45 | become: yes 46 | template: 47 | src: beat.j2 48 | dest: '{{ instance_default_file }}' 49 | mode: 0644 50 | force: true 51 | owner: root 52 | group: root 53 | notify: restart the service 54 | 55 | # Copy templated config file 56 | - name: Copy Configuration File for {{ beat }} 57 | become: yes 58 | template: 59 | src: beat.yml.j2 60 | dest: '{{ conf_file }}' 61 | mode: 0644 62 | force: true 63 | owner: root 64 | group: root 65 | backup: yes 66 | notify: restart the service 67 | 68 | # Copy default ILM policy file 69 | - name: Create default policies config directory 70 | become: yes 71 | file: 72 | path: '{{ beat_conf.setup.ilm.policy_file | dirname }}' 73 | state: directory 74 | mode: 0755 75 | owner: root 76 | group: root 77 | when: default_ilm_policy is defined 78 | 79 | - name: Copy default ILM policy file for {{ beat }} 80 | become: yes 81 | copy: 82 | src: '{{default_ilm_policy}}' 83 | dest: '{{ beat_conf.setup.ilm.policy_file }}' 84 | mode: 0644 85 | owner: root 86 | group: root 87 | when: default_ilm_policy is defined 88 | notify: restart the service 89 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | bcrypt_pbkdf (1.0.1) 5 | builder (3.2.4) 6 | ed25519 (1.2.4) 7 | equatable (0.5.0) 8 | erubi (1.9.0) 9 | ffi (1.12.1) 10 | gssapi (1.3.0) 11 | ffi (>= 1.0.1) 12 | gyoku (1.3.1) 13 | builder (>= 2.1.2) 14 | httpclient (2.8.3) 15 | kitchen-ansible (0.50.0) 16 | net-ssh (>= 3) 17 | test-kitchen (>= 1.4) 18 | kitchen-docker (2.9.0) 19 | test-kitchen (>= 1.0.0) 20 | license-acceptance (1.0.11) 21 | pastel (~> 0.7) 22 | tomlrb (~> 1.2) 23 | tty-box (~> 0.3) 24 | tty-prompt (~> 0.18) 25 | little-plugger (1.1.4) 26 | logging (2.2.2) 27 | little-plugger (~> 1.1) 28 | multi_json (~> 1.10) 29 | mixlib-install (3.11.18) 30 | mixlib-shellout 31 | mixlib-versioning 32 | thor 33 | mixlib-shellout (2.4.4) 34 | mixlib-versioning (1.2.7) 35 | multi_json (1.14.1) 36 | necromancer (0.4.0) 37 | net-scp (2.0.0) 38 | net-ssh (>= 2.6.5, < 6.0.0) 39 | net-ssh (5.2.0) 40 | net-ssh-gateway (2.0.0) 41 | net-ssh (>= 4.0.0) 42 | nori (2.6.0) 43 | pastel (0.7.2) 44 | equatable (~> 0.5.0) 45 | tty-color (~> 0.4.0) 46 | rubyntlm (0.6.2) 47 | rubyzip (2.0.0) 48 | strings (0.1.5) 49 | strings-ansi (~> 0.1) 50 | unicode-display_width (~> 1.5) 51 | unicode_utils (~> 1.4) 52 | strings-ansi (0.1.0) 53 | test-kitchen (2.2.5) 54 | bcrypt_pbkdf (~> 1.0) 55 | ed25519 (~> 1.2) 56 | license-acceptance (~> 1.0, >= 1.0.11) 57 | mixlib-install (~> 3.6) 58 | mixlib-shellout (>= 1.2, < 3.0) 59 | net-scp (>= 1.1, < 3.0) 60 | net-ssh (>= 2.9, < 6.0) 61 | net-ssh-gateway (>= 1.2, < 3.0) 62 | thor (~> 0.19) 63 | winrm (~> 2.0) 64 | winrm-elevated (~> 1.0) 65 | winrm-fs (~> 1.1) 66 | thor (0.20.3) 67 | timers (4.3.0) 68 | tomlrb (1.2.8) 69 | tty-box (0.3.0) 70 | pastel (~> 0.7.2) 71 | strings (~> 0.1.4) 72 | tty-cursor (~> 0.6.0) 73 | tty-color (0.4.3) 74 | tty-cursor (0.6.1) 75 | tty-prompt (0.18.1) 76 | necromancer (~> 0.4.0) 77 | pastel (~> 0.7.0) 78 | timers (~> 4.0) 79 | tty-cursor (~> 0.6.0) 80 | tty-reader (~> 0.5.0) 81 | tty-reader (0.5.0) 82 | tty-cursor (~> 0.6.0) 83 | tty-screen (~> 0.6.4) 84 | wisper (~> 2.0.0) 85 | tty-screen (0.6.5) 86 | unicode-display_width (1.6.0) 87 | unicode_utils (1.4.0) 88 | winrm (2.3.4) 89 | builder (>= 2.1.2) 90 | erubi (~> 1.8) 91 | gssapi (~> 1.2) 92 | gyoku (~> 1.0) 93 | httpclient (~> 2.2, >= 2.2.0.2) 94 | logging (>= 1.6.1, < 3.0) 95 | nori (~> 2.0) 96 | rubyntlm (~> 0.6.0, >= 0.6.1) 97 | winrm-elevated (1.1.1) 98 | winrm (~> 2.0) 99 | winrm-fs (~> 1.0) 100 | winrm-fs (1.3.4) 101 | erubi (~> 1.8) 102 | logging (>= 1.6.1, < 3.0) 103 | rubyzip (~> 2.0) 104 | winrm (~> 2.0) 105 | wisper (2.0.0) 106 | 107 | PLATFORMS 108 | ruby 109 | 110 | DEPENDENCIES 111 | kitchen-ansible 112 | kitchen-docker 113 | net-ssh 114 | test-kitchen 115 | 116 | BUNDLED WITH 117 | 1.17.0 118 | -------------------------------------------------------------------------------- /tasks/beats-debian.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Debian - Ensure apt-transport-https is installed 3 | become: yes 4 | apt: 5 | name: apt-transport-https 6 | state: present 7 | cache_valid_time: 86400 8 | when: use_repository | bool 9 | register: beat_install 10 | until: beat_install is succeeded 11 | notify: restart the service 12 | 13 | - name: Debian - Ensure python-urllib3, python-openssl, python-pyasn1 & python-pip are installed 14 | become: yes 15 | apt: 16 | name: 17 | - python-urllib3 18 | - python-openssl 19 | - python-pyasn1 20 | - python-pip 21 | state: present 22 | register: libs_install 23 | until: libs_install is succeeded 24 | when: 25 | - use_repository | bool 26 | - ansible_distribution_release == "trusty" 27 | 28 | - name: Debian - ensure ndg-httpsclient pip is installed 29 | become: yes 30 | pip: 31 | name: ndg-httpsclient 32 | state: present 33 | register: ndg_install 34 | until: ndg_install is succeeded 35 | when: 36 | - use_repository | bool 37 | - ansible_distribution_release == "trusty" 38 | 39 | - name: Debian - Add Beats repository key 40 | become: yes 41 | apt_key: 42 | url: "{{ elastic_repo_key }}" 43 | state: present 44 | register: apt_key_install 45 | until: apt_key_install is succeeded 46 | when: beats_add_repository | bool 47 | 48 | - name: Debian - add beats repository 49 | become: yes 50 | apt_repository: 51 | repo: "deb {{ repo_url }} stable main" 52 | state: present 53 | register: repo_install 54 | until: repo_install is succeeded 55 | when: beats_add_repository | bool 56 | 57 | - name: Debian - Check if {{ beat }} package is installed 58 | package_facts: 59 | manager: apt 60 | 61 | - name: Debian - unhold {{ beat }} version for install 62 | become: yes 63 | dpkg_selections: 64 | name: "{{ beat }}" 65 | selection: "install" 66 | when: beat in ansible_facts.packages 67 | changed_when: false 68 | 69 | - name: Debian - Ensure {{ beat }} is installed 70 | become: yes 71 | apt: 72 | name: >- 73 | {{ beat }}{% if beats_version is defined and beats_version|length>0 %}={{ beats_version }}{% endif %} 74 | state: present 75 | cache_valid_time: 86400 76 | register: beat_install 77 | until: beat_install is succeeded 78 | when: use_repository | bool 79 | notify: restart the service 80 | 81 | - name: Debian - hold {{ beat }} version 82 | become: yes 83 | dpkg_selections: 84 | name: "{{ beat }}" 85 | selection: "hold" 86 | when: version_lock 87 | changed_when: false 88 | 89 | - name: Set os_arch 90 | set_fact: 91 | os_arch: >- 92 | {{ ansible_architecture == 'x86_64' | ternary('amd64', 'i386') }} 93 | 94 | - name: Debian - Download {{ beat }} from url 95 | get_url: 96 | url: >- 97 | {% if custom_package_url is defined %}{{ custom_package_url }}{% 98 | else %}{{ beats_package_url }}/{{ beat }}/{{ beat }}_{{ beats_version }}_{{ os_arch }}.deb{% endif %} 99 | dest: "/tmp/{{ beat }}_{{ beats_version }}_{{ os_arch }}.deb" 100 | validate_certs: false 101 | when: not use_repository | bool 102 | 103 | - name: Debian - Ensure {{ beat }} is installed from downloaded package 104 | become: yes 105 | apt: 106 | deb: "/tmp/{{ beat }}_{{ beats_version }}_{{ os_arch }}.deb" 107 | when: not use_repository | bool 108 | notify: restart the service 109 | -------------------------------------------------------------------------------- /.kitchen.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: 3 | name: docker 4 | 5 | transport: 6 | max_ssh_sessions: 6 7 | 8 | provisioner: 9 | name: ansible_playbook 10 | hosts: localhost 11 | roles_path: ./ 12 | require_ansible_repo: true 13 | ansible_verbose: true 14 | idempotency_test: true 15 | 16 | platforms: 17 | - name: ubuntu-16.04 18 | driver_config: 19 | image: ubuntu:16.04 20 | privileged: true 21 | provision_command: 22 | - apt-get update && apt-get install -y software-properties-common && add-apt-repository -y ppa:ansible/ansible 23 | - apt-get update && apt-get -y -q install ansible python-apt python-pycurl 24 | use_sudo: false 25 | - name: ubuntu-18.04 26 | driver_config: 27 | image: ubuntu:18.04 28 | privileged: true 29 | provision_command: 30 | - apt-get update && apt-get install -y software-properties-common && add-apt-repository -y ppa:ansible/ansible 31 | - apt-get update && apt-get -y -q install ansible python-apt python-pycurl 32 | - mkdir -p /run/sshd 33 | use_sudo: false 34 | - name: ubuntu-20.04 35 | driver_config: 36 | image: ubuntu:20.04 37 | privileged: true 38 | provision_command: 39 | - apt-get update && apt-get install -y software-properties-common && add-apt-repository -y ppa:ansible/ansible 40 | - apt-get update && apt-get -y -q install ansible python-apt python-pycurl 41 | use_sudo: false 42 | - name: debian-8 43 | driver_config: 44 | image: debian:8 45 | privileged: true 46 | provision_command: 47 | - echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main" > /etc/apt/sources.list.d/ansible.list 48 | - apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367 49 | - apt-get update && apt-get -y install ansible 50 | use_sudo: false 51 | - name: debian-9 52 | driver_config: 53 | image: debian:9 54 | privileged: true 55 | provision_command: 56 | - apt-get update && apt-get -y install gnupg2 57 | - echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main" > /etc/apt/sources.list.d/ansible.list 58 | - apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367 59 | - apt-get update && apt-get -y install ansible 60 | use_sudo: false 61 | - name: debian-10 62 | driver_config: 63 | image: debian:10 64 | privileged: true 65 | provision_command: 66 | - apt-get update && apt-get -y install gnupg2 67 | - echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main" > /etc/apt/sources.list.d/ansible.list 68 | - apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367 69 | - apt-get update && apt-get -y install ansible 70 | use_sudo: false 71 | - name: centos-7 72 | driver_config: 73 | image: centos:7 74 | provision_command: 75 | - yum -y install epel-release 76 | - yum -y install ansible 77 | run_command: "/usr/sbin/init" 78 | privileged: true 79 | use_sudo: false 80 | - name: centos-8 81 | driver_config: 82 | image: centos:8 83 | provision_command: 84 | - yum -y install epel-release 85 | - yum -y install ansible 86 | run_command: "/usr/sbin/init" 87 | privileged: true 88 | use_sudo: false 89 | - name: amazonlinux-2 90 | driver_config: 91 | image: amazonlinux:2 92 | provision_command: 93 | - yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 94 | - yum -y install ansible 95 | volume: 96 | - <%=ENV['ES_XPACK_LICENSE_FILE']%>:/tmp/license.json 97 | - /etc # This fixes certain java file actions that check the mount point. Without this adding users fails for some docker storage drivers 98 | run_command: "/usr/sbin/init" 99 | privileged: true 100 | use_sudo: false 101 | suites: 102 | - name: standard 103 | provisioner: 104 | playbook: test/integration/standard.yml 105 | additional_copy_path: 106 | - "." 107 | run_list: 108 | attributes: 109 | - name: standard-6x 110 | provisioner: 111 | playbook: test/integration/standard-6x.yml 112 | additional_copy_path: 113 | - "." 114 | run_list: 115 | attributes: 116 | - name: multi 117 | provisioner: 118 | playbook: test/integration/multi.yml 119 | additional_copy_path: 120 | - "." 121 | run_list: 122 | attributes: 123 | - name: config 124 | provisioner: 125 | playbook: test/integration/config.yml 126 | additional_copy_path: 127 | - "." 128 | run_list: 129 | attributes: 130 | - name: oss 131 | provisioner: 132 | playbook: test/integration/oss.yml 133 | additional_copy_path: 134 | - "." 135 | run_list: 136 | attributes: 137 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ARCHIVED 2 | 3 | This project is no longer maintained. For alternative getting started 4 | experiences, you may want to try one of these options: 5 | 6 | - Start a [free trial on Elastic Cloud](https://www.elastic.co/cloud/elasticsearch-service/signup), our hosted service. 7 | - Take a look at [Elastic Cloud on Kubernetes (ECK)](https://elastic.co/guide/en/cloud-on-k8s/current/k8s-quickstart.html) for launching the stack via Kubernetes. 8 | - Read our [Running the Elastic Stack on Docker](https://www.elastic.co/guide/en/elastic-stack-get-started/current/get-started-docker.html) guide. 9 | - Take a look at the [Elastic Stack Terraform provider.](https://github.com/elastic/terraform-provider-elasticstack) 10 | 11 | 12 | # ansible-beats 13 | [![Build Status](https://img.shields.io/jenkins/s/https/devops-ci.elastic.co/job/elastic+ansible-beats+main.svg)](https://devops-ci.elastic.co/job/elastic+ansible-beats+main/) 14 | [![Ansible Galaxy](https://img.shields.io/badge/ansible--galaxy-elastic.beats-blue.svg)](https://galaxy.ansible.com/elastic/beats/) 15 | 16 | 17 | This role provides a generic means of installing Elastic supported Beats 18 | 19 | **Tested Beats** 20 | 21 | * Filebeat 22 | * MetricBeat (TopBeat in 1.x) 23 | * Packetbeat 24 | 25 | **Tested Versions** 26 | 27 | * 7.x 28 | * 6.x 29 | 30 | **Tested Platforms** 31 | 32 | * Ubuntu 16.04 33 | * Ubuntu 18.04 34 | * Ubuntu 20.04 35 | * Debian 8 36 | * Debian 9 37 | * Debian 10 38 | * CentOS 7 39 | * Amazon Linux 2 40 | 41 | ## Usage 42 | 43 | Create your Ansible playbook with your own tasks, and include the role beats. You will have to have this repository accessible within the context of playbook. 44 | 45 | ```sh 46 | ansible-galaxy install elastic.beats,v7.17.0 47 | ``` 48 | 49 | Then create your playbook yaml adding the role beats. 50 | The application of the beats role results in the installation of a node on a host. 51 | 52 | The simplest configuration therefore consists of: 53 | 54 | ```yaml 55 | hosts: localhost 56 | roles: 57 | - role: elastic.beats 58 | vars: 59 | beats_version: 7.17.0 60 | beat: filebeat 61 | beat_conf: 62 | filebeat: 63 | inputs: 64 | - type: log 65 | enabled: true 66 | paths: 67 | - /var/log/*.log 68 | ``` 69 | 70 | The above installs Filebeat 7.17.0 on the hosts 'localhost'. 71 | 72 | **Notes**: 73 | - Beats default version is described in [`beats_version`](https://github.com/elastic/ansible-beats/blob/main/defaults/main.yml#L4). You can override this variable in your playbook to install another version. 74 | While we are testing this role only with one 7.x and one 6.x version (respectively [7.17.0](https://github.com/elastic/ansible-beats/blob/main/defaults/main.yml#L4) and [6.8.23](https://github.com/elastic/ansible-beats/blob/main/test/integration/standard-6x.yml#L7) at the time of writing), this role should work with others version also in most cases. 75 | - Beat product is described in `beat` variable. While currently tested Beats are Filebeat, Metricbeat & Packetbeat, this role should work also with other member of [The Beats Family](https://www.elastic.co/products/beats) in most cases. 76 | 77 | ## Testing 78 | 79 | This playbook uses [Kitchen](https://kitchen.ci/) for CI and local testing. 80 | 81 | ### Requirements 82 | 83 | * Ruby 84 | * Bundler 85 | * Docker 86 | * Make 87 | 88 | ### Running the tests 89 | 90 | To converge an Ubuntu 18.04 host 91 | ```sh 92 | $ make converge 93 | ``` 94 | 95 | To run the tests 96 | ```sh 97 | $ make verify 98 | ``` 99 | 100 | To list all of the different test suits 101 | ```sh 102 | $ make list 103 | ``` 104 | 105 | The default test suite is Ubuntu 18.04. If you want to test another suite you can override this with the `PATTERN` variable 106 | ```sh 107 | $ make converge PATTERN=standard-centos-7 108 | ``` 109 | 110 | The `PATTERN` is a kitchen pattern which can match multiple suites. To run all tests for CentOS 111 | ```sh 112 | $ make converge PATTERN=centos-7 113 | ``` 114 | 115 | When you are finished testing you can clean up everything with 116 | ```sh 117 | $ make destroy-all 118 | ``` 119 | 120 | ### Basic Beats configuration 121 | 122 | All Beats configuration parameters are supported. This is achieved using a configuration map parameter `beat_conf` which is serialized into the `${beat}.yml` file. 123 | The use of a map ensures the Ansible playbook does not need to be updated to reflect new/deprecated/plugin configuration parameters. 124 | 125 | In addition to the `beat_conf` map, several other parameters are supported for additional functions e.g. script installation. These can be found in the role's `defaults/main.yml` file. 126 | 127 | The following illustrates applying configuration parameters to Packetbeat instance. 128 | 129 | ```yaml 130 | - name: Example playbook for installing packetbeat 131 | hosts: localhost 132 | roles: 133 | - { role: beats, beat: "packetbeat", 134 | beat_conf: { 135 | "interfaces": {"device":"any"}, 136 | "protocols": { 137 | "dns": { 138 | "ports": [53], 139 | "include_authorities":true 140 | }, 141 | "http": { 142 | "ports": [80, 8080, 8000, 5000, 8002] 143 | }, 144 | "memcache": { 145 | "ports": [11211] 146 | }, 147 | "mysql": { 148 | "ports": [3306] 149 | }, 150 | "pgsql": { 151 | "ports": [5432] 152 | }, 153 | "redis": { 154 | "ports": [6379] 155 | }, 156 | "thrift": { 157 | "ports": [9090] 158 | }, 159 | "mongodb": { 160 | "ports": [27017] 161 | } 162 | } 163 | }, 164 | output_conf : { 165 | "elasticsearch": { 166 | "hosts": ["localhost:9200"] 167 | } 168 | } 169 | } 170 | vars: 171 | use_repository: "true" 172 | ``` 173 | 174 | ### Additional Configuration 175 | 176 | Supported variables are as follows: 177 | 178 | - **beat** (*MANDATORY*): Beat product. Supported values are: "filebeat", "metricbeat" & "packetbeat" (others beats from [The Beats Family](https://www.elastic.co/products/beats) should work in most cases but aren't currently tested). 179 | - **beat_conf** (*MANDATORY*): Beat Configuration. Should be defined as a map. 180 | - **beats_version** (*Defaults to `7.17.0`*): Beats version. 181 | - **version_lock** (*Defaults to `false`*): Locks the installed version if set to true, thus preventing other processes from updating. This will not impact the roles ability to update the beat on subsequent runs (it unlocks and re-locks if required). 182 | - **use_repository** (*Defaults to `true`*): Use elastic repo for yum or apt if true. If false, a custom custom_package_url must be provided. 183 | - **beats_add_repository** (*Defaults to `{use_repository}`*): Install elastic repo for yum or apt if true. If false, the present repositories will be used. Useful if you already have beats packages in your repo. 184 | - **start_service** (*Defaults to `true`*): service will be started if true, false otherwise. 185 | - **restart_on_change** (*Defaults to `true`*): Changes to configuration or installed versions, will result in a restart if true. 186 | - **daemon_args** (*Applicable to version 1.x of beats*): Allows run time params to be passed to beats. 187 | - **logging_conf** (*Defaults to `{"files":{"rotateeverybytes":10485760}}`*): Logging configuration. Should be defined as a map. Map is serialized into logging section of beat config. 188 | - **shipper_conf** (*Applicable to version 1.x of beats*): Shipper configuration. Should be defined as a map . Map is serialized into shipper section of beat config. 189 | - **output_conf** (*Defaults to `{"elasticsearch":{"hosts":["localhost:9200"]}}`*): Output configuration. Map is serialized into output section of beat config. 190 | - **beats_pid_dir** (*Defaults to `/var/run`*): Location of beats pid file. 191 | - **beats_conf_dir** (*Defaults to `/etc/{beat}`*): Location of conf directory for beats configuration file. 192 | - **default_ilm_policy** (*Defaults undefined*): local path to default policy if any custom one is defined 193 | 194 | ### Focus on ILM 195 | 196 | By default, *beat* will create a default policy defined as part of the beat being deployed. 197 | You can override default ILM setup by defining ILM conf as part of *beat_conf*. 198 | For example: 199 | 200 | ``` 201 | - role: ansible-beats 202 | beat: metricbeat 203 | beat_conf: 204 | setup: 205 | ilm: 206 | policy_file: /etc/filebeat/policies/my-default-metricbeat.json 207 | overwrite: true 208 | metricbeat.modules: 209 | ... 210 | default_ilm_policy: conf/my-default-metricbeat.json 211 | become: yes 212 | ``` 213 | 214 | This will copy *conf/my-default-filebeat.json* to */etc/filebeat/policies/my-default-filebeat.json*. 215 | This policy will be used as default one for this beat. 216 | 217 | ## License 218 | 219 | Apache 2.0 220 | 221 | ## Limitations 222 | 223 | Multiple instances of the same beat cannot be installed on the same target server. 224 | 225 | ## Questions on Usage 226 | 227 | We welcome questions on how to use the role. However, in order to keep the GitHub issues list focused on "issues" we ask the community to raise questions at https://discuss.elastic.co/c/beats. This is monitored by the maintainers. 228 | 229 | Community Contributions always appreciated and welcome! Please ensure all contributions include tests as appropriate. 230 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 7.17.0 4 | 5 | * 7.17.0 as default version. 6 | 7 | 8 | | PR | Author | Title | 9 | | --- | --- | --- | 10 | | [#175](https://github.com/elastic/ansible-beats/pull/175) | [@jmlrt](https://github.com/jmlrt) | Remove CentOS 8 tests | 11 | 12 | 13 | ## 7.16.3 14 | 15 | * 7.16.3 as default version. 16 | * 6.8.23 as 6.x tested version 17 | 18 | ## 7.16.2 19 | 20 | * 7.16.2 as default version. 21 | * 6.8.22 as 6.x tested version 22 | 23 | ## 7.16.1 24 | 25 | * 7.16.1 as default version. 26 | * 6.8.21 as 6.x tested version 27 | 28 | 29 | | PR | Author | Title | 30 | | --- | --- | --- | 31 | | [#166](https://github.com/elastic/ansible-beats/pull/166) | [@mgreau](https://github.com/mgreau) | Add warning message about 8.x versions | 32 | | [#164](https://github.com/elastic/ansible-beats/pull/164) | [@seadog007](https://github.com/seadog007) | Remove duplicated space | 33 | 34 | 35 | ## 7.16.0 36 | 37 | * 7.16.0 as default version. 38 | 39 | 40 | | PR | Author | Title | 41 | | --- | --- | --- | 42 | | [#160](https://github.com/elastic/ansible-beats/pull/160) | [@ygel](https://github.com/ygel) | Rename master - main | 43 | 44 | 45 | ## 7.15.1 46 | 47 | * 7.15.1 as default version. 48 | 49 | ## 7.15.0 50 | 51 | * 7.15.0 as default version. 52 | 53 | ## 7.14.0 54 | 55 | * 7.14.0 as default version. 56 | * 6.8.18 as 6.x tested version 57 | 58 | ## 7.13.4 59 | 60 | * 7.13.4 as default version. 61 | 62 | ## 7.13.3 63 | 64 | * 7.13.3 as default version. 65 | * 6.8.17 as 6.x tested version 66 | 67 | 68 | | PR | Author | Title | 69 | | --- | --- | --- | 70 | | [#148](https://github.com/elastic/ansible-beats/pull/148) | [@metabsd](https://github.com/metabsd) | Backup the existing configuration file | 71 | 72 | 73 | ## 7.13.2 74 | 75 | * 7.13.2 as default version. 76 | 77 | ## 7.13.1 78 | 79 | * 7.13.1 as default version. 80 | 81 | 82 | | PR | Author | Title | 83 | | --- | --- | --- | 84 | | [#146](https://github.com/elastic/ansible-beats/pull/146) | [@jmlrt](https://github.com/jmlrt) | Fix unhold issue with custom deb packages | 85 | 86 | 87 | ## 7.13.0 88 | 89 | * 7.13.0 as default version. 90 | * 6.8.16 as 6.x tested version 91 | 92 | ## 7.12.1 93 | 94 | * 7.12.1 as default version. 95 | 96 | ## 7.12.0 97 | 98 | * 7.12.0 as default version. 99 | * 6.8.15 as 6.x tested version 100 | 101 | 102 | | PR | Author | Title | 103 | | --- | --- | --- | 104 | | [#138](https://github.com/elastic/ansible-beats/pull/138) | [@jmlrt](https://github.com/jmlrt) | [meta] fix changelog after 7.11.2 release | 105 | 106 | 107 | ## 7.11.2 108 | 109 | * 7.11.2 as default version. 110 | 111 | | PR | Author | Title | 112 | | --- | --- | --- | 113 | | [#135](https://github.com/elastic/ansible-beats/pull/135) | [@v1v](https://github.com/v1v) | Update metadata reference for CentOS 8 | 114 | | [#134](https://github.com/elastic/ansible-beats/pull/134) | [@v1v](https://github.com/v1v) | Remove Ubuntu-14.04 support | 115 | | [#118](https://github.com/elastic/ansible-beats/pull/118) | [@v1v](https://github.com/v1v) | Support ubuntu-20 | 116 | | [#116](https://github.com/elastic/ansible-beats/pull/116) | [@v1v](https://github.com/v1v) | Support debian 10 | 117 | | [#131](https://github.com/elastic/ansible-beats/pull/131) | [@jmlrt](https://github.com/jmlrt) | Copy ILM policy file with root permission | 118 | 119 | 120 | ## 7.11.1 121 | 122 | * 7.11.1 as default version. 123 | * 6.8.14 as 6.x tested version 124 | 125 | ## 7.10.2 126 | 127 | * 7.10.2 as default version. 128 | 129 | 130 | | PR | Author | Title | 131 | | --- | --- | --- | 132 | | [#123](https://github.com/elastic/ansible-beats/pull/123) | [@jmlrt](https://github.com/jmlrt) | Cleanup init_script variable | 133 | 134 | 135 | ## 7.10.1 136 | 137 | * 7.10.1 as default version. 138 | 139 | 140 | | PR | Author | Title | 141 | | --- | --- | --- | 142 | | [#115](https://github.com/elastic/ansible-beats/pull/115) | [@v1v](https://github.com/v1v) | Support CentOS-8 | 143 | | [#120](https://github.com/elastic/ansible-beats/pull/120) | [@jmlrt](https://github.com/jmlrt) | Remove CentOS 6 support | 144 | 145 | 146 | ## 7.10.0 147 | 148 | * 7.10.0 as default version. 149 | 150 | 151 | | PR | Author | Title | 152 | | --- | --- | --- | 153 | | [#113](https://github.com/elastic/ansible-beats/pull/113) | [@jmlrt](https://github.com/jmlrt) | [meta] clean deprecated bumper script | 154 | 155 | 156 | ## 7.9.3 157 | 158 | * 7.9.3 as default version. 159 | * 6.8.13 as 6.x tested version 160 | 161 | ## 7.9.2 - 2020/09/24 162 | 163 | * 7.9.2 as default version 164 | 165 | ## 7.9.1 - 2020/09/03 166 | 167 | * 7.9.1 as default version 168 | 169 | ## 7.9.0 - 2020/08/18 170 | 171 | * 7.9.0 as default version 172 | * 6.8.12 as 6.x tested version 173 | 174 | ## 7.8.1 - 2020/07/28 175 | 176 | * 7.8.1 as default version 177 | * 6.8.11 as 6.x tested version 178 | 179 | | PR | Author | Title | 180 | |---------------------------------------------------------|------------------------------------|--------------------------| 181 | | [#89](https://github.com/elastic/ansible-beats/pull/89) | [@jmlrt](https://github.com/jmlrt) | Add amazonlinux2 support | 182 | 183 | 184 | ## 7.8.0 - 2020/06/18 185 | 186 | * 7.8.0 as default version 187 | 188 | ## 7.7.1 - 2020/06/04 189 | 190 | * 7.7.1 as default version 191 | * 6.8.10 as 6.x tested version 192 | 193 | ## 7.7.0 - 2020/05/13 194 | 195 | * 7.7.0 as default version 196 | * 6.8.9 as 6.x tested version 197 | * Fix CentOS tests in [#86](https://github.com/elastic/ansible-beats/pull/86) ([@jmlrt](https://github.com/jmlrt)) 198 | 199 | | PR | Author | Title | 200 | |---------------------------------------------------------|------------------------------------------|---------------------------------------------| 201 | | [#84](https://github.com/elastic/ansible-beats/pull/84) | [@kravietz](https://github.com/kravietz) | Minor formatting fixes to pass ansible-lint | 202 | 203 | 204 | ## 7.6.2 - 2020/03/31 205 | 206 | * 7.6.2 as default version 207 | * 6.8.8 as 6.x tested version 208 | 209 | | PR | Author | Title | 210 | |---------------------------------------------------------|------------------------------------|---------------------------------------------------------------------------| 211 | | [#77](https://github.com/elastic/ansible-beats/pull/77) | [@jmlrt](https://github.com/jmlrt) | Add become to individual tasks | 212 | | [#75](https://github.com/elastic/ansible-beats/pull/75) | [@ktibi](https://github.com/ktibi) | Add option to disable the repo installation and lock package installation | 213 | | [#78](https://github.com/elastic/ansible-beats/pull/78) | [@astik](https://github.com/astik) | Aad task to create directory for default policies | 214 | 215 | 216 | ## 7.6.1 - 2020/03/04 217 | 218 | * 7.6.1 as default version 219 | 220 | 221 | ## 7.6.0 - 2020/02/11 222 | 223 | * 7.6.0 as default version 224 | 225 | | PR | Author | Title | 226 | |---------------------------------------------------------|--------------------------------------------------------|------------------------------------| 227 | | [#69](https://github.com/elastic/ansible-beats/pull/69) | [@dependabot[bot]](https://github.com/apps/dependabot) | Bump rubyzip from 1.2.2 to 2.0.0 | 228 | | [#71](https://github.com/elastic/ansible-beats/pull/71) | [@jmlrt](https://github.com/jmlrt) | Fix filebeat example configuration | 229 | | [#72](https://github.com/elastic/ansible-beats/pull/72) | [@beand](https://github.com/beand) | Fixed typo | 230 | 231 | 232 | ## 7.5.2 - 2020/01/21 233 | 234 | * 7.5.2 as default version 235 | 236 | | PR | Author | Title | 237 | |---------------------------------------------------------|------------------------------------|-----------------------------------------------| 238 | | [#66](https://github.com/elastic/ansible-beats/pull/66) | [@jmlrt](https://github.com/jmlrt) | [doc] switched relative URLs to absolute URLs | 239 | | [#67](https://github.com/elastic/ansible-beats/pull/67) | [@jmlrt](https://github.com/jmlrt) | [ci] bump ruby to 2.5.7 | 240 | 241 | 242 | ## 7.5.1 - 2019/12/18 243 | 244 | * 7.5.1 as default version 245 | * 6.8.6 as 6.x tested version 246 | 247 | | PR | Author | Title | 248 | |---------------------------------------------------------|----------------------------------------------------|--------------------------| 249 | | [#61](https://github.com/elastic/ansible-beats/pull/61) | [@robsonpeixoto](https://github.com/robsonpeixoto) | Allow use oss repository | 250 | 251 | 252 | ## 7.5.0 - 2019/12/02 253 | 254 | * 7.5.0 as default version 255 | * 6.8.5 as 6.x tested version in [#57](https://github.com/elastic/ansible-beats/pull/57) [@jmlrt](https://github.com/jmlrt) 256 | 257 | | PR | Author | Title | 258 | |---------------------------------------------------------|--------------------------------------------------|-----------------------------------------------------------------| 259 | | [#50](https://github.com/elastic/ansible-beats/pull/50) | [@jmlrt](https://github.com/jmlrt) | Add bumper script | 260 | | [#55](https://github.com/elastic/ansible-beats/pull/55) | [@tgadiev](https://github.com/tgadiev) | Update syntax to make it compliant to modern ansible-lint rules | 261 | | [#53](https://github.com/elastic/ansible-beats/pull/53) | [@jmlrt](https://github.com/jmlrt) | Indent yaml for config file | 262 | | [#51](https://github.com/elastic/ansible-beats/pull/51) | [@ktibi](https://github.com/ktibi) | Rename the handlers | 263 | | [#59](https://github.com/elastic/ansible-beats/pull/59) | [@MartinVerges](https://github.com/MartinVerges) | Beat config improvements | 264 | 265 | 266 | ## 7.4.1 - 2019/10/23 267 | 268 | * 7.4.1 as default version 269 | * 6.8.4 as 6.x tested version 270 | 271 | | PR | Author | Title | 272 | |---------------------------------------------------------|------------------------------------|---------------------| 273 | | [#48](https://github.com/elastic/ansible-beats/pull/48) | [@jmlrt](https://github.com/jmlrt) | Fix probot newlines | 274 | 275 | 276 | ## 7.4.0 - 2019/10/01 277 | 278 | * 7.4.0 as default version 279 | 280 | | PR | Author | Title | 281 | |---------------------------------------------------------|------------------------------------------|---------------------------------------------------------------------| 282 | | [#25](https://github.com/elastic/ansible-beats/pull/25) | [@jmlrt](https://github.com/jmlrt) | Update kitchen Gem dependencies | 283 | | [#6](https://github.com/elastic/ansible-beats/pull/6) | [@levonet](https://github.com/levonet) | Remove `beat_install` variable | 284 | | [#32](https://github.com/elastic/ansible-beats/pull/32) | [@astik](https://github.com/astik) | Remove unused `es_conf_dir` variable | 285 | | [#33](https://github.com/elastic/ansible-beats/pull/33) | [@astik](https://github.com/astik) | Replace custom filter with yaml handling | 286 | | [#10](https://github.com/elastic/ansible-beats/pull/10) | [@Meecr0b](https://github.com/Meecr0b) | Move the `repo_key` configuration to a variable | 287 | | [#34](https://github.com/elastic/ansible-beats/pull/34) | [@nyetwurk](https://github.com/nyetwurk) | Make sure the right beat service gets restarted | 288 | | [#38](https://github.com/elastic/ansible-beats/pull/38) | [@jmlrt](https://github.com/jmlrt) | Add probot config to manage stale issues/pr + GH issue template | 289 | | [#40](https://github.com/elastic/ansible-beats/pull/40) | [@nyetwurk](https://github.com/nyetwurk) | Make beats `repo_key` variable a unique name less likely to collide | 290 | | [#41](https://github.com/elastic/ansible-beats/pull/41) | [@jmlrt](https://github.com/jmlrt) | Enhance ansible-beats documentation | 291 | 292 | 293 | ## 7.0.0 - 2019/05/09 294 | 295 | * First release 296 | * 7.0.0 as default version 297 | --------------------------------------------------------------------------------