summaryrefslogtreecommitdiff
path: root/config/chef_apply.rb
blob: 9bdd100815701aec246260ffe0129e9e3aa25cb0 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
execute "yum-update" do
  command "yum update -y"
end

execute "yum-upgrade" do
  command "yum upgrade -y"
end

execute "yum-groupinstall" do
  command "yum groupinstall -y 'Development Tools'"
end

package "epel-release" do
  action :install
end

bash "install_rabbitmq" do
  user "root"
  cwd "/tmp"
  not_if { ::File.exist?("/etc/init.d/rabbitmq-server") }
  code <<-EOH
    wget https://www.rabbitmq.com/releases/erlang/erlang-17.4-1.el6.x86_64.rpm
    wget https://github.com/rabbitmq/rabbitmq-server/releases/download/rabbitmq_v3_5_3/rabbitmq-server-3.5.3-1.noarch.rpm
    rpm --import https://www.rabbitmq.com/rabbitmq-signing-key-public.asc
    yum install -y erlang-17.4-1.el6.x86_64.rpm rabbitmq-server-3.5.3-1.noarch.rpm
  EOH
end

bash "install_cassandra" do
  user 'root'
  not_if { ::File.exist?("/etc/yum.repos.d/datastax.repo") }
  code <<-SCRIPT
  echo "[datastax]\nname=DataStax Repo for Apache Cassandra\nbaseurl=http://rpm.datastax.com/community\nenabled=1\ngpgcheck=0" > /etc/yum.repos.d/datastax.repo
  SCRIPT
end

execute "yum-clean" do
  command "yum clean all"
end

packages = %w{
  dsc21
  git
  java-1.8.0-openjdk
  openssl-devel
  postgresql-contrib
  postgresql-server
  readline-devel
  zlib-devel
}

package packages do
  action :install
end

git "/usr/local/rbenv" do
  repository "https://github.com/sstephenson/rbenv.git"
  action :sync
end

bash "install_rbenv" do
  user "root"
  cwd "/tmp"
  not_if { ::File.exist?("/etc/profile.d/rbenv.sh") }
  code <<-EOH
    echo 'export RBENV_ROOT="/usr/local/rbenv"' >> /etc/profile.d/rbenv.sh
    echo 'export PATH="/usr/local/rbenv/bin:$PATH"' >> /etc/profile.d/rbenv.sh
    echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh
  EOH
end

directory "/usr/local/rbenv/plugins" do
  action :create
end

git "/usr/local/rbenv/plugins/ruby-build" do
  repository "https://github.com/sstephenson/ruby-build.git"
  action :sync
end

bash "install_ruby" do
  user "root"
  not_if { ::File.exist?("/usr/local/rbenv/shims/ruby") }
  code <<-EOH
    source /etc/profile.d/rbenv.sh
    rbenv install 2.2.2
    rbenv global 2.2.2
  EOH
end

bash "install_bundler" do
  code <<-EOH
    source /etc/profile.d/rbenv.sh
    gem install bundler --no-ri --no-rdoc
  EOH
end

bash "configure_postgres" do
  user "root"
  not_if { ::File.exist?("/var/lib/pgsql/data/base") }
  code <<-SCRIPT
    postgresql-setup initdb
  SCRIPT
end

service "rabbitmq-server" do
  action [:start, :enable]
end

service "cassandra" do
  action [:start, :enable]
end

service "postgresql" do
  action [:start, :enable]
end

bash "create_postgres_user" do
  user "postgres"
  code <<-SCRIPT
    psql postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='vagrant'" | grep -q 1 || createuser -s -e -w vagrant
  SCRIPT
end

bash "create_vagrant_db" do
  user "vagrant"
  not_if { "psql postgres -tAc \"SELECT 1 FROM pg_roles WHERE rolname='vagrant'\" | grep -q 1" }
  code <<-SCRIPT
    createdb
  SCRIPT
end