Skip to content

Commit

Permalink
#35 Provide additional settings as option files included in playbook
Browse files Browse the repository at this point in the history
  • Loading branch information
dortegau committed Apr 3, 2018
1 parent 2113dfc commit 1ea3ea8
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +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)
### Added
- [#35](https://github.com/idealista/mysql-role/issues/35) *Provide additional settings as option files included in playbook* @dortegau

### Fixed
- [#34](https://github.com/idealista/mysql-role/issues/34) *Adding default value for mysql_datadir variable* @dortegau

Expand Down
9 changes: 7 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ mysql_config_file: /etc/mysql/my.cnf
mysql_pid_file: /var/run/mysqld/mysqld.pid
mysql_datadir: /var/lib/mysql

# Allowing playbooks to provide external option files
mysql_extra_conf_include_dir: /etc/mysql/conf.d/
mysql_extra_conf_playbook_path: "{{ playbook_dir }}/files/mysql/conf"
mysql_extra_conf_template_playbook_path: "{{ playbook_dir }}/templates/mysql/conf"

# Databases.
mysql_databases: []
# - name: example
Expand Down Expand Up @@ -45,11 +50,11 @@ mysql_remount_run_partition_size: 512M
## https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html
mysql_global_variables:
include_dirs:
- /etc/mysql/conf.d/
- "{{ mysql_extra_conf_include_dir }}"
groups:
client:
user: "{{ mysql_user }}"
password: mysql_root_password
password: "{{ mysql_root_password }}"
port: 3306
socket: /var/run/mysqld/mysqld.sock
mysqld:
Expand Down
2 changes: 2 additions & 0 deletions molecule/default/files/mysql/conf/test_file.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Empty file to test !includedir directive with additional option files
# provided as file
3 changes: 3 additions & 0 deletions molecule/default/templates/mysql/conf/test_template.cnf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# {{ ansible_managed }}
# Empty template to test !includedir directive with additional option files
# provided as template
17 changes: 17 additions & 0 deletions molecule/default/tests/test_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ file:
group: {{ mysql_group }}
exists: true
filetype: directory
{{ mysql_extra_conf_include_dir }}:
owner: {{ mysql_user }}
group: {{ mysql_group }}
exists: true
filetype: directory
"{{ mysql_extra_conf_include_dir }}/test_file.cnf":
owner: {{ mysql_user }}
group: {{ mysql_group }}
exists: true
filetype: file
mode: "0600"
"{{ mysql_extra_conf_include_dir }}/test_template.cnf":
owner: {{ mysql_user }}
group: {{ mysql_group }}
exists: true
filetype: file
mode: "0600"

mount:
/run:
Expand Down
48 changes: 45 additions & 3 deletions tasks/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,50 @@
mode: 0600
notify: restart mysql

- name: MySQL | Ensure additional options file include dir exists
file:
path: "{{ mysql_extra_conf_include_dir }}"
state: directory
owner: "{{ mysql_user }}"
group: "{{ mysql_group }}"
mode: 0600

- name: MySQL | Ensure additional options file and template paths exists
file:
path: "{{ mysql_extra_conf_include_dir }}/{{ item.path }}"
state: directory
owner: "{{ mysql_user }}"
group: "{{ mysql_group }}"
mode: 0600
with_filetree:
- "{{ mysql_extra_conf_playbook_path }}/"
- "{{ mysql_extra_conf_template_playbook_path }}/"
when: item.state == "directory"

- name: MySQL | Copy extra option files (provided by playbooks)
copy:
src: "{{ item.src }}"
dest: "{{ mysql_extra_conf_include_dir }}/{{ item.path }}"
owner: "{{ mysql_user }}"
group: "{{ mysql_group }}"
mode: 0600
with_filetree:
- "{{ mysql_extra_conf_playbook_path }}/"
when: item.state == "file"
notify: restart mysql

- name: MySQL | Copy extra option files templates (provided by playbooks)
template:
src: "{{ item.src }}"
dest: "{{ mysql_extra_conf_include_dir }}/{{ item.path | splitext | first }}" # This is to remove .j2 extension
owner: "{{ mysql_user }}"
group: "{{ mysql_group }}"
mode: 0600
with_filetree:
- "{{ mysql_extra_conf_template_playbook_path }}/"
when: item.state == "file"
notify: restart mysql

- name: MySQL | Ensure datadir exists
file:
path: "{{ mysql_datadir }}"
Expand All @@ -30,13 +74,11 @@
ignore_errors: "yes"
changed_when: false

- name: MySQL | Flush handlers to restart MySQL after previous initialization
meta: flush_handlers

- name: MySQL | Ensure MySQL is started and enabled on boot
service:
name: mysql
state: started
enabled: "yes"

- name: MySQL | Flush handlers to restart MySQL after previous initialization
meta: flush_handlers

0 comments on commit 1ea3ea8

Please sign in to comment.