PageRenderTime 174ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/cookbooks/aki3/recipes/default.rb

https://github.com/henrymazza/chef-repo
Ruby | 220 lines | 144 code | 37 blank | 39 comment | 0 complexity | 273c130dd29ba0fac560ae5c1ddeb3a2 MD5 | raw file
  1. #
  2. # Cookbook Name:: aki3
  3. # Recipe:: default
  4. #
  5. # Copyright 2012, YOUR_COMPANY_NAME
  6. #
  7. # All rights reserved - Do Not Redistribute
  8. #
  9. #
  10. # (?) create aki3 home first
  11. # (?) aki3 service should be aki3 owned? or apps group owned?
  12. #
  13. include_recipe 'libmysqlclient'
  14. include_recipe 'php-fpm'
  15. include_recipe 'acme'
  16. #
  17. # Pre-install SSL
  18. #
  19. # Set up contact information. Note the mailto: notation
  20. node.override['acme']['contact'] = ['mailto:fabio@mazarotto.me']
  21. # Real certificates please...
  22. node.override['acme']['endpoint'] = 'https://acme-v01.api.letsencrypt.org'
  23. site = "blog.akivest.com.br"
  24. site2 = "aki3.sampa3.officina.me"
  25. directory "/etc/nginx/ssl/" do
  26. owner "root"
  27. group "root"
  28. end
  29. acme_selfsigned site do
  30. crt "/etc/nginx/ssl/#{site}.crt"
  31. chain "/etc/nginx/ssl/#{site}.pem"
  32. key "/etc/nginx/ssl/#{site}.key"
  33. owner "root"
  34. group "root"
  35. notifies :restart, "service[nginx]", :immediate
  36. end
  37. acme_selfsigned site2 do
  38. crt "/etc/nginx/ssl/#{site2}.crt"
  39. chain "/etc/nginx/ssl/#{site2}.pem"
  40. key "/etc/nginx/ssl/#{site2}.key"
  41. owner "root"
  42. group "root"
  43. notifies :restart, "service[nginx]", :immediate
  44. end
  45. #########################################################3
  46. mysql2_chef_gem 'default' do
  47. action :install
  48. end
  49. group "apps"
  50. directory "/home/aki3"
  51. user "aki3" do
  52. comment "Aki3 Wordpress"
  53. gid "apps"
  54. home "/home/aki3"
  55. end
  56. directory "/home/aki3/www/" do
  57. owner "aki3"
  58. group "apps"
  59. end
  60. directory "/home/aki3/logs/" do
  61. owner "aki3"
  62. group "apps"
  63. end
  64. directory "/home/aki3/s3" do
  65. owner "aki3"
  66. group "apps"
  67. end
  68. mysql_service 'default' do
  69. bind_address '0.0.0.0'
  70. port '3306'
  71. initial_root_password node['mysql']['server_root_password']
  72. action [:create, :start]
  73. end
  74. mysql_connection_info = ({:port => 3306, :host => "127.0.0.1", :username => 'root', :password => node['mysql']['server_root_password']})
  75. #########################################
  76. # create a mysql database and mysql user
  77. #########################################
  78. mysql_database 'aki3' do
  79. connection mysql_connection_info
  80. action :create
  81. end
  82. mysql_database_user "aki3" do
  83. username 'aki3'
  84. connection mysql_connection_info
  85. password 'aki666pass'
  86. action :create
  87. end
  88. mysql_database_user "aki3" do
  89. username 'aki3'
  90. connection mysql_connection_info
  91. password 'aki666pass'
  92. action :grant
  93. end
  94. #########################################
  95. # PHP
  96. #########################################
  97. # TODO: PHP 5.2 - Add the following source, reinstall php5,
  98. # and restart php-fpm.
  99. #
  100. # apt_repository "nginx-php" do
  101. # uri "http://ppa.launchpad.net/txwikinger/php5.2/ubuntu"
  102. # end
  103. template "#{node['nginx']['dir']}/wordpress.conf" do
  104. source 'wordpress-common.erb'
  105. owner 'root'
  106. group 'root'
  107. mode 00644
  108. cookbook 'aki3'
  109. end
  110. template "#{node['nginx']['dir']}/sites-available/aki3.conf" do
  111. source 'wordpress-sites.erb'
  112. owner 'root'
  113. group 'root'
  114. mode 00644
  115. cookbook 'aki3'
  116. variables(
  117. :name => 'aki3',
  118. :host => 'blog.akivest.com.br',
  119. :root => '/home/aki3/www/'
  120. )
  121. end
  122. nginx_site 'aki3.conf' do
  123. action :enable
  124. notifies :restart, "service[nginx]", :immediate
  125. end
  126. ######################################
  127. # Wordpress
  128. ######################################
  129. apt_package 'php5-mysqlnd'
  130. # Downloads and extracts latest wordpress version
  131. # TODO: stick with only one version
  132. tar_extract 'https://wordpress.org/wordpress-5.1.1.tar.gz' do
  133. target_dir '/home/aki3/www/'
  134. # prevent the command from running when the specified file already exists.
  135. creates File.join('/home/aki3/www/', 'index.php')
  136. user 'aki3'
  137. group 'apps'
  138. tar_flags [ '--strip-components 1' ]
  139. # looks like redundant
  140. not_if { ::File.exists?("/home/aki3/www/index.php") }
  141. end
  142. template "/home/aki3/www/wp-config.php" do
  143. source 'wp-config.php.erb'
  144. mode 0644
  145. variables(
  146. :db_name => 'aki3',
  147. :db_user => 'aki3',
  148. :db_password => 'aki666pass',
  149. :db_host => '127.0.0.1',
  150. :db_prefix => 'wp_',
  151. :db_charset => 'utf8',
  152. :db_collate => '',
  153. :auth_key => node['aki3']['keys']['auth'],
  154. :secure_auth_key => node['aki3']['keys']['secure_auth'],
  155. :logged_in_key => node['aki3']['keys']['logged_in'],
  156. :nonce_key => node['aki3']['keys']['nonce'],
  157. :auth_salt => node['aki3']['salt']['auth'],
  158. :secure_auth_salt => node['aki3']['salt']['secure_auth'],
  159. :logged_in_salt => node['aki3']['salt']['logged_in'],
  160. :nonce_salt => node['aki3']['salt']['nonce'],
  161. :lang => '',
  162. :allow_multisite => false,
  163. :wp_config_options => {}
  164. )
  165. owner 'aki3'
  166. group 'apps'
  167. action :create
  168. end
  169. #######################################
  170. acme_certificate site do
  171. crt "/etc/nginx/ssl/#{site}.crt"
  172. key "/etc/nginx/ssl/#{site}.key"
  173. wwwroot '/home/aki3/www'
  174. end
  175. acme_certificate site2 do
  176. crt "/etc/nginx/ssl/#{site2}.crt"
  177. key "/etc/nginx/ssl/#{site2}.key"
  178. wwwroot '/home/aki3/www'
  179. end
  180. #######################################
  181. service 'nginx' do
  182. action :restart
  183. end