feat: install database if datadir doesn't exist
This commit is contained in:
parent
d5d12a0b3b
commit
9c0af58687
5 changed files with 59 additions and 4 deletions
|
@ -4,6 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
Which is based on [Keep A Changelog](http://keepachangelog.com/)
|
Which is based on [Keep A Changelog](http://keepachangelog.com/)
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
- feat: install database if datadir doesn't exist
|
||||||
|
|
||||||
## [v1.0.1] - 2019-03-16
|
## [v1.0.1] - 2019-03-16
|
||||||
- fix: add client-server option in default configuration
|
- fix: add client-server option in default configuration
|
||||||
|
|
37
tasks/initdb.yml
Normal file
37
tasks/initdb.yml
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
---
|
||||||
|
- name: create the data directory
|
||||||
|
file:
|
||||||
|
path: '{{ mariadb_full_config.mysqld.datadir }}'
|
||||||
|
owner: '{{ mariadb_full_config.mysqld.user }}'
|
||||||
|
group: root
|
||||||
|
mode: 0750
|
||||||
|
state: directory
|
||||||
|
tags: mariadb
|
||||||
|
|
||||||
|
- name: initialize database
|
||||||
|
command:
|
||||||
|
args:
|
||||||
|
argv:
|
||||||
|
- mysql_install_db
|
||||||
|
- '--datadir={{ mariadb_full_config.mysqld.datadir }}'
|
||||||
|
- '--user={{ mariadb_full_config.mysqld.user }}'
|
||||||
|
- '--skip-name-resolve'
|
||||||
|
- '--no-defaults'
|
||||||
|
when: True
|
||||||
|
tags: mariadb
|
||||||
|
|
||||||
|
- name: start mariadb
|
||||||
|
systemd:
|
||||||
|
name: mysql
|
||||||
|
state: started
|
||||||
|
tags: mariadb
|
||||||
|
|
||||||
|
- name: wait mysql start
|
||||||
|
pause:
|
||||||
|
seconds: 5
|
||||||
|
tags: mariadb
|
||||||
|
|
||||||
|
- name: set root password
|
||||||
|
command: 'mysqladmin -u root password {{ mariadb_password }}'
|
||||||
|
when: True
|
||||||
|
tags: mariadb
|
|
@ -21,6 +21,15 @@
|
||||||
notify: restart mariadb
|
notify: restart mariadb
|
||||||
tags: mariadb
|
tags: mariadb
|
||||||
|
|
||||||
|
- name: check if datadir exist
|
||||||
|
stat:
|
||||||
|
path: '{{ mariadb_full_config.mysqld.datadir }}'
|
||||||
|
register: st
|
||||||
|
tags: mariadb
|
||||||
|
|
||||||
|
- import_tasks: initdb.yml
|
||||||
|
when: not st.stat.exists
|
||||||
|
|
||||||
- name: enable and start the service
|
- name: enable and start the service
|
||||||
service:
|
service:
|
||||||
name: mysql
|
name: mysql
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
mariadb_config:
|
mariadb_config:
|
||||||
client-server: {}
|
client-server: {}
|
||||||
mysqld:
|
mysqld:
|
||||||
|
datadir: /opt/mariadb
|
||||||
server-id: 5
|
server-id: 5
|
||||||
log-bin: mysql-bin
|
log-bin: mysql-bin
|
||||||
mariadb_databases:
|
mariadb_databases:
|
||||||
|
|
|
@ -16,6 +16,13 @@ puts '================================'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe file('/opt/mariadb') do
|
||||||
|
it { should be_directory }
|
||||||
|
it { should be_mode 750 }
|
||||||
|
it { should be_owned_by 'mysql' }
|
||||||
|
it { should be_grouped_into 'root' }
|
||||||
|
end
|
||||||
|
|
||||||
describe file('/etc/mysql/mariadb.cnf') do
|
describe file('/etc/mysql/mariadb.cnf') do
|
||||||
it { should be_file }
|
it { should be_file }
|
||||||
it { should be_mode 644 }
|
it { should be_mode 644 }
|
||||||
|
@ -33,24 +40,24 @@ describe port(3306) do
|
||||||
it { should be_listening }
|
it { should be_listening }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe command('mysql -u root -e "show databases"') do
|
describe command('mysql -uroot -psecret -e "show databases"') do
|
||||||
its(:exit_status) { should eq 0 }
|
its(:exit_status) { should eq 0 }
|
||||||
its(:stdout) { should contain 'test' }
|
its(:stdout) { should contain 'test' }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe command('mysql -u root -e "select user, host from mysql.user"') do
|
describe command('mysql -uroot -psecret -e "select user, host from mysql.user"') do
|
||||||
its(:exit_status) { should eq 0 }
|
its(:exit_status) { should eq 0 }
|
||||||
its(:stdout) { should contain(/toto.*%/) }
|
its(:stdout) { should contain(/toto.*%/) }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe command('mysql -u root -e "show grants for toto@\'%\'"') do
|
describe command('mysql -uroot -psecret -e "show grants for toto@\'%\'"') do
|
||||||
its(:exit_status) { should eq 0 }
|
its(:exit_status) { should eq 0 }
|
||||||
its(:stdout) do
|
its(:stdout) do
|
||||||
should contain "GRANT ALL PRIVILEGES ON `test`.* TO 'toto'@'%'"
|
should contain "GRANT ALL PRIVILEGES ON `test`.* TO 'toto'@'%'"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe command('mysql -u root -e "show variables where variable_name = \'log_bin\'"') do
|
describe command('mysql -uroot -psecret -e "show variables where variable_name = \'log_bin\'"') do
|
||||||
its(:exit_status) { should eq 0 }
|
its(:exit_status) { should eq 0 }
|
||||||
its(:stdout) { should contain 'ON' }
|
its(:stdout) { should contain 'ON' }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue