Skip to content

Commit

Permalink
add tests; move to GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfantom committed Jun 4, 2017
1 parent e55aa80 commit a782a3c
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 14 deletions.
42 changes: 42 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!groovy

/* Declarative pipeline */
pipeline {
agent {
node {
label 'master'
customWorkspace 'workspace/nginx'
}
}
stages {
stage('Prepare environment') {
steps {
sh 'molecule create'
sh 'molecule converge'
}
}
stage('Check syntax') {
steps {
sh 'molecule syntax'
}
}
stage('Run Tests'){
steps {
sh 'molecule idempotence'
sh 'molecule verify'
}
}
}

post {
always {
sh 'molecule destroy'
}
success {
mattermostSend color: 'good', message: "Job ${JOB_NAME} ${BUILD_NUMBER} has finished successfully (<${BUILD_URL}|Open>)"
}
failure {
mattermostSend color: 'danger', message: "Job ${JOB_NAME} ${BUILD_NUMBER} has failed(<${BUILD_URL}|Open>)"
}
}
}
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
Install and configure nginx
===========================
![Logo](https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Nginx_logo.svg/2000px-Nginx_logo.svg.png)

This role will install and configure nginx and its sites. It supports SSL/TLS
termination and letsencrypt autorenewal directory.
Ansible Role: nginx
===================

[![Build Status](https://ci.devops.sosoftware.pl/buildStatus/icon?job=SoInteractive/nginx/master)](https://ci.devops.sosoftware.pl/job/SoInteractive/nginx/master) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) [![Ansible Role](https://img.shields.io/ansible/role/18220.svg)](https://galaxy.ansible.com/SoInteractive/nginx/) [![Twitter URL](https://img.shields.io/twitter/follow/sointeractive.svg?style=social&label=Follow%20%40SoInteractive)](https://twitter.com/sointeractive)

This role will install and configure nginx and its sites. It supports SSL/TLS termination and letsencrypt autorenewal directory.

Disclaimer
----------
Some ideas taken from: https://github.com/jdauphant/ansible-role-nginx

Requirements
------------

None
Ideas taken from https://github.com/jdauphant/ansible-role-nginx

Examples
--------

Use it in a playbook as follows, assuming you already have docker setup:
Use it in a playbook as follows:
```yaml
- hosts: all
become: true
roles:
- users
- SoInteractive.nginx

```

Whenever needed, you can pass `nginx_dh_remove_old=true` to ansible-playbook
execution to remove previous Diffie-Hellman parameters

Expand Down
1 change: 0 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ nginx_http_params:
- server_tokens off
- types_hash_max_size 2048


nginx_remove_configs: []

nginx_security_headers:
Expand Down
3 changes: 2 additions & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ galaxy_info:
author: Pawel Krupa
description: Nginx installation and config
company: Sointeractive
license: MIT
min_ansible_version: 2.0
platforms:
- name: EL
Expand All @@ -14,9 +15,9 @@ galaxy_info:
- xenial
galaxy_tags:
- nginx
- letsencrypt
- ssl
- proxy
- letsencrypt

#dependencies:
# - { role: username.common }
Expand Down
19 changes: 19 additions & 0 deletions molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
ansible:
playbook: tests/playbook.yml
driver:
name: docker
verifier:
name: testinfra
docker:
containers:
- name: nginx-ubuntu
image: docker
image_version: xenial
ansible_groups:
- group1
- name: nginx-centos
image: centos
image_version: 7
ansible_groups:
- group2
4 changes: 4 additions & 0 deletions tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
localhost
[group1]
docker

4 changes: 4 additions & 0 deletions tests/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- hosts: all
roles:
- docker
58 changes: 58 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from testinfra.utils.ansible_runner import AnsibleRunner

testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all')


def test_directories(File):
present = [
"/etc/nginx",
"/etc/nginx/snippets",
"/etc/nginx/sites-enabled",
"/etc/nginx/sites-available"
]
if present:
for directory in present:
d = File(directory)
assert d.is_directory
assert d.exists


def test_files(File):
def test_files(File):
present = [
"/etc/nginx/nginx.conf"
]
absent = [
"/etc/nginx/sites-enabled/default"
]
if present:
for file in present:
f = File(file)
assert f.exists
assert f.is_file
if absent:
for file in absent:
d = File(file)
assert not d.exists



def test_service(Service):
present = [
"nginx"
]
if present:
for service in present:
s = Service(service)
assert s.is_running
assert s.is_enabled


def test_packages(Package):
present = [
"nginx"
]
if present:
for package in present:
p = Package(package)
assert p.is_installed

0 comments on commit a782a3c

Please sign in to comment.