Commit 8313fcbd authored by JooHan Hong's avatar JooHan Hong

ansible, 2021-03-08, update11

parent ac9a98d0
Pipeline #5120 passed with stages
in 2 seconds
[![logo](https://www.hongsnet.net/images/logo.gif)](https://www.hongsnet.net)
# Ansible의 copy,file 모듈 및 jinja2 템플릿을 이용한 MariaDB 설치
> MariaDB 설치를 자동화 할 수 있다.
## 주요 기능
- templates/resolv.conf.j2 파일을 이용해 변수에 맞게 DNS Resolver 설정을 수행할 수 있다.
- DNS Resolver는 설정즉시 반영되기 때문에 설정 후 dig 명령을 통해 제대로 Resolving 되는 지 확인한다.
## Inventory 설정
```bash
# cat hosts
[ALL_HOSTS]
172.16.0.100 managed_ip=172.16.0.100 des="2020-12-03"
[ALL_HOSTS_OK]
```
대상 호스트는 172.16.0.100이며, 추가는 2020-12-03에 수행한다. 참고적으로 **ALL_HOSTS_OK** 호스트 그룹은 작업이 완료된 호스트의 history를 위한 그룹이다.
## Host Variables 설정
```bash
# cat host_vars/172.16.0.100
ansible_ssh_host: 172.16.0.100
ansible_ssh_port: SSH_포트번호
ansible_ssh_user: 사용자 아이디
ansible_ssh_pass: "사용자 패스워드"
ansible_become: yes
ansible_become_method: su
ansible_become_user: root
ansible_become_pass: "!root_패스워드"
ansible_python_interpreter: python2.7
```
## Playbook 설정
```python
---
- name: Debian(Minimal Install) Basic APT Package Install
hosts: ALL_HOSTS
vars:
server_id: "XX"
buffer_pool_size: "65535MB"
mysql_conf_src: "/etc/mysql_src"
tasks:
- name: Basic apt sources.list file Backup
command: cp -rf /etc/apt/sources.list /etc/apt/sources.list_src
when: sources_list_src is not exists
- name: APT source sources.list file copy
copy:
src: "{{ item }}"
dest: /etc/apt/sources.list
owner: 'root'
group: 'root'
mode: 0644
#attr: i
with_items:
['sources.list']
- name: MariaDB 10.3 Installing
apt:
pkg:
- mariadb-server=10.3
- name: MariaDB Basic Setting
command: cp -rfp /etc/mysql /etc/mysql_src
when: mysql_conf_src is not exists
- name: MariaDB config files copy
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: 'root'
group: 'root'
with_items:
- { src: mysql_config/debian-start, dest: /etc/mysql/debian-start }
- { src: mysql_config/debian.cnf, dest: /etc/mysql/debian.cnf }
- { src: mysql_config/mariadb.cnf, dest: /etc/mysql/conf.d/mariadb.cnf }
- { src: mysql_config/mysqld_safe_syslog.cnf, dest: /etc/mysql/conf.d/mysqld_safe_syslog.cnf }
- { src: mysql_config/tokudb.cnf, dest: /etc/mysql/conf.d/tokudb.cnf }
- name: mysql config files permission set
file:
path: "{{ item.path }}"
mode: "{{ item.mode }}"
with_items:
- { path: /etc/mysql/debian-start, mode: 755 }
- { path: /etc/mysql/debian.cnf, mode: 600 }
- { path: /etc/mysql/conf.d/mariadb.cnf, mode: 644 }
- { path: /etc/mysql/conf.d/mysqld_safe_syslog.cnf, mode: 644 }
- { path: /etc/mysql/conf.d/tokudb.cnf, mode: 644 }
- name: ntp.conf configuration
template: src=templates/my.cnf.j2 dest=/etc/mysql/my.cnf mode=0644
- name: mysqld Daemon Restart
systemd:
state: restarted
name: mariadb.service
enabled: True
```
jinja2 템플릿 내역은 다음과 같다. 참고적으로 핵심적인 내역만은 명시한다.
```bash
# cat templates/my.cnf.j2
...중략
server-id = {{ server_id }}
...중략
innodb_buffer_pool_size = {{ buffer_pool_size }}
```
`MariaDB 자동설치`에 대한 Playbook 분석
* [ ] MariaDB의 최신버전을 설치하려면, APT의 sources.list 파일에 알맞는 설정을 수행해야 한다.
* [ ] 위의 Playbook은 SLAVE DBMS의 배포로써 server_id,innodb_buffer_pool_size를 변수로 받는다.
* [ ] 큰 틀에서는 기존 설정을 백업하고, 미리 약속된 설정을 배포하는데 유용하다.
## playbook 실행
```bash
# ansible-playbook -i hosts mariadb_install.yml
```
[![logo](https://www.hongsnet.net/images/logo.gif)](https://www.hongsnet.net)
# Ansible 활용
> DBMS Maintenance 작업을 수행한다.
# Table of Contents
| NO | ITEM | Content | 비고 |
| ------ | ------ | ------ | ------ |
| 1 | MariaDB Install | [GO](./MariaDB/) | |
| 2 | OS Package Installing (apt) | [GO](./APT/) | |
......@@ -11,7 +11,8 @@
| 1 | OS Maintenance ITEMs | [GO](./OS/) | |
| 2 | INFRA Maintenance ITEMs | [GO](./INFRA/) | |
| 3 | WEB Server Maintenance ITEMs | [GO](./WEB/) | |
| 4 | Users Management ITEMs | [GO](./USER/) | |
| 4 | DBMS Maintenance ITEMs | [GO](./DBMS/) | |
| 5 | Users Management ITEMs | [GO](./USER/) | |
| 6 | Virtualization Maintenance ITEMs | [GO](./VM/) | |
| 7 | Secure Vulnerability ITEMs | [GO](./SECURE/) | |
| 8 | MISC ITEMs | [GO](./MISC/) | |
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment