From 3adcafa60e11097426efb6bf4181f17990f84ec7 Mon Sep 17 00:00:00 2001 From: dortega Date: Fri, 9 Mar 2018 15:04:17 +0100 Subject: [PATCH] #21 using defaults-file specified in MySQL service --- LICENSE.txt => LICENSE | 2 +- README.md | 8 ++++---- meta/main.yml | 4 ++-- molecule.yml | 9 ++++++--- tasks/config.yml | 23 ++++++++++++---------- tasks/main.yml | 10 +++++----- tasks/users.yml | 7 +++++++ templates/mysql.service.j2 | 39 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 77 insertions(+), 25 deletions(-) rename LICENSE.txt => LICENSE (99%) create mode 100644 templates/mysql.service.j2 diff --git a/LICENSE.txt b/LICENSE similarity index 99% rename from LICENSE.txt rename to LICENSE index 731f303..327f4c5 100644 --- a/LICENSE.txt +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md index e5135fc..0822359 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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 diff --git a/meta/main.yml b/meta/main.yml index 6b2f8b6..b3b2aca 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -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 diff --git a/molecule.yml b/molecule.yml index f1de022..40daf62 100644 --- a/molecule.yml +++ b/molecule.yml @@ -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 diff --git a/tasks/config.yml b/tasks/config.yml index 032aa9f..e644083 100644 --- a/tasks/config.yml +++ b/tasks/config.yml @@ -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 @@ -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 diff --git a/tasks/main.yml b/tasks/main.yml index 76121d6..bd4dfde 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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 diff --git a/tasks/users.yml b/tasks/users.yml index 83b24aa..a39b5af 100644 --- a/tasks/users.yml +++ b/tasks/users.yml @@ -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: diff --git a/templates/mysql.service.j2 b/templates/mysql.service.j2 new file mode 100644 index 0000000..f41c97d --- /dev/null +++ b/templates/mysql.service.j2 @@ -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