Re-organized all files and added a Vagrantfile

This commit is contained in:
2016-02-02 11:40:47 -05:00
parent dd4fd53ce7
commit 8a55e9f946
19 changed files with 157 additions and 96 deletions

35
Vagrantfile vendored Normal file
View File

@@ -0,0 +1,35 @@
nodes = {
'db' => [3, 10],
'haproxy' => [1, 20],
'web' => [2,30],
'worker' => [1,40],
}
network = "192.168.20"
Vagrant.configure("2") do |config|
nodes.each do |prefix, (count, ip_start)|
count.times do |i|
hostname = prefix + i.to_s
#puts "hostnames: " + hostname
#puts "ip: #{ip_start+i}"
config.vm.define hostname do |box|
box.vm.box = "centos64"
box.vm.hostname = "#{hostname}"
puts "ip for #{hostname} #{network}.#{ip_start+i}"
box.vm.network :private_network, ip: "#{network}.#{ip_start+i}"
# set memory
box.vm.provider :virtualbox do |vbox|
vbox.customize ["modifyvm", :id, "--memory", 512]
vbox.customize ["modifyvm", :id, "--cpus", 1]
if prefix == "db"
vbox.customize ["modifyvm", :id, "--memory", 1024]
end
end
end
end
end
end

View File

@@ -1 +1 @@
ansible-playbook -i hosts code-deploy.yml
ansible-playbook -i hosts playbooks/code-deploy.yml

View File

@@ -59,3 +59,4 @@ if [ -z ${MEMCACHIER_USERNAME} ]; then
exit
fi
ansible-playbook -i hosts site.yml

View File

@@ -4,4 +4,4 @@
repository: https://github.com/jcwimer/wrestlingApp.git
replication_password: something
read_write_password: something
mysql_root_password: something

20
hosts
View File

@@ -1,22 +1,18 @@
[webservers]
[web]
webhostname
[workers]
[worker]
woker1
[masterdb]
db1-hostname server_id=1
[db]
db0 db1-hostname server_id=1
db1 db2-hostname server_id=2
db2 db3-hostname server_id=3
[slavedbs]
db2-hostname server_id=2
db3-hostname server_id=3
[haproxy]
[proxy]
haproxy-hostname
[masterdb-internal]
[slavedbs-internal]
[db-internal]
[web-internal]

26
playbooks/galeradb.yml Normal file
View File

@@ -0,0 +1,26 @@
---
# This playbook deploys a galera cluster
- name: Apply common configuration to all nodes
hosts: db
user: root
tasks:
- include: ../roles/common/tasks/main.yml
- name: Install galera and mariadb on all db nodes
hosts: db
user: root
tasks:
- include: ../roles/db/tasks/install.yml
- name: Start and create cluser on first db node
hosts: db[0]
user: root
tasks:
- include: ../roles/db/tasks/startcluster.yml
- name: Start mysql on other nodes
hosts: db[1-2]
user: root
tasks:
- include: ../roles/db/tasks/startmysql.yml

15
playbooks/proxy.yml Normal file
View File

@@ -0,0 +1,15 @@
---
# This playbook deploys the haproxy
- name: Apply common configuration to all nodes
hosts: proxy
user: root
tasks:
- include: ../roles/common/tasks/main.yml
- name: Deploy haproxy
hosts: proxy
user: root
tasks:
- include: ../roles/proxy/tasks/main.yml

26
playbooks/rails.yml Normal file
View File

@@ -0,0 +1,26 @@
---
# This playbook deploys the rails application
- name: Apply common configuration to all nodes
hosts: web:worker
user: root
tasks:
- include: ../roles/common/tasks/main.yml
- name: Apply variables to all nodes
hosts: web:worker
user: root
tasks:
- include: ../roles/rails/tasks/vars.yml
- name: Apply web tasks to web nodes
hosts: web
user: root
tasks:
- include: ../roles/rails/tasks/web.yml
- name: Apply worker tasks to worker nodes
hosts: worker
user: root
tasks:
- include: ../roles/rails/tasks/worker.yml

View File

@@ -29,3 +29,7 @@
- name: Modify configuration file to listen on all interfaces
lineinfile: dest=/etc/mysql/my.cnf regexp="^bind-address" line="bind-address=0.0.0.0"
- name: Stop mysql service
service: name=mysql state=stop

View File

