Skip to content

Commit

Permalink
Merge pull request #28 from idealista/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
dortegau authored Mar 15, 2018
2 parents 45f5633 + cd7f789 commit 3b43528
Show file tree
Hide file tree
Showing 25 changed files with 286 additions and 159 deletions.
2 changes: 0 additions & 2 deletions .flake8

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ tests/__pycache__
.molecule
.vagrant
.cache
Pipfile
Pipfile.lock
9 changes: 3 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
language: python
python: "2.7.13"
sudo: required
language: python
services:
- docker
install:
- pip install ansible==2.4.3.0
- pip install molecule==1.25.0
- pip install ansible-lint==3.4.20
- pip install docker
- pip install pipenv
- pipenv install -r test-requirements.txt --python 2.7
script:
- molecule test --driver docker
- pipenv run molecule test

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
13 changes: 13 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
extends: default

rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
line-length: disable
# NOTE(retr0h): Templates no longer fail this lint rule.
# Uncomment if running old Molecule templates.
# truthy: disable
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a ch

## [Unreleased](https://github.com/idealista-tech/mysql-role/tree/develop)

## [1.3.0](https://github.com/idealista-tech/mysql-role/tree/1.3.0) (15/03/2018)
[Full Changelog](https://github.com/idealista/mysql-role/compare/1.3.0...1.2.3)
### Added
- [#26](https://github.com/idealista/mysql-role/issues/26) *Adding the ability to configure SQL mode* @dortegau

### Changed
- [#25](https://github.com/idealista/mysql-role/issues/25) *Migrating to Molecule 2.10.1* @dortegau

### Fixed
- [#24](https://github.com/idealista/mysql-role/issues/24) *Fixing my.cnf template (providing value to 'explicit_defaults_for_timestamp')* @dortegau

## [1.2.3](https://github.com/idealista-tech/mysql-role/tree/1.2.3) (09/03/2018)
[Full Changelog](https://github.com/idealista/mysql-role/compare/1.2.3...1.2.0)
### Fixed
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![Logo](https://raw.githubusercontent.com/idealista/mysql-role/master/logo.gif)

# MySQL Ansible role
# MySQL Ansible role
[![Build Status](https://travis-ci.org/idealista/mysql-role.png)](https://travis-ci.org/idealista/mysql-role)

This ansible role installs a Prometheus Node Exporter in a debian environment.
Expand All @@ -25,7 +25,7 @@ These instructions will get you a copy of the role for your Ansible playbook. On
Ansible 2.4.3.0 version installed.
Inventory destination should be a Debian environment.

For testing purposes, [Molecule](https://molecule.readthedocs.io/) with [Vagrant](https://www.vagrantup.com/) as driver (with [hostmanager](https://github.com/devopsgroup-io/vagrant-hostmanager) plugin) and [VirtualBox](https://www.virtualbox.org/) as provider.
For testing purposes, [Molecule](https://molecule.readthedocs.io/) with Docker as driver and [Goss](https://goss.rocks/) as verifier.

### Installing

Expand Down Expand Up @@ -87,14 +87,14 @@ mysql_users:
## Testing
```
$ molecule test
$ pipenv install -r test-requirements.txt -python 2.7
```

To check the installation

```bash
$ molecule converge
$ molecule login --host mysql.vm
$ pipenv run molecule converge
$ pipenv run molecule login

vagrant@mysql:~$ mysql -u root -ptesting

Expand All @@ -113,6 +113,8 @@ mysql> show databases;
## Built With

![Ansible](https://img.shields.io/badge/ansible-2.4.3.0-green.svg)
![Molecule](https://img.shields.io/badge/molecule-2.10.1-green.svg)
![Goss](https://img.shields.io/badge/goss-0.3.5-green.svg)

## Versioning

Expand Down
3 changes: 2 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mysql_group: mysql

## Service options
# start on boot
mysql_service_enabled: True
mysql_service_enabled: true
# current state: started, stopped
mysql_service_state: started

Expand Down Expand Up @@ -45,6 +45,7 @@ mysql_max_connections: 151

# Other settings.
mysql_wait_timeout: 28800
mysql_sql_mode: "ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

# InnoDB settings.
# Set .._buffer_pool_size up to 80% of RAM but beware of setting too high.
Expand Down
93 changes: 0 additions & 93 deletions molecule.yml

This file was deleted.

13 changes: 13 additions & 0 deletions molecule/default/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Molecule managed

{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}

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
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
69 changes: 69 additions & 0 deletions molecule/default/create.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
- 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 docker network(s)
docker_network:
name: "{{ item }}"
state: present
with_items: "{{ molecule_yml.platforms | molecule_get_docker_networks }}"

- name: Create molecule instance(s)
docker_container:
name: "{{ item.name }}"
hostname: "{{ item.name }}"
image: "molecule_local/{{ item.image }}"
state: started
recreate: false
log_driver: json-file
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) }}"
exposed_ports: "{{ item.exposed_ports | default(omit) }}"
published_ports: "{{ item.published_ports | default(omit) }}"
ulimits: "{{ item.ulimits | default(omit) }}"
networks: "{{ item.networks | default(omit) }}"
dns_servers: "{{ item.dns_servers | 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 }}"
33 changes: 33 additions & 0 deletions molecule/default/destroy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
- 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 }}"

- name: Delete docker network(s)
docker_network:
name: "{{ item }}"
state: absent
with_items: "{{ molecule_yml.platforms | molecule_get_docker_networks }}"
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
mysql_databases:
- name: test01
encoding: utf8
Expand Down
28 changes: 28 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
platforms:
- name: mysql
groups:
- mysql_group
image: geerlingguy/docker-debian9-ansible:latest
privileged: true
capabilities:
- SYS_ADMIN
volumes:
- '/sys/fs/cgroup:/sys/fs/cgroup:ro'
command: '/lib/systemd/systemd'
provisioner:
name: ansible
lint:
name: ansible-lint
scenario:
name: default
verifier:
name: goss
lint:
name: flake8
4 changes: 2 additions & 2 deletions tests/playbook.yml → molecule/default/playbook.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---

- hosts: all
- name: Converge
hosts: all
roles:
- role: mysql-role
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: []
Loading

0 comments on commit 3b43528

Please sign in to comment.