Skip to content

Commit

Permalink
Merge pull request #1 from CoffeeITWorks/support_ubuntu1604
Browse files Browse the repository at this point in the history
Support ubuntu1604
  • Loading branch information
pablodav authored Jan 10, 2019
2 parents a1507dc + 18024e6 commit 00dd5d7
Show file tree
Hide file tree
Showing 36 changed files with 702 additions and 26 deletions.
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# http://www.jeffgeerling.com/blog/testing-ansible-roles-travis-ci-github
sudo: required
language: python
services:
- docker
before_install:
- sudo apt-get -qq update
#- docker build --tag molecule_local/fedora-rawhide2:latest -f molecule/default/fedorar/Dockerfile molecule/default/fedorar

install:
- sudo apt-get install -y python-pip libssl-dev libffi-dev
- pip install molecule
- pip install docker-py
#- ansible-galaxy install -r requirements.yml

script:
- molecule --debug create
- molecule converge
- molecule syntax
#- molecule idempotence

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
18 changes: 18 additions & 0 deletions ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# config file for ansible -- http://ansible.com/
# ==============================================

# nearly all parameters can be overridden in ansible-playbook
# or with command line flags. ansible will read ANSIBLE_CONFIG,
# ansible.cfg in the current working directory, .ansible.cfg in
# the home directory or /etc/ansible/ansible.cfg, whichever it
# finds first

[defaults]
roles_path = ../:/etc/ansible/roles:~/.ansible/roles
host_key_checking = False

retry_files_enabled = False
callback_whitelist = profile_tasks

[ssh_connection]
pipelining = False
26 changes: 25 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

snmptt_strip_domain:
- testdomain.net
snmptt_resolve_value_ip_addresses: 0
snmptt_net_snmp_perl_enable: 1
snmptt_net_snmp_perl_best_guess: 0
snmptt_translate_log_trap_oid: 2
snmptt_translate_value_oids: 2
snmptt_translate_enterprise_oid_format: 2
snmptt_translate_trap_oid_format: 2
snmptt_translate_varname_oid_format: 1
snmptt_translate_integers: 1
snmptt_description_mode: 2
snmptt_description_clean: 0
snmptt_threads_enable: 1
snmptt_threads_max: 10

nagios_etc: '/usr/local/nagios/etc'
nagios_config_cfg_dir: "{{ nagios_etc }}/conf.d"
nagios_service: "nagios"
Expand Down Expand Up @@ -42,6 +56,16 @@ nagios_snmptrap_nagios_service_template_lines:
- 'notification_period 24x7'
- 'notification_options u,c,r ; Will not send email for warnings'
- 'contact_groups admins ; Modify this to match your Nagios contact group definitions'
- 'check_interval 120 ; Don not clear for 2 hours'
- 'check_interval 120 ; clear each 2 hours'
- 'notes This service is automatically cleared every 2hs, so please create ticket if is alerted. Also ensure to attach all details in status information, as it could be any event from snmp trap.'

snmptt_trap_files:
- /etc/snmp/snmptt.conf
- /etc/snmp/snmptt.conf.prime
- /etc/snmp/snmptt.conf.cisco.config
- /etc/snmp/snmptt.conf.cisco.if
- /etc/snmp/snmptt.conf.if
- /etc/snmp/snmptt.conf.cisco.syslog
- /etc/snmp/snmptt.conf.hh3c-config
- /etc/snmp/snmptt.conf.hh3c-sys-man
- /etc/snmp/snmptt.conf.hh3c_ui-man
14 changes: 14 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
name: supervisor
state: restarted
sleep: 5
when: snmptrap_config_supervisor

- name: restart snmptt
service:
Expand All @@ -21,9 +22,22 @@
service:
name: "{{ nagios_service }}"
state: reloaded
notify: restart nagios

- name: restart nagios
service:
name: "{{ nagios_service }}"
state: restarted

