Skip to content

Commit

Permalink
Adds documentation (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliendufresne committed Jul 11, 2016
1 parent 150b42f commit c0f1466
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 21 deletions.
18 changes: 18 additions & 0 deletions INSTALL.md
@@ -0,0 +1,18 @@
Installation
============

This repository relies on **Vagrant** and the **VirtualBox** provider.

* Vagrant version 1.8.4+ (needed to install latest ansible version) - [Website](https://www.vagrantup.com/) - [Download page](https://www.vagrantup.com/downloads.html)
* Virtualbox - [Website](https://www.virtualbox.org/) - [Download page](https://www.virtualbox.org/wiki/Downloads)

As you can see you don't even need ansible on your host.

Once this packages are installed, you just need to clone this repository
and run your first test:

$ git clone https://github.com/juliendufresne/test-ansible-roles.git
$ cd test-ansible-roles
$ ./test.sh

> _**Note:** You can install specific ansible version in the guest using the **--pre-script** option_
136 changes: 131 additions & 5 deletions README.md
@@ -1,12 +1,138 @@
Test Ansible Roles
==================

Tests an ansible roles against ubuntu 16.04
Tests your ansible roles in multiple operating systems.

Requirements
Installation
------------

* Vagrant version 1.8.4+ (needed to install latest ansible version)
* Virtualbox - [Website](https://www.virtualbox.org/) - [download page](https://www.virtualbox.org/wiki/Downloads)
Please see the file called [INSTALL.md](INSTALL.md).

Since ansible will be installed in the vagrant box, you don't need it on your host.
Examples
--------

1. Test ansible roles in operating systems defined in [config/default.md](config/default.md)
`$ ./test.sh`
2. Test juliendufresne.influxdb role on bento/ubuntu-16.04 vagrant box with debug if something fails
`$ ./test.sh --verbose --ansible-role juliendufresne.influxdb --vagrant-box bento/ubuntu-16.04`
3. Test ansible roles defined in a custom config file defined in config/debian.md
`$ ./test.sh --config-file debian`
4. Test using the config file config/default.md filtering by ansible role
`$ ./test.sh --ansible-role juliendufresne.influxdb`
4. Test using the config file config/default.md filtering by vagrant box
`$ ./test.sh --vagrant-box bento/centos7`

> **Tips:** First, run your test with a config file then run failed tests manually with the `--verbose` option.
Options
-------

**TL;DR** RTFM: `./test.sh --help`

<details>
<summary>**`--ansible-role ANSIBLE_ROLE`**</summary>
> **Note:** You need to do few things to be able to test any ansible role (see [Adding a role section](#adding-a-role))
This option allows to specify which ansible role to test.
You can specify more than one ansible role.

Examples:

$ ./test.sh --ansible-role juliendufresne.influxdb
$ ./test.sh --ansible-role juliendufresne.influxdb --ansible-role juliendufresne.grafana

> _**Note:** If you don't specify a vagrant box, the script will search in your configuration file_
</details>
<details>
<summary>**`--config-file CONFIG_FILE`** (Recommended)</summary>
A configuration file ease repetitive tests by providing a set of (ansible role, vagrant box) to test.

The script will run one test for each line in the config file (except the headers).
Basically, a line contains an ansible role, a vagrant box and some options that you would define manually otherwise.

Examples:

$ ./test.sh # will load config/default.md
$ ./test.sh --config-file default # will load config/default.md
$ ./test.sh --config-file /home/julien/debian.md # will load /home/julien/debian.md

> **Note:** The configuration file may be anywhere accessible in your computer.
If you specify a relative path, the script will search in:
* your current directory
* the repository root directory
* the repository config directory

> **Note:** You can omit the ".md" extension. This simplify the command line: `./test.sh --config-file default`
> **Note:** If you don't specify a configuration file, the script will try to load the config/default.md file
</details>
<details>
<summary>**`--enable-vbguest`**</summary>
Some vagrant box needs virtual box guest additions to be installed in
order to create a synced folder between your host and the virtual machine.

Since it installs some additional packages and hence, slows the tests, it
is not installed by default.

> **Tips:** If your test doesn't work the first time, try to enable vbguest and see if it solves the problem.
</details>
<details>
<summary>**`--pre-script PRE_SCRIPT`**</summary>
Executes a script in the virtual machine after it is up but before running
ansible playbook.
For instance, vagrant is not able to install the latest version of ansible
in some operating systems (like centos 6). In this case of situation, you
can install it manually using this option.

Example:

$ ./test.sh --pre-script provision/install_ansible.sh --ansible-role juliendufresne.influxdb --vagrant-box bento/centos6

> **Note:** You can only execute one script.
</details>
<details>
<summary>**`-v`**, **`--verbose`**</summary>
Activates the debugging for failed task.

Example:

$ ./test.sh -v
$ ./test.sh --verbose --ansible-role juliendufresne.influxdb --vagrant-box bento/centos7
</details>

<details>
<summary>**`--vagrant-box VAGRANT_BOX`**</summary>

This option allows to specify a vagrant box to test.
You can specify more than one vagrant box.

Examples:

$ ./test.sh --vagrant-box bento/centos6
$ ./test.sh --vagrant-box bento/centos6 --vagrant-box bento/centos7

> _**Note:** If you don't specify an ansible role, the script will search in your configuration file_
</details>
Adding a role
-------------

When you want to test a new role, you need to:
* [ansible galaxy only] add a line in the [requirements.yml](requirements.yml) file.
* create a playbook in the [playbooks](playbooks) directory.
The file name must be `<your_role_name>.yml`. For example, for a role
name juliendufresne.influxdb, you will need a file playbooks/juliendufresne.influxdb.yml
* [local (non galaxy) role] define your role in the playbooks/roles directory

Reports
-------

Every tests are reported in a file located in the reports directory.
Reports are grouped by ansible roles.
If you run a test on the same operating system, it will override the previous report.

You can see an example of report in [reports/juliendufresne.influxdb.md](reports/juliendufresne.influxdb.md)
25 changes: 25 additions & 0 deletions reports/juliendufresne.influxdb.md
@@ -0,0 +1,25 @@
# juliendufresne.influxdb report

Columns explanation
-------------------

* **From scratch** represents the results when you run your ansible playbook on a clean distribution
* **Idempotency** represents the second run of your ansible playbook. It should not contains any changes tasks

Results
-------

| Distribution | Last check date | From scratch | Idempotency |
| ---------------------- | ------------------- | --------------- | ----------- |
| CentOS 6.8 (Final) | 2016-07-11 01:16:06 | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) |
| CentOS 7.2.1511 (Core) | 2016-07-11 01:20:08 | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) |
| Debian 7.9 (wheezy) | 2016-07-11 01:22:47 | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) |
| Debian 7.10 (wheezy) | 2016-07-11 01:26:28 | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) |
| Debian 8.2 (jessie) | 2016-07-11 01:34:21 | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) |
| Debian 8.3 (jessie) | 2016-07-11 01:38:15 | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) |
| Debian 8.4 (jessie) | 2016-07-11 01:42:04 | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) |
| Ubuntu 12.04 (precise) | 2016-07-11 01:45:27 | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) |
| Ubuntu 14.04 (trusty) | 2016-07-11 01:49:06 | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) |
| Ubuntu 15.04 (vivid) | 2016-07-11 01:56:36 | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) |
| Ubuntu 15.10 (wily) | 2016-07-11 02:00:22 | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) |
| Ubuntu 16.04 (xenial) | 2016-07-11 03:26:20 | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) | ![OK](https://img.shields.io/badge/status-pass-brightgreen.svg) |
32 changes: 16 additions & 16 deletions src/_usage.sh
Expand Up @@ -16,22 +16,22 @@ usage() {
${script_name} [OPTION...]
\e[1mDESCRIPTION\e[0m
Test ansible role in a vagrant box
Tests your ansible roles in multiple operating systems.
--ansible-role ANSIBLE_ROLE use specified ansible role instead of default one. This option may be specified
multiple times.
--config-file CONFIG_FILE use specified configuration file.
CONFIG_FILE must end with .md
The file path may be relative to:
- the current working directory
- this project root directory
- this project config directory
To ease usage, you can omit file directory and extension.
e.g: '--config-file default' may be resolved with <repository_root>/config/default.md
--enable-vbguest enable the vagrant-vbguest plugin and install it if needed.
-h, --help show this help.
--pre-script PRE_SCRIPT path to a script to run before running ansible playbook.
-v, --verbose increase verbosity.
--vagrant-box VAGRANT_BOX use specified vagrant box instead of default one. This option may be specified multiple times.
--ansible-role ANSIBLE_ROLE use specified ansible role instead of default one. This option may be specified
multiple times.
--config-file CONFIG_FILE use specified configuration file.
CONFIG_FILE must end with .md
The file path may be relative to:
- the current working directory
- this project root directory
- this project config directory
To ease usage, you can omit file directory and extension.
e.g: '--config-file default' may be resolved with <repository_root>/config/default.md
--enable-vbguest enable the vagrant-vbguest plugin and install it if needed.
-h, --help show this help.
--pre-script PRE_SCRIPT path to a script to run before running ansible playbook.
-v, --verbose increase verbosity.
--vagrant-box VAGRANT_BOX use specified vagrant box instead of default one. This option may be specified multiple times.
"
}

0 comments on commit c0f1466

Please sign in to comment.