Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Update syntax to make it compliant to modern ansible-lint rules #55

Merged
merged 8 commits into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ suites:
additional_copy_path:
- "."
run_list:
attributes:
attributes:
8 changes: 4 additions & 4 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---

allow_duplicates: yes

allow_duplicates: true
dependencies: []
galaxy_info:
role_name: beats
author: Dale McDiarmid
description: Beats for Linux
company: "Elastic.co"
issue_tracker_url: https://github.com/elastic/ansible-beats/issues
license: "license (Apache)"
min_ansible_version: 2.0
platforms:
Expand All @@ -20,7 +20,7 @@ galaxy_info:
- name: Ubuntu
versions:
- all
categories:
galaxy_tags:
- beats
- elastic
- elk
Expand Down
56 changes: 38 additions & 18 deletions tasks/beats-config.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,61 @@
---
# Configure Beats Node

- set_fact: pid_file={{ beats_pid_dir }}/{{beat}}.pid
- set_fact: instance_default_file={{ default_file }}/{{beat}}
- set_fact: conf_file={{ beats_conf_dir }}/{{beat}}.yml

- set_fact:
- name: Set default facts
set_fact:
pid_file: '{{ beats_pid_dir }}/{{ beat }}.pid'
instance_default_file: '{{ default_file }}/{{ beat }}'
conf_file: '{{ beats_conf_dir }}/{{ beat }}.yml'
beat_output_conf:
output: "{{ output_conf }}"
output: '{{ output_conf }}'

- set_fact:
- name: Set beat_shipper_conf
set_fact:
beat_shipper_conf:
shipper: "{{ shipper_conf }}"
shipper: '{{ shipper_conf }}'
when: shipper_conf is defined

- set_fact:
- name: Set beat_logging_conf
set_fact:
beat_logging_conf:
logging: "{{ logging_conf }}"
logging: '{{ logging_conf }}'

- stat: path={{beats_pid_dir}}
- name: Check pid_dir status
stat:
path: '{{ beats_pid_dir }}'
register: pid_stat

- name: Create PID Directory
file: path={{ beats_pid_dir }} state=directory
file:
path: '{{ beats_pid_dir }}'
state: directory
when: pid_stat.stat.isdir is not defined or pid_stat.stat.islnk is not defined

#fail if pid and config directories are not links or not directories i.e files

- name: Create Config Directory
file: path={{ beats_conf_dir }} state=directory
file:
path: '{{ beats_conf_dir }}'
state: directory

#Copy the default file
- name: Copy Default File for Instance
template: src=beat.j2 dest={{instance_default_file}} mode=0644 force=yes owner=root group=root
notify: restart {{beat}}
template:
src: beat.j2
dest: '{{ instance_default_file }}'
mode: 0644
force: true
owner: root
group: root
notify: restart {{ beat }}

#Copy templated config file
- name: Copy Configuration File for {{beat}}
template: src=beat.yml.j2 dest={{conf_file}} mode=0644 force=yes owner=root group=root
notify: restart {{beat}}
- name: Copy Configuration File for {{ beat }}
template:
src: beat.yml.j2
dest: '{{ conf_file }}'
mode: 0644
force: true
owner: root
group: root
notify: restart {{ beat }}
96 changes: 65 additions & 31 deletions tasks/beats-debian.yml
Original file line number Diff line number Diff line change
@@ -1,57 +1,91 @@
---

- name: Debian - Ensure apt-transport-https is installed
apt: name=apt-transport-https state=present cache_valid_time=86400
when: use_repository
apt:
name: apt-transport-https
state: present
cache_valid_time: 86400
when: use_repository | bool
register: beat_install
notify: restart {{beat}}
until: beat_install is succeeded
notify: restart {{ beat }}

- name: Debian - Ensure python-urllib3, python-openssl, python-pyasn1 & python-pip are installed
apt:
name: python-urllib3,python-openssl,python-pyasn1,python-pip
name:
- python-urllib3
- python-openssl
- python-pyasn1
- python-pip
state: present
when: use_repository and ansible_distribution_release == "trusty"
register: libs_install
until: libs_install is succeeded
when:
- use_repository | bool
- ansible_distribution_release == "trusty"

