From f47d4a2b3b8f17cc187a74093023d51fe54b92a8 Mon Sep 17 00:00:00 2001 From: Greg Kuwaye Date: Tue, 31 Dec 2013 17:09:28 -0500 Subject: [PATCH] Ensure users are dropped with host; check if exists For ensure => absent, drop user with a reference to the host; apply similar check to only delete user if its presence is established. --- manifests/user.pp | 6 ++++-- spec/defines/user_spec.rb | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/manifests/user.pp b/manifests/user.pp index 486c301..53426fc 100644 --- a/manifests/user.pp +++ b/manifests/user.pp @@ -25,8 +25,10 @@ } } elsif $ensure == 'absent' { exec { "delete mysql user ${name}": - command => "mysql -uroot -p13306 --password='' -e 'drop user ${name}'", - require => Exec['wait-for-mysql'] + command => "mysql -uroot -p13306 --password='' -e 'drop user \'${name}\'@\'${host}\''", + require => Exec['wait-for-mysql'], + onlyif => "mysql -uroot -p13306 -e 'SELECT User,Host FROM mysql.user;' \ + --password='' | grep -w '${name}' | grep -w '${host}'" } } } diff --git a/spec/defines/user_spec.rb b/spec/defines/user_spec.rb index f385dd8..9cce192 100644 --- a/spec/defines/user_spec.rb +++ b/spec/defines/user_spec.rb @@ -33,7 +33,7 @@ it "destroys the database" do should contain_exec("delete mysql user #{title}"). with( - :command => "mysql -uroot -p13306 --password='' -e 'drop user #{title}'" + :command => "mysql -uroot -p13306 --password='' -e 'drop user \'#{title}\'@\'localhost\''" ) end end