summaryrefslogtreecommitdiff
path: root/kitchen-tests/cookbooks/webapp/recipes/default.rb
blob: 2b3459b794c077d600a101cde413ed17190f966b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#
# Cookbook Name:: webapp
# Recipe:: default
#
# Copyright (C) 2014
#

include_recipe "apache2"
include_recipe "database::mysql"
include_recipe "php"

creds = Hash.new
%w{mysql webapp}.each do |item_name|
  creds[item_name] = data_bag_item("passwords", item_name)
end

web_app "webapp" do
  server_name "localhost"
  server_aliases [node["fqdn"], node["hostname"], "localhost.localdomain"]
  docroot node["webapp"]["path"]
  cookbook "apache2"
end

mysql_service "default" do
  server_root_password creds["mysql"]["server_root_password"]
  server_repl_password creds["mysql"]["server_repl_password"]
end

mysql_database node["webapp"]["database"] do
  connection ({
    :host => "localhost",
    :username => "root",
    :password => creds["mysql"]["server_root_password"],
  })
  action :create
end

mysql_database_user node["webapp"]["db_username"] do
  connection ({
    :host => "localhost",
    :username => "root",
    :password => creds["mysql"]["server_root_password"],
  })
  password creds["webapp"]["db_password"]
  database_name node["webapp"]["database"]
  privileges [:select, :update, :insert, :create, :delete]
  action :grant
end

directory node["webapp"]["path"] do
  owner "root"
  group "root"
  mode "0755"
  action :create
  recursive true
end

template "#{node['webapp']['path']}/index.html" do
  source "index.html.erb"
end

template "#{node['webapp']['path']}/index.php" do
  source "index.php.erb"
end