- name: Debian - ensure ndg-httpsclient pip is installed
pip:
name: ndg-httpsclient
state: present
when: use_repository and ansible_distribution_release == "trusty"
register: ndg_install
until: ndg_install is succeeded
when:
- use_repository | bool
- ansible_distribution_release == "trusty"

- name: Debian - Add Beats repository key
apt_key:
url: "{{ elastic_repo_key }}"
url: '{{ elastic_repo_key }}'
state: present
when: use_repository
register: apt_key_install
until: apt_key_install is succeeded
when: use_repository | bool

- name: Debian - add beats repository
apt_repository: repo="deb {{ repo_url }} stable main" state=present
when: use_repository
apt_repository:
repo: 'deb {{ repo_url }} stable main'
state: present
register: repo_install
until: repo_install is succeeded
when: use_repository | bool

- name: Debian - unhold {{beat}} version for install
command: apt-mark unhold {{beat}}
changed_when: False
- name: Debian - unhold {{ beat }} version for install
command: apt-mark unhold {{ beat }}
changed_when: false

- name: Debian - Ensure {{beat}} is installed
apt: name={{beat}}{% if beats_version is defined and beats_version != "" %}={{ beats_version }}{% endif %} state=present cache_valid_time=86400
when: use_repository
notify: restart {{beat}}
- name: Debian - Ensure {{ beat }} is installed
apt:
name: >-
{{ beat }}{% if beats_version is defined and beats_version|length>0 %}={{ beats_version }}{% endif %}
state: present
cache_valid_time: 86400
register: beat_install
until: beat_install is succeeded
when: use_repository | bool
notify: restart {{ beat }}

- name: Debian - hold {{beat}} version
command: apt-mark hold {{beat}}
- name: Debian - hold {{ beat }} version
command: apt-mark hold {{ beat }}
when: version_lock
changed_when: False
changed_when: false

- set_fact: os_arch="i386"
- name: Set os_arch
set_fact:
os_arch: >-
{{ ansible_architecture == 'x86_64' | ternary('amd64', 'i386') }}

- set_fact: os_arch="amd64"
when: ansible_architecture == "x86_64"
- name: Debian - Download {{ beat }} from url
get_url:
url: >-
{% if custom_package_url is defined %}{{ custom_package_url }}{%
else %}{{ beats_package_url }}/{{ beat }}/{{ beat }}_{{ beats_version }}_{{ os_arch }}.deb{% endif %}
dest: '/tmp/{{ beat }}_{{ beats_version }}_{{ os_arch }}.deb'
validate_certs: false
when: not use_repository | bool

- name: Debian - Download {{beat}} from url
get_url: url={% if custom_package_url is defined %}{{ custom_package_url }}{% else %}{{ beats_package_url }}/{{beat}}/{{beat}}_{{ beats_version }}_{{os_arch}}.deb{% endif %} dest=/tmp/{{beat}}_{{ beats_version }}_{{os_arch}}.deb validate_certs=no
when: not use_repository

- name: Debian - Ensure {{beat}} is installed from downloaded package
apt: deb=/tmp/{{beat}}_{{ beats_version }}_{{os_arch}}.deb
when: not use_repository
notify: restart {{beat}}
- name: Debian - Ensure {{ beat }} is installed from downloaded package
apt:
deb: '/tmp/{{ beat }}_{{ beats_version }}_{{ os_arch }}.deb'
when: not use_repository | bool
notify: restart {{ beat }}
15 changes: 10 additions & 5 deletions tasks/beats-param-check.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
---
- name: Check beat variable
fail:
msg: "beat must be specified and cannot be blank e.g. filebeat"
when: beat is not defined or (beat | length == 0)

- fail: msg="beat must be specified and cannot be blank e.g. filebeat"
when: beat is not defined or beat == ''

- fail: msg="beat_conf must be specified"
- name: Check beat_conf variable
fail:
msg: "beat_conf must be specified"
when: beat_conf is not defined