- name: restart snmptrapd
supervisorctl:
name: snmptrapd
state: restarted
when: snmptrap_config_supervisor

- name: restart snmptrapd systemd
service:
name: snmptrapd
state: restarted
when: not snmptrap_config_supervisor

19 changes: 19 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
galaxy_info:
author: Diego Daguerre, Pablo Estigarribia
description: Install and setup snmp traps services and dependencies
license: GPLv2
min_ansible_version: 2.0
platforms:
- name: Ubuntu
versions:
- trusty
- xenial
- bionic
galaxy_tags:
- monitoring
- infraestructure
allow_duplicates: no
dependencies:
- role: coffeeitworks.ansible_nagios4_checkmk_livestatus
tags: ["install", "nagios_server_all", "nagios_server"]
24 changes: 24 additions & 0 deletions molecule/default/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Molecule managed

FROM {{ item.image }}

RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get upgrade -y && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \
elif [ $(command -v yum) ]; then yum makecache fast && yum update -y && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
elif [ $(command -v zypper) ]; then zypper refresh && zypper update -y && zypper install -y python sudo bash python-xml && zypper clean -a; \
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; fi

RUN if [ $(command -v dnf) ]; then dnf -y update && dnf clean all; fi

RUN if [ $(command -v dnf) ]; then dnf -y install systemd hostname && dnf clean all && \
(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*; fi

# VOLUME [ "/sys/fs/cgroup" ]
# CMD ["/usr/sbin/init"]
16 changes: 16 additions & 0 deletions molecule/default/INSTALL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
*******
Install
*******

Requirements
============

* Docker Engine
* docker-py

Install
=======

.. code-block:: bash
$ sudo pip install docker-py
59 changes: 59 additions & 0 deletions molecule/default/create.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
- name: Create
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
vars:
molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}"
molecule_ephemeral_directory: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}"
molecule_scenario_directory: "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}"
molecule_yml: "{{ lookup('file', molecule_file) | molecule_from_yaml }}"
tasks:
- name: Create Dockerfiles from image names
template:
src: "{{ molecule_scenario_directory }}/Dockerfile.j2"
dest: "{{ molecule_ephemeral_directory }}/Dockerfile_{{ item.image | regex_replace('[^a-zA-Z0-9_]', '_') }}"
with_items: "{{ molecule_yml.platforms }}"
register: platforms

- name: Discover local Docker images
docker_image_facts:
name: "molecule_local/{{ item.item.name }}"
with_items: "{{ platforms.results }}"
register: docker_images

- name: Build an Ansible compatible image
docker_image:
path: "{{ molecule_ephemeral_directory }}"
name: "molecule_local/{{ item.item.image }}"
dockerfile: "{{ item.item.dockerfile | default(item.invocation.module_args.dest) }}"
force: "{{ item.item.force | default(true) }}"
with_items: "{{ platforms.results }}"
when: platforms.changed or docker_images.results | map(attribute='images') | select('equalto', []) | list | count >= 0

- name: Create molecule instance(s)
docker_container:
name: "{{ item.name }}"
hostname: "{{ item.name }}"
image: "molecule_local/{{ item.image }}"
state: started
recreate: false
log_driver: syslog
command: "{{ item.command | default('bash -c \"while true; do sleep 10000; done\"') }}"
privileged: "{{ item.privileged | default(omit) }}"
volumes: "{{ item.volumes | default(omit) }}"
capabilities: "{{ item.capabilities | default(omit) }}"
ports: "{{ item.exposed_ports | default(omit) }}"
register: server
with_items: "{{ molecule_yml.platforms }}"
async: 7200
poll: 0

