Skip to content

Commit

Permalink
#21 using defaults-file specified in MySQL service
Browse files Browse the repository at this point in the history
  • Loading branch information
dortegau committed Mar 9, 2018
1 parent 897862d commit 3adcafa
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 25 deletions.
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ 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

Expand Down Expand Up @@ -114,7 +114,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 +132,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
9 changes: 6 additions & 3 deletions molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,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 Down
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
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

0 comments on commit 3adcafa

Please sign in to comment.