│ ├── mariadb-10.3.15-linux-glibc_214-x86_64.tar.gz
│ └── my.cnf
├── handlers
│ └── main.yaml
├── tasks
│ ├── copy.yaml
│ ├── install.yaml
│ ├── main.yaml
│ └── mysqld
├── templates
└── vars
root@jenkins:~/ansible/roles/mariadb/handlers
- name: "启动mysql服务"
raw: /etc/init.d/mysqld start
root@jenkins:~/ansible/roles/mariadb/tasks
copy.yaml install.yaml main.yaml mysqld
root@jenkins:~/ansible/roles/mariadb/tasks
- name: "拷贝安装包到远程服务器"
copy: src=mariadb-10.3.15-linux-glibc_214-x86_64.tar.gz dest=/usr/local/src owner=root group=root
- name: "拷贝配置文件到远程服务器"
copy: src=my.cnf dest=/etc/my.cnf owner=root group=root
- name: "拷贝启动服务文件到远程服务器"
copy: src=mysqld dest=/etc/init.d/mysqld
root@jenkins:~/ansible/roles/mariadb/tasks
root@jenkins:~/ansible/roles/mariadb/tasks
- name: "安装依赖包"
apt: name={{ item }} state=latest
with_items:
- libaio-dev
- libncurses*
- name: "解压mariadb安装包"
shell: cd /usr/local/src ; tar zxf mariadb-10.3.15-linux-glibc_214-x86_64.tar.gz -C /usr/local
- name: "重命名mariadb安装包"
shell: cd /usr/local ; mv mariadb-10.3.15-linux-glibc_214-x86_64 mariadb
- name: "添加mysql用户"
shell: useradd mysql -M -s /sbin/nologin
- name: "安装包赋权"
shell: cd /usr/local ; chown -R mysql:mysql mariadb
- name: "安装包赋权"
shell: cd /etc/init.d ; chown -R mysql:mysql mysqld ;chmod +x mysqld
- name: "创建必备的文件夹"
file:
path: "{{ item }}"
state: directory
owner: mysql
group: mysql
with_items:
- /data/mysql
- /data/mysql/data
- /data/mysql/logs
- /data/mysql/slowlogs
- /data/mysql/binlog
- name: "初始化mysql"
shell: /usr/local/mariadb/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb --datadir=/data/mysql/data
- name: "添加系统环境变量"
shell: echo "PATH=\$PATH:/usr/local/mariadb/bin" >> /etc/profile
- name: "source环境变量"
shell: . /etc/profile
notify: "启动mysql服务"
root@jenkins:~/ansible/roles/mariadb/tasks
- include: copy.yaml
- include: install.yaml
root@jenkins:~/ansible/roles/mariadb/tasks
root@jenkins:~/ansible/roles
- hosts: '{{ server }}'
remote_user: root
gather_facts: False
roles:
- mariadb
|