From 38a7aa0e1cc48338f7aecd3e8ec6a9f4e480449a Mon Sep 17 00:00:00 2001 From: Jethro van Ginkel Date: Thu, 7 Dec 2017 18:09:21 +0100 Subject: [PATCH 1/2] #puppethack allow undef value for bind-address If set `bind-address` to `undef` the bind-address will not be set in the mysql-config file so MySQL is listening on all interfaces. ```puppet class { '::mysql::server': override_options => { mysqld => { bind-address => undef, }, } ``` --- spec/classes/mysql_server_spec.rb | 15 +++++++++++++++ templates/my.cnf.erb | 2 ++ 2 files changed, 17 insertions(+) diff --git a/spec/classes/mysql_server_spec.rb b/spec/classes/mysql_server_spec.rb index fcf11e2c8..ad65d6c23 100644 --- a/spec/classes/mysql_server_spec.rb +++ b/spec/classes/mysql_server_spec.rb @@ -97,6 +97,21 @@ it { is_expected.to contain_file('/tmp/error.log') } end + context 'default bind-address' do + let(:params) { } + + it { is_expected.to contain_file('mysql-config-file').with_content(/^bind-address = 127.0.0.1/) } + end + context 'with defined bind-address' do + let(:params) { { override_options: { 'mysqld' => { 'bind-address' => '1.1.1.1' } } } } + + it { is_expected.to contain_file('mysql-config-file').with_content(/^bind-address = 1.1.1.1/) } + end + context 'without bind-address' do + let(:params) { { override_options: { 'mysqld' => { 'bind-address' => :undef } } } } + + it { is_expected.to contain_file('mysql-config-file').without_content(/^bind-address/) } + end end context 'mysql::server::root_password' do diff --git a/templates/my.cnf.erb b/templates/my.cnf.erb index 7d1f1486b..8845fc39c 100644 --- a/templates/my.cnf.erb +++ b/templates/my.cnf.erb @@ -6,6 +6,8 @@ <% v.sort.map do |ki, vi| -%> <% if ki == 'ssl-disable' or (ki =~ /^ssl/ and v['ssl-disable'] == true) -%> <% next %> +<% elsif ki == 'bind-address' and vi == :undef -%> +<% next %> <% elsif vi == true or vi == '' -%> <%= ki %> <% elsif vi.is_a?(Array) -%> From da638b4b04003fee87e1622ea2120e273ae6f2cf Mon Sep 17 00:00:00 2001 From: Jethro van Ginkel Date: Thu, 7 Dec 2017 20:02:08 +0100 Subject: [PATCH 2/2] Revert template change + rubocop changes --- spec/classes/mysql_server_spec.rb | 8 +++----- templates/my.cnf.erb | 2 -- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/spec/classes/mysql_server_spec.rb b/spec/classes/mysql_server_spec.rb index ad65d6c23..7a30ead36 100644 --- a/spec/classes/mysql_server_spec.rb +++ b/spec/classes/mysql_server_spec.rb @@ -98,19 +98,17 @@ it { is_expected.to contain_file('/tmp/error.log') } end context 'default bind-address' do - let(:params) { } - - it { is_expected.to contain_file('mysql-config-file').with_content(/^bind-address = 127.0.0.1/) } + it { is_expected.to contain_file('mysql-config-file').with_content(%r{^bind-address = 127.0.0.1}) } end context 'with defined bind-address' do let(:params) { { override_options: { 'mysqld' => { 'bind-address' => '1.1.1.1' } } } } - it { is_expected.to contain_file('mysql-config-file').with_content(/^bind-address = 1.1.1.1/) } + it { is_expected.to contain_file('mysql-config-file').with_content(%r{^bind-address = 1.1.1.1}) } end context 'without bind-address' do let(:params) { { override_options: { 'mysqld' => { 'bind-address' => :undef } } } } - it { is_expected.to contain_file('mysql-config-file').without_content(/^bind-address/) } + it { is_expected.to contain_file('mysql-config-file').without_content(%r{^bind-address}) } end end diff --git a/templates/my.cnf.erb b/templates/my.cnf.erb index 8845fc39c..7d1f1486b 100644 --- a/templates/my.cnf.erb +++ b/templates/my.cnf.erb @@ -6,8 +6,6 @@ <% v.sort.map do |ki, vi| -%> <% if ki == 'ssl-disable' or (ki =~ /^ssl/ and v['ssl-disable'] == true) -%> <% next %> -<% elsif ki == 'bind-address' and vi == :undef -%> -<% next %> <% elsif vi == true or vi == '' -%> <%= ki %> <% elsif vi.is_a?(Array) -%>