- name: Wait for instance(s) creation to complete
async_status:
jid: "{{ item.ansible_job_id }}"
register: docker_jobs
until: docker_jobs.finished
retries: 300
with_items: "{{ server.results }}"
27 changes: 27 additions & 0 deletions molecule/default/destroy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
- name: Destroy
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
vars:
molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}"
molecule_yml: "{{ lookup('file', molecule_file) | molecule_from_yaml }}"
tasks:
- name: Destroy molecule instance(s)
docker_container:
name: "{{ item.name }}"
state: absent
force_kill: "{{ item.force_kill | default(true) }}"
register: server
with_items: "{{ molecule_yml.platforms }}"
async: 7200
poll: 0

- name: Wait for instance(s) deletion to complete
async_status:
jid: "{{ item.ansible_job_id }}"
register: docker_jobs
until: docker_jobs.finished
retries: 300
with_items: "{{ server.results }}"
66 changes: 66 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
dependency:
name: galaxy
options:
ignore-certs: True
ignore-errors: True
role-file: requirements.yml
driver:
name: docker
lint:
name: yamllint
platforms:

- name: ansible_test-01
image: paulfantom/ubuntu-molecule:16.04
#privileged: True
command: /sbin/init
capabilities:
- SYS_ADMIN
volumes:
- "/sys/fs/cgroup:/sys/fs/cgroup:ro"
groups:
- group1

- name: ansible_test-01_2
image: paulfantom/ubuntu-molecule:18.04
#privileged: True
command: /sbin/init
capabilities:
- SYS_ADMIN
volumes:
- "/sys/fs/cgroup:/sys/fs/cgroup:ro"
groups:
- group1

- name: ansible_test-02
image: ubuntu:trusty
groups:
- groupold
#
# - name: ansible_test-03
# image: centos/systemd
# command: /sbin/init
# capabilities:
# - SYS_ADMIN
# volumes:
# - "/sys/fs/cgroup:/sys/fs/cgroup:ro"
#privileged: True
# groups:
# - group1

provisioner:
name: ansible
config_options:
defaults:
callback_whitelist: profile_tasks
lint:
name: ansible-lint

scenario:
name: default

verifier:
name: testinfra
lint:
name: flake8
10 changes: 10 additions & 0 deletions molecule/default/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Converge
hosts: all
vars:
nagios_update_hosts_file: true
roles:
- role: ansible-role-nagios
- role: coffeeitworks.ansible_nagios4_server_config
- role: coffeeitworks.ansible_nagios4_checkmk_livestatus
- role: ansible_nagios4_server_snmptrap
5 changes: 5 additions & 0 deletions molecule/default/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Prepare
hosts: all
gather_facts: false
tasks: []
11 changes: 11 additions & 0 deletions molecule/default/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# from GitHub, overriding the name and specifying a specific tag
- src: https://github.com/CoffeeITWorks/ansible-role-nagios.git
version: master
name: ansible-role-nagios

- src: geerlingguy.repo-epel

- src: coffeeitworks.ansible_nagios4_server_config

- src: coffeeitworks.ansible_nagios4_checkmk_livestatus
version: 1.1.0
14 changes: 14 additions & 0 deletions molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os

import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')


def test_hosts_file(host):
f = host.file('/etc/hosts')

assert f.exists
assert f.user == 'root'
assert f.group == 'root'
Binary file added molecule/default/tests/test_default.pyc
Binary file not shown.
24 changes: 24 additions & 0 deletions molecule/local/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Molecule managed

FROM {{ item.image }}

RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get upgrade -y && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \
elif [ $(command -v yum) ]; then yum makecache fast && yum update -y && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
elif [ $(command -v zypper) ]; then zypper refresh && zypper update -y && zypper install -y python sudo bash python-xml && zypper clean -a; \
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; fi

RUN if [ $(command -v dnf) ]; then dnf -y update && dnf clean all; fi

RUN if [ $(command -v dnf) ]; then dnf -y install systemd hostname && dnf clean all && \
(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*; fi

# VOLUME [ "/sys/fs/cgroup" ]
# CMD ["/usr/sbin/init"]
Loading

0 comments on commit 00dd5d7

Please sign in to comment.