Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Ansible の基本 + MySQL レプリケーションを設定する事例
Search
Ian Lewis
June 10, 2014
Technology
4
7k
Ansible の基本 + MySQL レプリケーションを設定する事例
Ian Lewis
June 10, 2014
Tweet
Share
More Decks by Ian Lewis
See All by Ian Lewis
Kubernetes Security Best Practices
ianlewis
38
26k
The Enemy Within: Running untrusted code in Kubernetes
ianlewis
0
1.3k
The Enemy Within: Running untrusted code with gVisor
ianlewis
4
1.1k
KubeCon EU Runtime Track Recap
ianlewis
3
1.6k
コンテナによるNoOpsオートメーション
ianlewis
2
150
Google Kubernetes Engine 概要 & アップデート @ GCPUG Kansai Summit Day 2018
ianlewis
2
900
Extending Kubernetes with Custom Resources and Operator Frameworks
ianlewis
10
3.7k
Kubernetesのセキュリティのベストプラクティス
ianlewis
12
17k
Scheduling and Resource Management in Kubernetes
ianlewis
2
1.4k
Other Decks in Technology
See All in Technology
次世代KYC活動報告 / 20250219-BizDay17-KYC-nextgen
oidfj
0
150
『衛星データ利用の方々にとって近いようで触れる機会のなさそうな小話 ~ 衛星搭載ソフトウェアと衛星運用ソフトウェア (実物) を動かしながらわいわいする編 ~』 @日本衛星データコミニティ勉強会
meltingrabbit
0
140
地方拠点で エンジニアリングマネージャーってできるの? 〜地方という制約を楽しむオーナーシップとコミュニティ作り〜
1coin
1
220
明日からできる!技術的負債の返済を加速するための実践ガイド~『ホットペッパービューティー』の事例をもとに~
recruitengineers
PRO
3
290
Datadogとともにオブザーバビリティを布教しよう
mego2221
0
130
データマネジメントのトレードオフに立ち向かう
ikkimiyazaki
3
300
白金鉱業Meetup Vol.17_あるデータサイエンティストのデータマネジメントとの向き合い方
brainpadpr
4
300
Larkご案内資料
customercloud
PRO
0
650
Googleマップ/Earthが一般化した 地図タイルのイマ
mapconcierge4agu
1
200
7日間でハッキングをはじめる本をはじめてみませんか?_ITエンジニア本大賞2025
nomizone
2
1.7k
データ資産をシームレスに伝達するためのイベント駆動型アーキテクチャ
kakehashi
PRO
2
470
株式会社EventHub・エンジニア採用資料
eventhub
0
4.2k
Featured
See All Featured
Rails Girls Zürich Keynote
gr2m
94
13k
Designing for humans not robots
tammielis
250
25k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
4
410
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
YesSQL, Process and Tooling at Scale
rocio
171
14k
How GitHub (no longer) Works
holman
313
140k
Become a Pro
speakerdeck
PRO
26
5.1k
How to Think Like a Performance Engineer
csswizardry
22
1.3k
Designing Experiences People Love
moore
139
23k
Being A Developer After 40
akosma
89
590k
Transcript
None
おめーだれねん?
おれは、関東人でも、 関西人でもないです。
貴様を倒すアメリカ県民だ
イアンです。
@IanMLewis
None
None
None
女性フレンドリー
連絡事項
21:30まで
Ansible とは?
An ansible is a fictional machine capable of instantaneous or
superluminal communication.
\
Ansible is an IT automation tool
自動化
None
None
pip install ansible
ansible provisioning/site.yml
Ansibleの基本
SSH NODE1 NODE2 ... Ansible 女子です
•Playbook •Inventory •Module •Role •Task •Handler 用語
Playbook
YAML
%YAML 1.2 --- YAML: YAML Ain't Markup Language What It
Is: YAML is a human friendly data serialization standard for all programming languages.
--- - hosts: dbservers sudo: True roles: - common -
mysql …
production # 本番環境のInventory stage # ステージング環境のInventory group_vars/ group1 # グループ変数
group2 # "" host_vars/ hostname1 # ホスト変数 hostname2 # "" site.yml # マスターPlaybook webservers.yml # ウェブサーバーのPlaybook dbservers.yml # DBサーバーのPlaybook
roles/ common/ # この下は”common”と言うロール tasks/ # main.yml # <-- ファイルを分割できます。
handlers/ # main.yml # <-- ハンドラー templates/ # <-- テンプレート ntp.conf.j2 # <------- ファイル拡張子は.j2 files/ # bar.txt # <-- コピーするファイル vars/ # main.yml # <-- このロールの変数
http://docs.ansible.com/playbooks_best_practices.html
Inventory
mail.example.com [webservers] foo.example.com bar.example.com [dbservers] one.example.com two.example.com three.example.com
SSH foo.example.com ... Ansible 女子です bar.example.com
Roles
roles/ common/ # この下は”common”と言うロール tasks/ # main.yml # <-- ファイルを分割できます。
handlers/ # main.yml # <-- ハンドラー templates/ # <-- テンプレート ntp.conf.j2 # <------- ファイル拡張子は.j2 files/ # bar.txt # <-- コピーするファイル vars/ # main.yml # <-- このロールの変数
Tasks
roles/ common/ # この下は”common”と言うロール tasks/ # main.yml # <-- ファイルを分割できます。
handlers/ # main.yml # <-- ハンドラー templates/ # <-- テンプレート ntp.conf.j2 # <------- ファイル拡張子は.j2 files/ # bar.txt # <-- コピーするファイル vars/ # main.yml # <-- このロールの変数
--- - name: Add the OS specific varibles include_vars: "{{
ansible_os_family }}.yml" - name: Install the required packages in Redhat derivatives yum: name={{ item }} state=installed with_items: ntp_pkgs when: ansible_os_family == 'RedHat' …
Modules
- name: reboot the servers command: /sbin/reboot -t now
Handlers
roles/ common/ # この下は”common”と言うロール tasks/ # main.yml # <-- ファイルを分割できます。
handlers/ # main.yml # <-- ハンドラー templates/ # <-- テンプレート ntp.conf.j2 # <------- ファイル拡張子は.j2 files/ # bar.txt # <-- コピーするファイル vars/ # main.yml # <-- このロールの変数
--- - name: restart ntp service: name={{ ntp_svc_name }} state=restarted
enabled=yes
まとめ
Playbook Role Task Task … Role Task … Handler Inventory
webservers dbservers
事例
MySQL
めんどくせー
https://github.com/bennojoy/ansible-roles/ tree/master/mysql
- name: Install the mysql packages in Debian derivatives apt:
name={{ item }} state=installed update_cache=yes with_items: mysql_pkgs environment: env - name: Copy the my.cnf file template: - src: my.cnf.{{ ansible_os_family }}.j2 dest: {{ mysql_conf_dir }}/my.cnf notify: - restart mysql
- name: remove the test database mysql_db: name=test state=absent -
name: Create the database's mysql_db: name={{ item.name }} state=present with_items: mysql_db when: mysql_db|lower() != 'none'
Primary
- name: Create the replication users mysql_user: - name: {{
item.name }} host: "%" password: {{ item.pass|default("foobar") }} priv: *.*:"REPLICATION SLAVE" state: present with_items: mysql_repl_user when: mysql_repl_role == 'master'
Replica
- name: Get primary servers replication status mysql_replication: mode=getmaster delegate_to:
"{{ mysql_repl_master }}" register: repl_stat when: slave|failed and mysql_repl_role == 'slave' and mysql_repl_master is defined
- name: Change the master in slave mysql_replication: - mode:
changemaster master_host: {{ mysql_repl_master }} master_log_file: {{ repl_stat.File }} master_log_pos: {{ repl_stat.Position }} master_user: {{ mysql_repl_user[0].name }} master_password: {{ mysql_repl_user[0].pass }} when: <snip>
- name: Start slave mysql_replication: mode=startslave ignore_errors: true when: mysql_repl_role
== 'slave'
またまとめ
Playbook Role Task Task … Role Task … Handler Inventory
webservers dbservers
Playbook copy my.cnf MASTER STATUS … Replica copy my.cnf …
Restart mysql Inventory primaries replicas Primary SLAVE START
ありがとう
さいごに
None
@IanMLewis http://www.ianlewis.org/ どうも!