diff --git a/README.md b/README.md index 56be157..c27a9c9 100644 --- a/README.md +++ b/README.md @@ -217,6 +217,10 @@ What is the group used for root? What to set the package to. Can be 'present', 'absent', or 'x.y.z'. +#####`package_manage` + +Whether to manage the mysql server package. Defaults to true. + #####`package_name` The name of the mysql server package to install. @@ -471,6 +475,10 @@ Pass install_options array to managed package resources. You must be sure to pas What to set the package to. Can be 'present', 'absent', or 'x.y.z'. +#####`package_manage` + +Whether to manage the mysql client package. Defaults to true. + #####`package_name` What is the name of the mysql client package to install. diff --git a/manifests/client.pp b/manifests/client.pp index 2b84e59..3d5d706 100644 --- a/manifests/client.pp +++ b/manifests/client.pp @@ -3,6 +3,7 @@ class mysql::client ( $bindings_enable = $mysql::params::bindings_enable, $install_options = undef, $package_ensure = $mysql::params::client_package_ensure, + $package_manage = $mysql::params::client_package_manage, $package_name = $mysql::params::client_package_name, ) inherits mysql::params { diff --git a/manifests/client/install.pp b/manifests/client/install.pp index 068fe24..8ffff5b 100644 --- a/manifests/client/install.pp +++ b/manifests/client/install.pp @@ -1,9 +1,13 @@ class mysql::client::install { - package { 'mysql_client': - ensure => $mysql::client::package_ensure, - install_options => $mysql::client::install_options, - name => $mysql::client::package_name, + if $mysql::client::package_manage { + + package { 'mysql_client': + ensure => $mysql::client::package_ensure, + install_options => $mysql::client::install_options, + name => $mysql::client::package_name, + } + } } diff --git a/manifests/params.pp b/manifests/params.pp index 8382a7b..095a93e 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -7,9 +7,11 @@ class mysql::params { $restart = false $root_password = 'UNSET' $server_package_ensure = 'present' + $server_package_manage = true $server_service_manage = true $server_service_enabled = true $client_package_ensure = 'present' + $client_package_manage = true $create_root_user = true $create_root_my_cnf = true # mysql::bindings diff --git a/manifests/server.pp b/manifests/server.pp index b309b7b..f3f0189 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -7,6 +7,7 @@ class mysql::server ( $old_root_password = $mysql::params::old_root_password, $override_options = {}, $package_ensure = $mysql::params::server_package_ensure, + $package_manage = $mysql::params::server_package_manage, $package_name = $mysql::params::server_package_name, $purge_conf_dir = $mysql::params::purge_conf_dir, $remove_default_accounts = false, diff --git a/manifests/server/install.pp b/manifests/server/install.pp index 5fb89db..f8b42a2 100644 --- a/manifests/server/install.pp +++ b/manifests/server/install.pp @@ -1,35 +1,38 @@ # class mysql::server::install { - package { 'mysql-server': - ensure => $mysql::server::package_ensure, - install_options => $mysql::server::install_options, - name => $mysql::server::package_name, - } + if $mysql::server::package_manage { - # Build the initial databases. - $mysqluser = $mysql::server::options['mysqld']['user'] - $datadir = $mysql::server::options['mysqld']['datadir'] - $basedir = $mysql::server::options['mysqld']['basedir'] - $config_file = $mysql::server::config_file + package { 'mysql-server': + ensure => $mysql::server::package_ensure, + install_options => $mysql::server::install_options, + name => $mysql::server::package_name, + } - if $mysql::server::manage_config_file { - $install_db_args = "--basedir=${basedir} --defaults-extra-file=${config_file} --datadir=${datadir} --user=${mysqluser}" - } else { - $install_db_args = "--basedir=${basedir} --datadir=${datadir} --user=${mysqluser}" - } + # Build the initial databases. + $mysqluser = $mysql::server::options['mysqld']['user'] + $datadir = $mysql::server::options['mysqld']['datadir'] + $basedir = $mysql::server::options['mysqld']['basedir'] + $config_file = $mysql::server::config_file - exec { 'mysql_install_db': - command => "mysql_install_db ${install_db_args}", - creates => "${datadir}/mysql", - logoutput => on_failure, - path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin', - require => Package['mysql-server'], - } + if $mysql::server::manage_config_file { + $install_db_args = "--basedir=${basedir} --defaults-extra-file=${config_file} --datadir=${datadir} --user=${mysqluser}" + } else { + $install_db_args = "--basedir=${basedir} --datadir=${datadir} --user=${mysqluser}" + } - if $mysql::server::restart { - Exec['mysql_install_db'] { - notify => Class['mysql::server::service'], + exec { 'mysql_install_db': + command => "mysql_install_db ${install_db_args}", + creates => "${datadir}/mysql", + logoutput => on_failure, + path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin', + require => Package['mysql-server'], + } + + if $mysql::server::restart { + Exec['mysql_install_db'] { + notify => Class['mysql::server::service'], + } } } diff --git a/spec/classes/mysql_client_spec.rb b/spec/classes/mysql_client_spec.rb index 7f67f49..b2689b5 100644 --- a/spec/classes/mysql_client_spec.rb +++ b/spec/classes/mysql_client_spec.rb @@ -17,6 +17,19 @@ describe 'mysql::client' do it { is_expected.to contain_class('mysql::bindings') } it { is_expected.to contain_package('mysql_client') } end + + context 'with package_manage set to true' do + let(:params) {{ :package_manage => true }} + + it { is_expected.to contain_package('mysql_client') } + end + + context 'with package_manage set to false' do + let(:params) {{ :package_manage => false }} + + it { is_expected.not_to contain_package('mysql_client') } + end + end end end diff --git a/spec/classes/mysql_server_spec.rb b/spec/classes/mysql_server_spec.rb index 2058e5f..635bf57 100644 --- a/spec/classes/mysql_server_spec.rb +++ b/spec/classes/mysql_server_spec.rb @@ -20,11 +20,19 @@ describe 'mysql::server' do end context 'mysql::server::install' do - it 'contains the package' do + it 'contains the package by default' do is_expected.to contain_package('mysql-server').with({ :ensure => :present, }) end + context 'with package_manage set to true' do + let(:params) {{ :package_manage => true }} + it { is_expected.to contain_package('mysql-server') } + end + context 'with package_manage set to false' do + let(:params) {{ :package_manage => false }} + it { is_expected.not_to contain_package('mysql-server') } + end context 'with datadir overridden' do let(:params) {{ :override_options => { 'mysqld' => { 'datadir' => '/tmp' }} }} it { is_expected.to contain_exec('mysql_install_db') }