Ansible roles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

100 lines
3.0 KiB

---
- name: Install MariaDB server and client
yum:
name:
- mariadb-server
- mariadb
- MySQL-python
notify:
- restart mariadb
- name: Create pre and post backup hook dir
file: path={{ item }} state=directory mode=750
with_items:
- /etc/backup/pre.d
- /etc/backup/post.d
- name: Deploy backup scripts
template: src={{ item.script }}.j2 dest=/etc/backup/{{ item.hook }}.d/{{ item.script }} mode=755
with_items:
- { script: 'mariadb_create_dumps.sh', hook: pre }
- { script: 'mariadb_delete_dumps.sh', hook: post }
tags: mysql
- name: Create system override directory
file: path=/etc/systemd/system/mariadb.service.d/ state=directory
- name: Modify the service unit
template: src=systemd_limits.conf.j2 dest=/etc/systemd/system/mariadb.service.d/limits.conf
register: mysql_unit
notify: restart mariadb
- name: Reload systemd
systemd: daemon_reload=True
when: mysql_unit.changed
- name: Deploy my.cnf
template: src=my.cnf.j2 dest=/etc/my.cnf
notify: restart mariadb
- name: Start and enable MariaDB
service: name=mariadb state=started enabled=True
- name: Check if we need to create a password for the root user
stat: path=/root/.my.cnf
register: my_no_cnf
- name: Generate a random password for user root
command: openssl rand -base64 45
register: my_root_pass
when: not my_no_cnf.stat.exists
- name: Set MariaDB root password
command: mysqladmin password "{{ my_root_pass.stdout }}"
when:
- not my_no_cnf.stat.exists
- my_root_pass.stdout is defined
- name: Deploy /root/.my.cnf
template: src=root_my.cnf.j2 dest=/root/.my.cnf
when:
- not my_no_cnf.stat.exists
- my_root_pass.stdout is defined
- name: Remove anonymous user
mysql_user: name='' host_all=yes state=absent
- name: Remove the test database
mysql_db: name=test state=absent
- name: Handle MariaDB port
iptables_raw:
name: mysql_port
state: "{{ (mysql_src_ip is defined and mysql_src_ip | length > 0) | ternary('present','absent') }}"
rules: "-A INPUT -m state --state NEW -p tcp --dport {{ mysql_port | default('3306') }} -s {{ mysql_src_ip | join(',') }} -j ACCEPT"
when: iptables_manage | default(True)
- name: Create database admin
mysql_user: name=sqladmin password={{ mysql_admin_pass }} host="%" priv="*.*:ALL,GRANT" state=present
- name: Create databases
mysql_db: name={{ item }} state=present
with_items: "{{ mysql_databases | default([]) }}"
- name: Create mysql users
mysql_user: name={{ item.name }} password={{ item.password }} priv={{ item.privileges }} host={{ item.host | default('localhost') }} state=present
with_items: "{{ mysql_users | default([]) }}"
when:
- item.name is defined
- item.password is defined
- item.privileges is defined
- name: Remove databases
mysql_db: name={{ item }} state=absent
with_items: "{{ mysql_databases_to_remove }}"
- name: Remove users
mysql_user: name={{ item.name }} host={{ item.host | default(omit) }} state=absent
with_items: "{{ mysql_users_to_remove }}"
...