- set_fact: "beats_major_version={{ beats_version[0] }}.x"
- name: Set beats_major_version
set_fact:
beats_major_version: '{{ beats_version[0] }}.x'
65 changes: 48 additions & 17 deletions tasks/beats-redhat.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,62 @@
---

- name: Ensure libselinux-python on CentOS 6.x
yum: name=libselinux-python state=present update_cache=yes
when: ( ansible_distribution == "CentOS" ) and ( ansible_distribution_major_version == "6" )
yum:
name: libselinux-python
state: present
update_cache: true
register: libselinux_install
until: libselinux_install is succeeded
when:
- ansible_distribution == "CentOS"
- ansible_distribution_major_version == "6"

- name: Redhat - add beats repository
template: src=beats.repo.j2 dest=/etc/yum.repos.d/beats.repo
template:
src: beats.repo.j2
dest: /etc/yum.repos.d/beats.repo
when: use_repository

- name: RedHat - install yum-version-lock
yum: name=yum-plugin-versionlock state=present update_cache=yes
yum:
name: yum-plugin-versionlock
state: present
update_cache: true
register: versionlock_install
until: versionlock_install is succeeded

- name: RedHat - unlock {{beat}} for install
shell: yum versionlock delete {{beat}} || true
changed_when: False
- name: RedHat - unlock {{ beat }} for install
shell: yum versionlock delete {{ beat }} || true
changed_when: false
tags:
- skip_ansible_lint

- name: RedHat - Ensure {{beat}} is installed
yum: name={{beat}}{% if beats_version is defined and beats_version != "" %}-{{ beats_version }}{% endif %} state=present update_cache=yes
- name: RedHat - Ensure {{ beat }} is installed
yum:
name: >-
{{ beat }}{% if beats_version is defined and beats_version|length %}-{{ beats_version }}{% endif %}
state: present
update_cache: true
register: beat_install
until: beat_install is succeeded
when: use_repository
notify: restart {{beat}}
notify: restart {{ beat }}

- name: RedHat - lock {{beat}} version
shell: yum versionlock add {{beat}}{% if beats_version is defined and beats_version != "" %}-{{ beats_version }}{% endif %}
- name: RedHat - lock {{ beat }} version
shell: >-
yum versionlock add
{{ beat }}{% if beats_version is defined and beats_version|length %}-{{ beats_version }}{% endif %}
when: version_lock
changed_when: False
changed_when: false
tags:
- skip_ansible_lint

- name: RedHat - Install {{beat}} from url
yum: name={% if custom_package_url is defined %}{{ custom_package_url }}{% else %}{{ beats_package_url }}/{{beat}}-{{ beats_version }}-{{ansible_architecture}}.rpm{% endif %} state=present
- name: RedHat - Install {{ beat }} from url
yum:
name: >-
{% if custom_package_url is defined %}{{ custom_package_url }}{%
else %}{{ beats_package_url }}/{{ beat }}-{{ beats_version }}-{{ ansible_architecture }}.rpm{% endif %}
state: present
register: beat_install
until: beat_install is succeeded
when: not use_repository
notify: restart {{beat}}
notify: restart {{ beat }}
11 changes: 7 additions & 4 deletions tasks/beats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
# Install OS specific beats

- name: Include specific Beats
include: beats-debian.yml
include_tasks: beats-debian.yml
when: ansible_os_family == 'Debian'

- name: Include specific Beats
include: beats-redhat.yml
include_tasks: beats-redhat.yml
when: ansible_os_family == 'RedHat'

#Configuration file for beats
- name: Beats configuration
include: beats-config.yml
include_tasks: beats-config.yml

# Make sure the service is started, and restart if necessary
- name: Start {{ beat }} service
service: name={{ beat }} state=started enabled=yes
service:
name: '{{ beat }}'
state: started
enabled: true
when: start_service
register: beats_started
6 changes: 3 additions & 3 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# tasks file for beats

- name: check-parameters
include: beats-param-check.yml
include_tasks: beats-param-check.yml

- name: os-specific vars
include_vars: "{{ansible_os_family}}.yml"
include_vars: '{{ ansible_os_family }}.yml'

- include: beats.yml
- include_tasks: beats.yml