[ansible] mysql ์ค์นํ๊ธฐ
ansible ๋๋ ํฐ๋ฆฌ ๊ตฌ์กฐ
- /etc/ansible - ansible ํ
- hosts - ansible inventory ๋ก ์คํฌ๋ฆฝํธ๋ฅผ ๋ ๋ฆด ์๊ฒฉ ์๋ฒ ๋ชจ์
- ansible.cfg - ansible ํ๊ฒฝ ์ค์ ์ผ๋ก sh ์คํ sh,bash ์ผ์ง ์ ํํ๊ฑฐ๋ ansible ๋ก๊ทธ ๋จ๊ธฐ๋ ๋๋ ํฐ๋ฆฌ ์ค์
- roles - ansible ์คํํ playbook ๋ชจ์ (task ๋ชจ์์ด๋ผ๊ณ ์๊ฐํ๋ฉด ๋จ)
- mysql
- tasks - mysql ์ค์นํ๋ task ๋ชจ์
- templates - mysql ์ค์น ํ ํ๊ฒฝ ์ธํ ํ๋ ํ์ผ ๋ชจ์ (ex : my.ini)
- handlers - mysql service ์คํ
- mysql
- example_site.yml - roles์ ์์ฑ๋ tasks ์คํํ ํ์ผ
ํด๋น ์ฝ๋๋ github๋ฅผ ์ฐธ์กฐํ์์
https://github.com/ansible/ansible-examples/tree/master/wordpress-nginx
ansible/ansible-examples
A few starter examples of ansible playbooks, to show features and how they work together. See http://galaxy.ansible.com for example roles from the Ansible community for deploying many popular appl...
github.com
ansible.cfg ์ค์
** remote ์๋ฒ์ ssh-copy-id๋ก ์ฌ์ ์์ ๋์ด ์์ด์ผ ํ๋ค.
sudo ๊ถํ์ ์ค userid ์์ฑ
1
2
3
4
5
6
|
[defaults]
# some basic default values...
inventory = /etc/ansible/hosts
sudo_user = userId
ask_pass = False
|
cs |
{ANSIBLE_HOME}/roles/mysql/tasks/main.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
---
- name: Install Mysql package
yum: name={{ item }} state=present
with_items:
- http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
- mysql-community-server
- MySQL-python
- libselinux-python
- libsemanage-python
- name: Configure SELinux to start mysql on any port
seboolean: name=mysql_connect_any state=true persistent=yes
when: ansible_selinux.status == "enabled"
- name: Create Mysql configuration file
template: src=my.cnf.j2 dest=/etc/my.cnf
notify:
- restart mysql
- name: Start Mysql Service
service: name=mysqld state=started enabled=yes
|
cs |
{ANSIBLE_HOME}/roles/mysql/templates/my.cnf.j2
1
2
3
4
5
6
7
8
9
10
11
|
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
port=3306
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
|
cs |
{ANSIBLE_HOME}/roles/mysql/handlers/main.yml
1
2
3
|
---
- name: restart mysql
service: name=mysqld state=restarted
|
cs |
{ANSIBLE_HOME}/example_site.yaml
1
2
3
4
5
6
7
8
9
|
---
- name: Install MySQL
hosts: all
remote_user: userId
become: yes
become_method: sudo
roles:
- mysql
|
cs |
{ANSIBLE_HOME}/hosts ์ ์ค์น์คํฌ๋ฆฝํธ๋ฅผ ๋ ๋ฆด ์๊ฒฉ์๋ฒ์ ip๋ฅผ ์ ์ด ์ค๋ค.
ํด๋น ์คํฌ๋ฆฝํธ ์คํ ๋ช ๋ น์ด
1
|
$ ansible-playnook -i hosts example_site.yaml
|
cs |