diff options
Diffstat (limited to 'deploy/adapters/ansible/roles/database/tasks')
8 files changed, 114 insertions, 104 deletions
diff --git a/deploy/adapters/ansible/roles/database/tasks/main.yml b/deploy/adapters/ansible/roles/database/tasks/main.yml index ad5c5b71..f380f603 100644 --- a/deploy/adapters/ansible/roles/database/tasks/main.yml +++ b/deploy/adapters/ansible/roles/database/tasks/main.yml @@ -1,11 +1,11 @@ --- - include_vars: "{{ ansible_os_family }}.yml" -- include: mysql.yml - when: haproxy_hosts is not defined +- include: mariadb_install.yml +- include: mariadb_cluster.yml -- include: mariadb.yml - when: haproxy_hosts is defined +- include: mariadb_config.yml + when: + - inventory_hostname == haproxy_hosts.keys()[0] - include: mongodb.yml - diff --git a/deploy/adapters/ansible/roles/database/tasks/mariadb.yml b/deploy/adapters/ansible/roles/database/tasks/mariadb.yml deleted file mode 100644 index 9a9ebda5..00000000 --- a/deploy/adapters/ansible/roles/database/tasks/mariadb.yml +++ /dev/null @@ -1,79 +0,0 @@ ---- -#- name: delete default maridb-libs -# action: "{{ ansible_pkg_mgr }} name=mariadb-libs state=absent" -# when: ansible_os_family == "RedHat" -# ignore_errors: True - -- name: install python-mysqldb - action: "{{ ansible_pkg_mgr }} name={{ item }} state=present" - with_items: maridb_packages | union(packages_noarch) - -- name: create mysql log directy - file: path=/var/log/mysql state=directory owner=mysql group=mysql mode=0755 - -- name: update mariadb config file - template: src={{ item }} dest={{ mysql_config_file_path }}/{{ item }} backup=yes - with_items: mysql_config_file_name - -- name: update galera wsrep.cnf - template: src=wsrep.cnf dest={{ wsrep_config_file_path }}/wsrep.cnf backup=yes - -- name: update wsrep_sst_rsync uid - lineinfile: dest=/usr/bin/wsrep_sst_rsync state=absent regexp="\s*uid = \$MYUID$" backup=yes - -- name: update wsrep_sst_rsync gid - lineinfile: dest=/usr/bin/wsrep_sst_rsync state=absent regexp="\s*gid = \$MYGID$" backup=yes - -- stat: path=/opt/mysql_init_complete - register: mysql_init_complete - -- name: restart first mysql server - shell: service mysql restart --wsrep-cluster-address="gcomm://" && touch /opt/mysql_init_complete - when: inventory_hostname == haproxy_hosts.keys()[0] and mysql_init_complete.stat.exists == False - tags: - - mysql_restart - #register: result - #until: result|success - #retries: 5 - #delay: 5 - -- name: restart other mysql server - shell: service mysql restart && touch /opt/mysql_init_complete - tags: - - mysql_restart - when: inventory_hostname != haproxy_hosts.keys()[0] and mysql_init_complete.stat.exists == False - #register: result - #until: result|success - #retries: 5 - #delay: 5 - -- name: generate mysql service list - shell: echo {{ item }} >> /opt/service - with_items: services_noarch - -- name: create all needed db - run_once: yes - mysql_db: name={{ item.db }} state=present - with_items: "{{ credentials }}" - -- name: create service db user - run_once: yes - mysql_user: - name={{ item[0].user }} - password={{ item[0].password }} - priv=*.*:ALL,GRANT - host={{ item[1] }} - state=present - with_nested: - - "{{ credentials }}" - - ['%', 'localhost', inventory_hostname] - -- name: create wsrep db user - run_once: yes - mysql_user: - name={{ WSREP_SST_USER }} - password={{ WSREP_SST_PASS }} - priv=*.*:ALL,GRANT - host={{ item }} - state=present - with_items: ['%', 'localhost', inventory_hostname] diff --git a/deploy/adapters/ansible/roles/database/tasks/mariadb_cluster.yml b/deploy/adapters/ansible/roles/database/tasks/mariadb_cluster.yml new file mode 100644 index 00000000..69c8997a --- /dev/null +++ b/deploy/adapters/ansible/roles/database/tasks/mariadb_cluster.yml @@ -0,0 +1,3 @@ +--- +- include: mariadb_cluster_debian.yml + when: ansible_os_family == "Debian" diff --git a/deploy/adapters/ansible/roles/database/tasks/mariadb_cluster_debian.yml b/deploy/adapters/ansible/roles/database/tasks/mariadb_cluster_debian.yml new file mode 100644 index 00000000..96df442d --- /dev/null +++ b/deploy/adapters/ansible/roles/database/tasks/mariadb_cluster_debian.yml @@ -0,0 +1,32 @@ +--- +- name: start first node to create new cluster + service: + name: mysql + state: restarted + args: "--wsrep-new-cluster" + when: + - inventory_hostname == haproxy_hosts.keys()[0] + +- name: wait for cluster ready + command: mysql --silent --skip-column-names -e 'SHOW STATUS LIKE "wsrep_evs_state"' + register: cluster_status + until: cluster_status|success + failed_when: not cluster_status.stdout | search("OPERATIONAL") + retries: 10 + delay: 3 + when: + - inventory_hostname == haproxy_hosts.keys()[0] + +- name: restart other nodes and join cluster + service: + name: mysql + state: restarted + when: + - inventory_hostname != haproxy_hosts.keys()[0] + +- name: restart first nodes + service: + name: mysql + state: restarted + when: + - inventory_hostname == haproxy_hosts.keys()[0] diff --git a/deploy/adapters/ansible/roles/database/tasks/mariadb_config.yml b/deploy/adapters/ansible/roles/database/tasks/mariadb_config.yml new file mode 100644 index 00000000..16783ed4 --- /dev/null +++ b/deploy/adapters/ansible/roles/database/tasks/mariadb_config.yml @@ -0,0 +1,24 @@ +--- +- name: create all needed db + mysql_db: name={{ item.db }} state=present + with_items: "{{ credentials }}" + +- name: create service db user + mysql_user: + name={{ item[0].user }} + password={{ item[0].password }} + priv=*.*:ALL,GRANT + host={{ item[1] }} + state=present + with_nested: + - "{{ credentials }}" + - ['%', 'localhost', inventory_hostname] + +- name: create wsrep db user + mysql_user: + name={{ WSREP_SST_USER }} + password={{ WSREP_SST_PASS }} + priv=*.*:ALL,GRANT + host={{ item }} + state=present + with_items: ['%', 'localhost', inventory_hostname] diff --git a/deploy/adapters/ansible/roles/database/tasks/mariadb_install.yml b/deploy/adapters/ansible/roles/database/tasks/mariadb_install.yml new file mode 100644 index 00000000..41ee5ffe --- /dev/null +++ b/deploy/adapters/ansible/roles/database/tasks/mariadb_install.yml @@ -0,0 +1,49 @@ +--- +- name: disable auto start + copy: + content: "#!/bin/sh\nexit 101" + dest: "/usr/sbin/policy-rc.d" + mode: 0755 + when: ansible_os_family == "Debian" + +- name: install python-mysqldb + action: "{{ ansible_pkg_mgr }} name={{ item }} state=present" + with_items: maridb_packages | union(packages_noarch) + +- name: change open file limit + copy: + content: "* - nofile 65536 }}" + dest: "/etc/security/limits.conf" + mode: 0755 + +- name: update mariadb config file + template: + src: '{{ item.src }}' + dest: '{{ item.dest }}' + backup: yes + mode: 0644 + with_items: mysql_config + +- name: bugfix for rsync version 3.1 + lineinfile: + dest: /usr/bin/wsrep_sst_rsync + state: absent + regexp: '{{ item }}' + with_items: + - "\\s*uid = \\$MYUID$" + - "\\s*gid = \\$MYGID$" + +- stat: path=/opt/mysql_init_complete + register: mysql_init_complete + +- name: enable auto start + file: + path=/usr/sbin/policy-rc.d + state=absent + when: ansible_os_family == "Debian" + +- name: rm old datafiles + shell: rm -rf /var/lib/mysql/ib_logfile* + +- name: set owner + file: path=/var/lib owner=mysql group=mysql recurse=yes state=directory diff --git a/deploy/adapters/ansible/roles/database/tasks/mongodb.yml b/deploy/adapters/ansible/roles/database/tasks/mongodb.yml index c46a2932..c5e1d6d1 100644 --- a/deploy/adapters/ansible/roles/database/tasks/mongodb.yml +++ b/deploy/adapters/ansible/roles/database/tasks/mongodb.yml @@ -21,7 +21,7 @@ - /var/lib/mongodb/journal/* - name: manually restart mongodb server - service: name={{ mongodb_serveice }} state=restarted + service: name={{ mongodb_service }} state=restarted - wait_for: port=27017 delay=3 timeout=60 host={{ internal_vip.ip }} diff --git a/deploy/adapters/ansible/roles/database/tasks/mysql.yml b/deploy/adapters/ansible/roles/database/tasks/mysql.yml deleted file mode 100644 index 9e272d1b..00000000 --- a/deploy/adapters/ansible/roles/database/tasks/mysql.yml +++ /dev/null @@ -1,19 +0,0 @@ ---- -- name: install mysql client and server packages - apt: name={{ item }} state=present - with_items: mysql_packages - -- name: create mysql log directy - file: path=/var/log/mysql state=directory owner=mysql group=mysql mode=0755 - -- name: update mysql config file - copy: src={{ item }} dest={{ mysql_config_file_path }}/{{ item }} backup=yes - with_items: mysql_config_file_name - -- name: manually restart mysql server - shell: service mysql restart - -- name: create database/user - shell: /opt/data.sh - tags: - - mysql_user |