diff --git a/group_vars/all b/group_vars/all index 859bdd7..71f251d 100644 --- a/group_vars/all +++ b/group_vars/all @@ -2,4 +2,6 @@ # Variables listed here are applicable to all host groups repository: https://github.com/jcwimer/wrestlingApp.git +replication_password: something +read_write_password: something diff --git a/group_vars/dbservers b/group_vars/dbservers deleted file mode 100644 index 027a32a..0000000 --- a/group_vars/dbservers +++ /dev/null @@ -1,9 +0,0 @@ ---- -# The variables file used by the playbooks in the dbservers group. -# These don't have to be explicitly imported by vars_files: they are autopopulated. - -mysqlservice: mysqld -mysql_port: 3306 -dbuser: foouser -dbname: foodb -upassword: abc diff --git a/hosts b/hosts index f22cd1d..8c1759b 100644 --- a/hosts +++ b/hosts @@ -4,18 +4,20 @@ webhostname [workers] woker1 -[dbfirstclustermachine] -db1-hostname +[masterdb] +db1-hostname server_id=1 -[dbservers] -db2-hostname -db3-hostname +[slavedbs] +db2-hostname server_id=2 +db3-hostname server_id=3 [haproxy] haproxy-hostname -[db-internal-ips] +[masterdb-internal] -[web-internal-ips] +[slavedbs-internal] -[proxy-internal-ip] +[web-internal] + +[proxy-internal] diff --git a/roles/db/tasks/main.yml b/roles/db/tasks/main.yml index e31f126..4998390 100644 --- a/roles/db/tasks/main.yml +++ b/roles/db/tasks/main.yml @@ -1,5 +1,7 @@ --- # 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: Update apt apt: update_cache=yes @@ -7,15 +9,23 @@ - name: Install software properties apt: name=software-properties-common state=present -- name: Add galera apt repo - apt_key: url=hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db - apt_repository: repo='deb [arch=amd64,i386] http://ftp.osuosl.org/pub/mariadb/repo/10.1/ubuntu trusty main' +- name: Install MariaDB repository + apt_repository: repo='deb http://ftp.igh.cnrs.fr/pub/mariadb/repo/10.1/ubuntu trusty main' state=present -- name: Update apt - apt: udpate_cache=yes +- name: Add repository key to the system + apt_key: keyserver=keyserver.ubuntu.com id=0xcbcb082a1bb943db -- name: Install mariadb - apt: name=mariadb-server state=present +- name: Install MariaDB Server + apt: name=mariadb-server state=latest update_cache=yes +- name: Install python module + apt: name=python-mysqldb state=installed +- name: Create replication account + mysql_user: name=repl host="%" password={{ replication_password }} priv=*.*:"REPLICATION SLAVE" state=present +- name: Create readwrite user + mysql_user: name=rwuser host="%" password={{ read_write_password }} priv=*.*:SELECT,INSERT,UPDATE,DELETE,CREATE,DROP state=present + +- 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" diff --git a/roles/masterdb/tasks/main.yml b/roles/masterdb/tasks/main.yml new file mode 100644 index 0000000..4bac833 --- /dev/null +++ b/roles/masterdb/tasks/main.yml @@ -0,0 +1,13 @@ +--- +# 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" diff --git a/roles/slavedb/tasks/main.yml b/roles/slavedb/tasks/main.yml new file mode 100644 index 0000000..0adf391 --- /dev/null +++ b/roles/slavedb/tasks/main.yml @@ -0,0 +1,13 @@ +--- +# 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 diff --git a/site.yml b/site.yml index 328c741..0b59829 100644 --- a/site.yml +++ b/site.yml @@ -24,20 +24,21 @@ - applicationvars - worker -- name: deploy first db and create cluster - hosts: dbfirstclustermachine +- name: deploy master db + hosts: masterdb remote_user: root roles: - db - - firstdb + - masterdb - name: deploy mysql and configure database - hosts: dbservers + hosts: slavedbs remote_user: root roles: - db + - slavedb - name: deploy haproxy hosts: proxy