Skip to content

Instantly share code, notes, and snippets.

@sawanoboly
Last active December 21, 2015 12:19
Show Gist options
  • Save sawanoboly/6305359 to your computer and use it in GitHub Desktop.
Save sawanoboly/6305359 to your computer and use it in GitHub Desktop.
Chefのレシピでmysql_secure_installation(bashリソース利用) ref: http://qiita.com/sawanoboly/items/90d2b038f0f15282b872
# cat <<'EOL' | chef-apply -s
> bash 'mysql_secure_install emulate' do
> code <<-"EOH"
> /usr/bin/mysqladmin drop test -f
> /usr/bin/mysql -e "delete from user where user = '';" -D mysql
> /usr/bin/mysql -e "delete from user where user = 'root' and host = \'#{node[:hostname]}\';" -D mysql
> /usr/bin/mysql -e "SET PASSWORD FOR 'root'@'::1' = PASSWORD('newpassword');" -D mysql
> /usr/bin/mysql -e "SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('newpassword');" -D mysql
> /usr/bin/mysql -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpassword');" -D mysql
> /usr/bin/mysqladmin flush-privileges -pnewpassword
> EOH
> action :run
> only_if "/usr/bin/mysql -u root -e 'show databases;'"
> end
> EOL
Recipe: (chef-apply cookbook)::(chef-apply recipe)
* bash[mysql_secure_install emulate] action run
- execute "bash" "/tmp/chef-script20130822-12249-10qdpq7-0"
Recipe: (chef-apply cookbook)::(chef-apply recipe)
* bash[mysql_secure_install emulate] action run (skipped due to only_if)
bash 'mysql_secure_install emulate' do
code <<-"EOH"
/usr/bin/mysqladmin drop test -f
/usr/bin/mysql -e "delete from user where user = '';" -D mysql
/usr/bin/mysql -e "delete from user where user = 'root' and host = \'#{node[:hostname]}\';" -D mysql
/usr/bin/mysql -e "SET PASSWORD FOR 'root'@'::1' = PASSWORD('newpassword');" -D mysql
/usr/bin/mysql -e "SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('newpassword');" -D mysql
/usr/bin/mysql -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpassword');" -D mysql
/usr/bin/mysqladmin flush-privileges -pnewpassword
EOH
action :run
only_if "/usr/bin/mysql -u root -e 'show databases;'"
end
# mysql -e 'select user,host,password from user;' -D mysql -pnewpassword
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost | *FE4F2D624C07AAEBB979DA5C980D0250C37D8F63 |
| root | 127.0.0.1 | *FE4F2D624C07AAEBB979DA5C980D0250C37D8F63 |
| root | ::1 | *FE4F2D624C07AAEBB979DA5C980D0250C37D8F63 |
+------+-----------+-------------------------------------------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment