Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Commit

Permalink
Configure user, group and mode for config files (#2)
Browse files Browse the repository at this point in the history
* Add configs user,group and mode

* review fixes
  • Loading branch information
hyvs authored and nervo committed Jan 24, 2017
1 parent 7f7097e commit b5ca5bb
Show file tree
Hide file tree
Showing 16 changed files with 350 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/tests/*.retry
25 changes: 25 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
language: generic

sudo: required

services:
- docker

before_install:
- docker pull manala/ansible-debian:wheezy
- docker pull manala/ansible-debian:jessie

script:
- make lint@wheezy
- make test@wheezy
- make lint@jessie
- make test@jessie

notifications:
webhooks:
urls:
- https://galaxy.ansible.com/api/v1/notifications/
- https://webhooks.gitter.im/e/430e0a92ad6370b7b805
on_success: change
on_failure: always
on_start: never
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Change Log
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [1.0.0] - 2016-01-24

### Added
- Install and configure sensu-server, sensu-client and sensu-api
- Install ruby gems
- Configure sensu checks
108 changes: 108 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
.SILENT:
.PHONY: help

## Colors
COLOR_RESET = \033[0m
COLOR_INFO = \033[32m
COLOR_COMMENT = \033[33m

## Role
ROLE_NAME = manala.sensu

## Macros
DOCKER = docker run \
--rm \
--volume `pwd`:/etc/ansible/roles/${ROLE_NAME} \
--volume `pwd`:/srv \
--workdir /srv \
--tty \
--cap-add SYS_PTRACE \
${DOCKER_OPTIONS} \
manala/ansible-debian:${DEBIAN_DISTRIBUTION} \
${DOCKER_COMMAND}

## Help
help:
printf "${COLOR_COMMENT}Usage:${COLOR_RESET}\n"
printf " make [target]\n\n"
printf "${COLOR_COMMENT}Available targets:${COLOR_RESET}\n"
awk '/^[a-zA-Z\-\_0-9\.@]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " ${COLOR_INFO}%-16s${COLOR_RESET} %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)

#######
# Dev #
#######

dev@wheezy: DEBIAN_DISTRIBUTION = wheezy
dev@wheezy: DOCKER_OPTIONS = --interactive
dev@wheezy: DOCKER_COMMAND = /bin/bash
dev@wheezy:
printf "${COLOR_INFO}Run docker...${COLOR_RESET}\n"
$(DOCKER)

dev@jessie: DEBIAN_DISTRIBUTION = jessie
dev@jessie: DOCKER_OPTIONS = --interactive
dev@jessie: DOCKER_COMMAND = /bin/bash
dev@jessie:
printf "${COLOR_INFO}Run docker...${COLOR_RESET}\n"
$(DOCKER)

########
# Lint #
########

lint@wheezy: DEBIAN_DISTRIBUTION = wheezy
lint@wheezy: DOCKER_COMMAND = make lint
lint@wheezy:
printf "${COLOR_INFO}Run docker...${COLOR_RESET}\n"
$(DOCKER)

lint@jessie: DEBIAN_DISTRIBUTION = jessie
lint@jessie: DOCKER_COMMAND = make lint
lint@jessie:
printf "${COLOR_INFO}Run docker...${COLOR_RESET}\n"
$(DOCKER)

lint:
ansible-lint -v .

########
# Test #
########

test@wheezy: DEBIAN_DISTRIBUTION = wheezy
test@wheezy: DOCKER_COMMAND = sh -c 'make test'
test@wheezy:
printf "${COLOR_INFO}Run docker...${COLOR_RESET}\n"
$(DOCKER)

test@jessie: DEBIAN_DISTRIBUTION = jessie
test@jessie: DOCKER_COMMAND = sh -c 'make test'
test@jessie:
printf "${COLOR_INFO}Run docker...${COLOR_RESET}\n"
$(DOCKER)

test: test-install test-config test-configs test-gems

test-install:
ansible-playbook tests/install.yml --syntax-check
ansible-playbook tests/install.yml

test-config:
ansible-playbook tests/config.yml --syntax-check
ansible-playbook tests/config.yml

test-configs:
ansible-playbook tests/configs.yml --syntax-check
ansible-playbook tests/configs.yml

test-gems:
ansible-playbook tests/gems.yml --syntax-check
ansible-playbook tests/gems.yml
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Ansible Role: sensu

# Ansible Role: sensu [![Build Status](https://travis-ci.org/manala/ansible-role-sensu.svg?branch=master)](https://travis-ci.org/manala/ansible-role-sensu)

This role will deal with the setup of __sensu__.

It's part of the Manala <a href="http://www.manala.io" target="_blank">Ansible stack</a> but can be used as a stand alone component.

## Requirements

None.
This role is made to work with the __sensu__ official debian packages, available on the [__sensu__ debian repository](https://sensuapp.org/docs/0.26/platforms/sensu-on-ubuntu-debian.html#sensu-core). Please use the [**manala.apt**](https://galaxy.ansible.com/manala/apt/) role to handle it properly.

## Dependencies

Expand Down Expand Up @@ -40,16 +39,19 @@ Using ansible galaxy requirements file:

## Role Variables

| Name | Default | Type | Description |
| ------------------------------- | --------------------- | ------ | ------------------------ |
| `manala_sensu_services` | [] | array | Enable and start sensu services (sensu-server, sensu-client, sensu-server) |
| `manala_sensu_gems` | [] | array | Install sensu gems (http://sensu-plugins.io/) |
| `manala_sensu_config_template` | ~ | string | |
| `manala_sensu_config` | [] | array | Sensu config directives |
| `manala_sensu_configs_template` | ~ | string | |
| `manala_sensu_configs` | [] | array | Sensu additional configs |
| `manala_sensu_configs_exclusive`| false | array | If true, will remove extra files in /etc/sensu/conf.d |
| `manala_sensu_checks` | [] | array | Sensu checks definitions |
| Name | Default | Type | Description |
| ------------------------------- | ---------------------- | ------ | -------------------------------------------------------------------------- |
| `manala_sensu_services` | [] | Array | Enable and start sensu services (sensu-server, sensu-client, sensu-server) |
| `manala_sensu_gems` | [] | Array | Install sensu gems (http://sensu-plugins.io/) |
| `manala_sensu_config_template` | config/empty.j2 | String | Sensu config base template |
| `manala_sensu_config` | [] | Array | Sensu config directives |
| `manala_sensu_configs_template` | configs/default.j2 | String | Sensu configs base template |
| `manala_sensu_configs` | [] | Array | Sensu additional configs |
| `manala_sensu_configs_exclusive`| false | Array | If true, will remove extra files in /etc/sensu/conf.d |
| `manala_sensu_configs_user | root | String | Name of the user that should own config files |
| `manala_sensu_configs_group | sensu | String | Name of the group that should own config files |
| `manala_sensu_configs_mode | 0640 | String | Config files mode |
| `manala_sensu_checks` | [] | Array | Sensu checks definitions |

### Configuration example

Expand Down
13 changes: 9 additions & 4 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
---

manala_sensu_services: []

manala_sensu_gems: []

# Config
manala_sensu_config_template: ~
manala_sensu_config: []

# Gems
manala_sensu_gems: []

# Configs
manala_sensu_configs_template: ~
manala_sensu_configs: []
manala_sensu_configs_exclusive: false
manala_sensu_configs_user: ~
manala_sensu_configs_group: ~
manala_sensu_configs_mode: ~

# Checks
manala_sensu_checks: []

# Services
manala_sensu_services: []
3 changes: 3 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ galaxy_info:
- wheezy
- jessie
galaxy_tags:
- alerting
- monitoring
- system
- sensu
7 changes: 5 additions & 2 deletions tasks/configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

- name: configs > Templates
template:
src: "{{ item.template|default(manala_sensu_configs_template|ternary(manala_sensu_configs_template, 'configs/default.json.j2')) }}"
dest: "{{ manala_sensu_configs_dir }}/{{ item.file }}"
src: "{{ item.template|default(manala_sensu_configs_template|ternary(manala_sensu_configs_template, 'configs/default.j2')) }}"
dest: "{{ manala_sensu_configs_dir }}/{{ item.file }}"
owner: "{{ item.user|default(manala_sensu_configs_user|ternary(manala_sensu_configs_user, 'root')) }}"
group: "{{ item.group|default(manala_sensu_configs_group|ternary(manala_sensu_configs_group, 'root')) }}"
mode: "{{ item.mode|default(manala_sensu_configs_mode|ternary(manala_sensu_configs_mode, '0644')) }}"
with_items: "{{ manala_sensu_configs }}"
notify:
- sensu restart
Expand Down
21 changes: 9 additions & 12 deletions tasks/gems.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
---

- set_fact:
_manala_sensu_embedded_ruby: "{{ manala_sensu_config.EMBEDDED_RUBY|default(false) }}"

- name: packages > Setup gem packages
gem:
name: "{{ item.name }}"
executable: "{{ item.executable|default('/opt/sensu/embedded/bin/gem' if _manala_sensu_embedded_ruby else omit) }}"
gem_source: "{{ item.gem_source|default(omit) }}"
include_dependencies: "{{ item.include_dependencies|default(omit) }}"
pre_release: "{{ item.pre_release|default(omit) }}"
repository: "{{ item.repository|default(omit) }}"
state: "{{ item.state|default(omit) }}"
user_install: "{{ item.user_install|default(false) }}"
version: "{{ item.version|default(omit) }}"
name: "{{ item.name }}"
executable: "{{ item.executable|default((manala_sensu_config.EMBEDDED_RUBY|default(false))|ternary('/opt/sensu/embedded/bin/gem', omit)) }}"
gem_source: "{{ item.gem_source|default(omit) }}"
include_dependencies: "{{ item.include_dependencies|default(omit) }}"
pre_release: "{{ item.pre_release|default(omit) }}"
repository: "{{ item.repository|default(omit) }}"
state: "{{ item.state|default(omit) }}"
user_install: "{{ item.user_install|default(false) }}"
version: "{{ item.version|default(omit) }}"
with_items: "{{ manala_sensu_gems }}"
3 changes: 3 additions & 0 deletions tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
apt:
name: "{{ item }}"
state: present
install_recommends: false
update_cache: true
cache_valid_time: 3600
with_items:
- sensu
File renamed without changes.
28 changes: 28 additions & 0 deletions tests/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---

- hosts: all

vars:
manala_sensu_config:
EMBEDDED_RUBY: true
LOG_LEVEL: warn

pre_tasks:
- include: pre_tasks/apt.yml

roles:
- manala.sensu

post_tasks:

- name: Goss
raw: "{{ 'echo \"' ~ item|to_yaml ~ '\"|goss -g - validate' }}"
with_items:
- file:
/etc/default/sensu:
exists: true
owner: root
group: root
contains:
- EMBEDDED_RUBY=true
- LOG_LEVEL=warn
48 changes: 48 additions & 0 deletions tests/configs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---

- hosts: all

vars:
manala_sensu_configs_user: root
manala_sensu_configs_group: sensu
manala_sensu_configs_mode: '0640'

manala_sensu_configs:
- file: transport.json
config:
transport:
name: redis
- file: redis.json
user: sensu
group: sensu
mode: '0600'
config:
redis:
host: localhost

pre_tasks:
- include: pre_tasks/apt.yml

roles:
- manala.sensu

post_tasks:

- name: Goss
raw: "{{ 'echo \"' ~ item|to_yaml ~ '\"|goss -g - validate' }}"
with_items:
- file:
/etc/sensu/conf.d/transport.json:
exists: true
owner: root
group: sensu
mode: '0640'
contains:
- redis
/etc/sensu/conf.d/redis.json:
exists: true
owner: sensu
group: sensu
mode: '0600'
contains:
- localhost
25 changes: 25 additions & 0 deletions tests/gems.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---

- hosts: all

vars:
manala_sensu_config:
EMBEDDED_RUBY: true
manala_sensu_gems:
- name: sensu-plugins-slack
version: 1.0.0

pre_tasks:
- include: pre_tasks/apt.yml

roles:
- manala.sensu

post_tasks:

- name: Goss
raw: "{{ 'echo \"' ~ item|to_yaml ~ '\"|goss -g - validate' }}"
with_items:
- command:
/opt/sensu/embedded/bin/gem list|grep sensu-plugins-slack:
exit-status: 0
Loading

0 comments on commit b5ca5bb

Please sign in to comment.