@@ -0,0 +1,27 @@
---
# This starts the galera cluster
# Check if mysql is running
- name: bootstrap by starting mysql with gcom://
action: shell /etc/init.d/mysql start --wsrep-cluster-address="gcomm://"
only_if: ${is_mysql_running.rc} > 0
- name: set mysql root password
action: shell mysql -e "UPDATE mysql.user SET password=PASSWORD('$root_mysql_password') where user='root';"
only_if: ${is_mysql_running.rc} > 0
- name: create state snapshot transfer user from anywhere
action: shell mysql -e "CREATE USER '$state_snapshot_transfer_user'@'%' IDENTIFIED BY '$state_snapshot_transfer_password';"
only_if: ${is_mysql_running.rc} > 0
- name: create state snapshot transfer user from localhost
action: shell mysql -e "CREATE USER '$state_snapshot_transfer_user'@'localhost' IDENTIFIED BY '$state_snapshot_transfer_password';"
only_if: ${is_mysql_running.rc} > 0
- name: set privileges for state snapshot transfer user
action: shell mysql -e "GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO '$state_snapshot_transfer_user'@'%';"
only_if: ${is_mysql_running.rc} > 0
- name: set privileges for state snapshot transfer user and flush privileges
action: shell mysql -e "GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO '$state_snapshot_transfer_user'@'localhost'; FLUSH PRIVILEGES;"
only_if: ${is_mysql_running.rc} > 0

View File

@@ -0,0 +1,6 @@
---
# This starts the mysql service
- name: Start mysql service
service: name=mysql state=start

View File

@@ -1,13 +0,0 @@
---
# This sets up the wrestlingtourney database and starts the binlogs
# https://mariadb.com/blog/devops-mariadb-part-1
# https://mariadb.com/blog/devops-mariadb-and-ansible-part-2
- name: Modify configuration file to setup server ID
lineinfile: dest=/etc/mysql/my.cnf regexp="^#server-id" line="server-id=1"
- name: Restart mysql service
service: name=mysql state=restarted
- name: Reset master binlog
command: /usr/bin/mysql -u root -e "RESET MASTER"

View File

@@ -21,7 +21,7 @@ listen mysql-cluster
mode tcp
option mysql-check user haproxy_check
balance roundrobin
{% for db_server in masterdb-internal %}
{% for db_server in db-internal %}
server {{ db_server }} {{ db_server }}:3306 check
{% endfor %}
@@ -33,20 +33,12 @@ frontend www-http
frontend www-https
bind 0.0.0.0:443 ssl crt /root/server.pem
reqadd X-Forwarded-Proto:\ https
acl host_wrestlingdev hdr(host) -i wrestlingdev.com
use_backend wrestlingdev if host_wrestlingdev
default_backend www-backend
backend www-backend
redirect scheme https if !{ ssl_fc }
errorfile 503 /root/home.html
default_backend wrestlingdev
backend wrestlingdev
redirect scheme https if !{ ssl_fc }
balance roundrobin
cookie SERVERID insert indirect nocache
{% for web_server in web-internal-ips %}
{% for web_server in web-internal %}
server {{ web_server }} {{ web_server }}:443 check cookie {{ web_server }} ssl verify none
{% endfor %}

View File

@@ -1,13 +0,0 @@
---
# This installs mariadb and galera on db nodes
# https://mariadb.com/blog/devops-mariadb-part-1
# https://mariadb.com/blog/devops-mariadb-and-ansible-part-2
- name: Modify configuration file to setup server ID
lineinfile: dest=/etc/mysql/my.cnf regexp="^#server-id" line="server-id=2"
- name: Setup replication
command: /usr/bin/mysql -uroot -e "CHANGE MASTER TO master_host='192.168.50.2', master_user='repl', master_password='{{ replication_password }}', master_use_gtid=current_pos"
- name: Restart mysql service
service: name=mysql state=restarted

View File

@@ -1,48 +1,7 @@
--
---
# This playbook deploys the whole application stack for wrestlingdev
#
- name: apply common configuration to all nodes
hosts: all
remote_user: root
roles:
- common
- name: configure and deploy the webservers and application code
hosts: webservers
remote_user: root
roles:
- applicationvars
- web
- name: configure and deploy the rails workers and application code
hosts: workers
remote_user: root
roles:
- applicationvars
- worker
- name: deploy master db
hosts: masterdb
remote_user: root
roles:
- db
- masterdb
- name: deploy mysql and configure database
hosts: slavedbs
remote_user: root
roles:
- db
- slavedb
- name: deploy haproxy
hosts: proxy
remote_user: root
roles:
- proxy
- include: playbooks/galeradb.yml
- include: playbooks/proxy.yml
- include: playbooks/rails.yml