Skip to content

Commit

Permalink
Merge pull request #22 from idealista/bugs/21
Browse files Browse the repository at this point in the history
#21 using defaults-file specified in MySQL service
  • Loading branch information
dortegau authored Mar 9, 2018
2 parents 897862d + 6387915 commit 0f80a4c
Show file tree
Hide file tree
Showing 17 changed files with 180 additions and 128 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ language: python
services:
- docker
install:
- pip install ansible==2.3.1.0
- pip install ansible==2.4.3.0
- pip install molecule==1.25.0
- pip install ansible-lint==3.4.20
- pip install docker
script:
- molecule test --driver docker
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a changelog](https://github.com/olivierlacan/keep-a-changelog).

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

### Fixed
- [#21](https://github.com/idealista/mysql-role/issues/21)*Using my.cnf file provided as template instead of installation default file (mysql.cnf)* @dortegau
- *Fixing typo in config filename and changing invalid config values* @dortegau

## [1.2.0](https://github.com/idealista-tech/mysql-role/tree/1.2.0) (10/08/2017)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt → LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work

/**
* Copyright 2017 Idealista S.A.
* Copyright 2018 Idealista S.A.U
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ These instructions will get you a copy of the role for your Ansible playbook. On

### Prerequisities

Ansible 2.2.0.0 version installed.
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 [landrush](https://github.com/vagrant-landrush/landrush) plugin) and [VirtualBox](https://www.virtualbox.org/) as provider.
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.

### Installing

Create or add to your roles dependency file (e.g requirements.yml):

```
- src: http://github.com/idealista/mysql-role.git
scm: git
- src: idealista.mysql-role
version: 1.0.0
name: mysql
```
Expand Down Expand Up @@ -64,7 +63,7 @@ Set at least mysql_root_user and mysql_root_password:

```yaml
mysql_root_user: mysql # Change mysql root user
mysql_root_password: secret # Change mysql root password
mysql_root_password: secret # Change mysql root password
```
Add any number of databases and create users with privs on them
Expand All @@ -89,16 +88,16 @@ mysql_users:
## Testing
```
molecule test
$ molecule test
```

To check the installation

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

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

mysql> show databases;
+--------------------+
Expand All @@ -114,7 +113,7 @@ mysql> show databases;

## Built With

![Ansible](https://img.shields.io/badge/ansible-2.2.0.0-green.svg)
![Ansible](https://img.shields.io/badge/ansible-2.4.3.0-green.svg)

## Versioning

Expand All @@ -132,7 +131,7 @@ See also the list of [contributors](https://github.com/idealista/mysql-role/cont

![Apache 2.0 Licence](https://img.shields.io/hexpm/l/plug.svg)

This project is licensed under the [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0) license - see the [LICENSE.txt](LICENSE.txt) file for details.
This project is licensed under the [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0) license - see the [LICENSE](LICENSE) file for details.

## Contributing

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

galaxy_info:
company: Idealista S.A.
company: Idealista S.A.U
description: MySQL role
min_ansible_version: 2.2
min_ansible_version: 2.4.3.0
license: Apache 2.0
platforms:
- name: Debian
Expand Down
45 changes: 15 additions & 30 deletions molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ molecule:
- .vagrant
- .molecule

# directory to look for goss tests
goss_dir: tests/goss
goss_playbook: verifier.yml

test:
sequence:
- destroy
Expand All @@ -38,9 +42,12 @@ ansible:
# configuration options for the internal call to vagrant
vagrant:
raw_config_args:
- "landrush.enabled = true"
- "landrush.tld = 'vm'"
- "landrush.guest_redirect_dns = false"
- "hostmanager.enabled = true"
# Enable for debug purpose
#- "hostmanager.manage_host = true"
- "hostmanager.manage_guest = true"
- "hostmanager.ignore_private_ip = false"
- "hostmanager.include_offline = true"
# molecule's --platform option will look for these names
platforms:
- name: Debian8
Expand All @@ -56,16 +63,9 @@ vagrant:
cpus: 1

instances:
- name: mysql.vm
ansible_groups:
- test01
interfaces:
- network_name: private_network
type: dhcp
auto_config: true
- name: mysqlUpgrade.vm
- name: mysql
ansible_groups:
- test01
- mysql_group
interfaces:
- network_name: private_network
type: dhcp
Expand All @@ -75,23 +75,8 @@ docker:
containers:
- name: mysql
ansible_groups:
- test01
dockerfile: tests/Dockerfile
image: debian9-testinfra
image_version: latest
# All these parameters are needed for Docker testing with systemd
privileged: True
cap_add:
- SYS_ADMIN
volume_mounts:
- '/sys/fs/cgroup:/sys/fs/cgroup:ro'
command: '/lib/systemd/systemd'

- name: mysqlUpgrade
ansible_groups:
- test01
dockerfile: tests/Dockerfile
image: debian9-testinfra
- mysql_group
image: geerlingguy/docker-debian9-ansible
image_version: latest
# All these parameters are needed for Docker testing with systemd
privileged: True
Expand All @@ -102,7 +87,7 @@ docker:
command: '/lib/systemd/systemd'

verifier:
name: testinfra
name: goss
options:
connection: ansible
ansible-inventory: .molecule/ansible_inventory
23 changes: 13 additions & 10 deletions tasks/config.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
---

- name: MySQL | Copy MySQL service config
template:
src: mysql.service.j2
dest: /lib/systemd/system/mysql.service
owner: "{{ mysql_user }}"
group: "{{ mysql_group }}"
mode: 0755
notify: restart mysql

- name: MySQL | Copy global MySQL configuration
template:
src: my.cnf.j2
dest: "{{ mysql_config_file }}"
owner: root
group: root
owner: "{{ mysql_user }}"
group: "{{ mysql_group }}"
mode: 0600
notify: restart mysql

Expand All @@ -26,11 +35,5 @@
name: mysql
state: started
enabled: yes

- name: MySQL | Set root password
mysql_user:
name: "{{ mysql_root_user }}"
password: "{{ mysql_root_password }}"
login_user: root
login_host: localhost
when: "installed_mysql.stdout != 'Status: install ok installed'"
- name: MySQL | Flush handlers to restart MySQL after previous initialization
meta: flush_handlers
8 changes: 4 additions & 4 deletions tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
tags:
skip_ansible_lint

- name: MySQL | Download mysql config deb
- name: MySQL | Download MySQL config deb
get_url:
url: "{{ mysql_deb_repo }}"
dest: /tmp
validate_certs: no

- name: MySQL | Install mysql repo deb
- name: MySQL | Install MySQL repo deb
apt:
deb: "/tmp/{{ mysql_deb_package }}"

Expand All @@ -24,14 +24,14 @@
allow_unauthenticated: yes
changed_when: false

- name: MySQL | Check if mysql is already installed
- name: MySQL | Check if MySQL is already installed
shell: dpkg -s mysql-server | grep Status
register: installed_mysql
ignore_errors: yes
changed_when: false
failed_when: false

- name: MySQL | Install MYSQL packages
- name: MySQL | Install MySQL packages
apt:
package: "{{ item }}"
state: present
Expand Down
10 changes: 5 additions & 5 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
---

- name: MySQL | Install
include: install.yml
include_tasks: install.yml
tags:
- install

- name: MySQL | Configure
include: config.yml
include_tasks: config.yml
tags:
- configure

- name: MySQL | Users
include: users.yml
include_tasks: users.yml
tags:
- configure
- users

- name: MySQL | Databases
include: databases.yml
include_tasks: databases.yml
tags:
- configure
- databases

- name: MySQL | Service
include: service.yml
include_tasks: service.yml
tags:
- service
7 changes: 7 additions & 0 deletions tasks/users.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
---
- name: MySQL | Set root password
mysql_user:
name: "{{ mysql_root_user }}"
password: "{{ mysql_root_password }}"
login_user: root
login_host: localhost
when: "installed_mysql.stdout != 'Status: install ok installed'"

- name: MySQL | Ensure MySQL users are present
mysql_user:
Expand Down
39 changes: 39 additions & 0 deletions templates/mysql.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# {{ ansible_managed }}
# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

# MySQL systemd service file

[Unit]
Description=MySQL Community Server
After=network.target

[Install]
WantedBy=multi-user.target

[Service]
User={{ mysql_user }}
Group={{ mysql_group }}
Type=forking
PermissionsStartOnly=true
PIDFile={{ mysql_pid_file }}
ExecStartPre=/usr/share/mysql/mysql-systemd-start pre
ExecStart=/usr/sbin/mysqld --defaults-file={{ mysql_config_file }} --daemonize --pid-file={{ mysql_pid_file }}
TimeoutSec=600
LimitNOFILE=5000
Restart=on-failure
RestartPreventExitStatus=1
RuntimeDirectory=mysqld
RuntimeDirectoryMode=755
5 changes: 0 additions & 5 deletions tests/Dockerfile

This file was deleted.

Loading

0 comments on commit 0f80a4c

Please sign in to comment.