Last active
December 21, 2015 12:19
-
-
Save sawanoboly/6305359 to your computer and use it in GitHub Desktop.
Chefのレシピでmysql_secure_installation(bashリソース利用) ref: http://qiita.com/sawanoboly/items/90d2b038f0f15282b872
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Recipe: (chef-apply cookbook)::(chef-apply recipe) | |
* bash[mysql_secure_install emulate] action run (skipped due to only_if) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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