---
- hosts: test_playbook
remote_user: root
vars:
timestamp: "{{ ansible_date_time.iso8601 | regex_replace(':', '-') | regex_replace('T', '_') | regex_replace('Z', '') }}"
tasks:
- name: Configure Aliyun YUM repository
yum_repository:
name: aliyun
description: Aliyun YUM Repository
baseurl: http://mirrors.aliyun.com/centos/7/os/x86_64/
gpgcheck: 1
gpgkey: http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
enabled: yes
- name: Update YUM cache
command: yum makecache
- name: install mariadb-server package
yum:
name: mariadb-server
state: present
- name: create mariadb error log directory
file:
path: /var/log/mariadb
state: directory
- name: starting mariadb service
service:
name: mariadb
state: started
enabled: true
- name: Ensure log_error path is correctly set in /etc/my.cnf
lineinfile:
path: /etc/my.cnf
regexp: '^log_error='
line: 'log_error=/var/log/mariadb/error.log'
state: present
- name: Replace a setting in /etc/my.cnf
replace:
path: /etc/my.cnf
regexp: '^#'
replace: '##'
- name: starting mariadb service
service:
name: mariadb
state: restarted
enabled: true
- name: creat mount directory
file:
path: /mnt/disk
state: directory
- name: Mount /dev/sdb1 to /mnt/disk
mount:
path: /mnt/disk
src: /dev/sdb1
fstype: xfs
state: mounted
- name: create a tar.gz file
command: tar -czvf /var/log/mariadb/error_{{ timestamp }}.log.gz -C /var/log/mariadb error.log
- name: Extract a tar.gz file
unarchive:
src: /var/log/mariadb/error_{{ timestamp }}.log.gz
dest: /var/log/mariadb/
remote_src: yes